MnQInvestmentDevelopment/MnQInvestment/00_StrategyswithSimon/DerIndicatorDerWeisen.mq5

86 lines
2.4 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 15:08:44 +02:00
//+------------------------------------------------------------------+
//| MyExpertAdvisor.mq5 |
//| by XYZ |
//| https://www.example.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright XYZ"
#property link "https://www.example.com/"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- specify the number of bars to retrieve
int limit = 1440;
//--- create an array to store the closing prices
MqlRates rates[];
ArraySetAsSeries(rates, true);
//--- retrieve the closing prices
int copied = CopyRates(_Symbol, PERIOD_M1, 0, limit, rates);
Print("Copied Values:",copied);
if (copied == 0)
{
Print("Error copying rates data: ", GetLastError());
return INIT_FAILED;
}
//--- calculate the price differences
double diff[];
ArrayResize(diff, limit-1);
for (int i=0; i<limit-1; i++)
{
diff[i] = rates[i].close - rates[i+1].close;
}
//--- count the number of series where the price rises or falls
int rises[10], falls[10];
ArrayInitialize(rises, 0);
ArrayInitialize(falls, 0);
int count = 0;
bool prev_rise = false, prev_fall = false;
for (int i=0; i<limit-2; i++)
{
bool rise = (diff[i] < diff[i+1]);
bool fall = (diff[i] > diff[i+1]);
if (rise && prev_rise)
{
count++;
}
else
{
rises[count]++;
count = 0;
}
prev_rise = rise;
if (fall && prev_fall)
{
count++;
}
else
{
falls[count]++;
count = 0;
}
prev_fall = fall;
}
rises[count]++;
falls[count]++;
//--- output the results
for (int i=2; i<=10; i++)
{
PrintFormat("Series of %d consecutive rises: %d", i, rises[i]);
PrintFormat("Series of %d consecutive falls: %d", i, falls[i]);
}
return INIT_SUCCEEDED;
}