Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 440

 
STARIJ:

it works for me - it tracks mouse movement


I mean surolling).
 

Good day to all. There is a need to analyse information from a senior timeframe.

The system has a condition to build a channel. It's finding the maximum and minimum prices for a certain number of bars. I implemented it using the following method:

extern ENUM_TIMEFRAMES TimeFrameRZ = PERIOD_M15; //Период разворотной зоны
extern ENUM_TIMEFRAMES TimeFrameIn = PERIOD_M5; //Период точки входа
extern int ATR_period = 14;
extern int UpLineSell = 7;
extern int DownLineSell = 7;
extern int UpLineBuy = 7;
extern int DownLineBuy = 7;

//      Параметры разворотных свечей
extern string Comment2 = "---------------------------------Параметры разворотных свечей------------------------------------------";
extern int Volotilnost = 20; // Диапазон цен для трех разворотных свечей (в пунктах)
extern int MaxLineSell = 3;
extern int MaxLineBuy = 3;

bool SellPattern = false;
bool BuyPattern = false;
bool New_Bar = false;

double UpLine_Sell = 0;
double DownLine_Sell = 0;
double UpLine_Buy = 0;
double DownLine_Buy = 0;

int i = 0, j = 0;
int ULs = 0;
int DLs = 0;
int ULb = 0;
int DLb = 0;

double MassZone[2][10];

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
if(Digits == 3 || Digits ==5 )
  {
  Volotilnost *=10;
  UpLineSell *= 10;
  DownLineSell *= 10;
  UpLineBuy*= 10;
  DownLineBuy*= 10;
  }

   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
 
   
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
RazvorotZona();
 
 if(SellPattern == true)
   {

   
     if(ObjectCreate(ChartID(),"UpLine_Sell"+IntegerToString(ULs),OBJ_HLINE,0,TimeCurrent(),UpLine_Sell))
        {
        ObjectSetInteger(ChartID(),"UpLine_Sell"+IntegerToString(ULs),OBJPROP_COLOR,clrOrange);//--- установим цвет прямоугольника 
        ObjectSetInteger(ChartID(),"UpLine_Sell"+IntegerToString(ULs),OBJPROP_STYLE,STYLE_SOLID);//--- установим стиль линий прямоугольника 
        ObjectSetInteger(ChartID(),"UpLine_Sell"+IntegerToString(ULs),OBJPROP_WIDTH,1);//--- установим толщину линий прямоугольника 
        ObjectSetInteger(ChartID(),"UpLine_Sell"+IntegerToString(ULs),OBJPROP_BACK,false);//--- отобразим на переднем (false) или заднем (true) плане
        }
                  
      if(ObjectCreate(ChartID(),"DownLine_Sell"+IntegerToString(DLs),OBJ_HLINE,0,TimeCurrent(),DownLine_Sell))
        {
        ObjectSetInteger(ChartID(),"DownLine_Sell"+IntegerToString(DLs),OBJPROP_COLOR,clrMagenta);//--- установим цвет прямоугольника 
        ObjectSetInteger(ChartID(),"DownLine_Sell"+IntegerToString(DLs),OBJPROP_STYLE,STYLE_SOLID);//--- установим стиль линий прямоугольника 
        ObjectSetInteger(ChartID(),"DownLine_Sell"+IntegerToString(DLs),OBJPROP_WIDTH,1);//--- установим толщину линий прямоугольника 
        ObjectSetInteger(ChartID(),"DownLine_Sell"+IntegerToString(DLs),OBJPROP_BACK,false);//--- отобразим на переднем (false) или заднем (true) плане
        }
        ULs++;
        DLs++;
        if(DLs >= MaxLineSell && ULs >= MaxLineSell)
          {
          ObjectDelete(ChartID(),"UpLine_Sell"+IntegerToString(ULs - MaxLineSell));
          ObjectDelete(ChartID(),"DownLine_Sell"+IntegerToString(DLs - MaxLineSell));
          }
   }
   
 if(BuyPattern == true)
   {
   if(ObjectCreate(ChartID(),"UpLine_Buy"+IntegerToString(ULb),OBJ_HLINE,0,TimeCurrent(),UpLine_Buy))
        {
        ObjectSetInteger(ChartID(),"UpLine_Buy"+IntegerToString(ULb),OBJPROP_COLOR,clrDeepSkyBlue);//--- установим цвет прямоугольника 
        ObjectSetInteger(ChartID(),"UpLine_Buy"+IntegerToString(ULb),OBJPROP_STYLE,STYLE_SOLID);//--- установим стиль линий прямоугольника 
        ObjectSetInteger(ChartID(),"UpLine_Buy"+IntegerToString(ULb),OBJPROP_WIDTH,1);//--- установим толщину линий прямоугольника 
        ObjectSetInteger(ChartID(),"UpLine_Buy"+IntegerToString(ULb),OBJPROP_BACK,false);//--- отобразим на переднем (false) или заднем (true) плане
        }
                   
      if(ObjectCreate(ChartID(),"DownLine_Buy"+IntegerToString(DLb),OBJ_HLINE,0,TimeCurrent(),DownLine_Buy))
        {
        ObjectSetInteger(ChartID(),"DownLine_Buy"+IntegerToString(DLb),OBJPROP_COLOR,clrBrown);//--- установим цвет прямоугольника 
        ObjectSetInteger(ChartID(),"DownLine_Buy"+IntegerToString(DLb),OBJPROP_STYLE,STYLE_SOLID);//--- установим стиль линий прямоугольника 
        ObjectSetInteger(ChartID(),"DownLine_Buy"+IntegerToString(DLb),OBJPROP_WIDTH,1);//--- установим толщину линий прямоугольника 
        ObjectSetInteger(ChartID(),"DownLine_Buy"+IntegerToString(DLb),OBJPROP_BACK,false);//--- отобразим на переднем (false) или заднем (true) плане
        }
        ULb++;
        DLb++;
        if(ULb >= MaxLineBuy && DLb >= MaxLineBuy)
          {
          ObjectDelete(ChartID(),"UpLine_Buy"+IntegerToString(ULb - MaxLineBuy));
          ObjectDelete(ChartID(),"DownLine_Buy"+IntegerToString(DLb - MaxLineBuy));
          }
   }
}
//+------------------------------------------------------------------+
//    Функция определения нового бара                                |
//+------------------------------------------------------------------+
void Find_New_Bar()
{ 
   datetime TimeBar0 = iTime(Symbol(),TimeFrameRZ,0);
   static datetime New_Time=0;                     // Время текущего бара
   New_Bar=false;                                 // Нового бара нет 
   if(New_Time != TimeBar0)                       // Сравниваем время 
   { 
      New_Time = TimeBar0;                        // Теперь время такое 
      New_Bar = true;                             // Поймался новый бар 
   } 
}
//+------------------------------------------------------------------+
//    Функция определения разворотной зоны                           |
//+------------------------------------------------------------------+
void RazvorotZona()
{
Find_New_Bar();

   double Open3= NormalizeDouble (iOpen(Symbol(), TimeFrameRZ,4),Digits);
   double Close3 = NormalizeDouble (iClose(Symbol(), TimeFrameRZ,4),Digits);
   double High3 = NormalizeDouble (iHigh(Symbol(), TimeFrameRZ,4),Digits);
   double Low3 = NormalizeDouble (iLow(Symbol(), TimeFrameRZ,4),Digits);
//Параметры индикатора волотильности ATR для нахожденя относительно большой свечи перед перевернутым Молотом
   double ATR = iATR(Symbol(),TimeFrameRZ,ATR_period,1);
   
   SellPattern = false;
   BuyPattern = false;
   
   int bar1 = 1;
   int bar2 = 3;
   double Max, Min;
   

   Max = High[iHighest(NULL, TimeFrameRZ, MODE_HIGH, bar2, bar1)]; //1. Ищем High и Low на отрезке [bar1, bar2].
   Min = Low[iLowest(NULL, TimeFrameRZ, MODE_LOW, bar2, bar1)];

   if(NormalizeDouble((Max - Min) / Point, Digits) < Volotilnost && 
      MathAbs(Close3-Open3) > 1.5*ATR)
      {
      if((Close3 > Open3) && New_Bar == true)
        {
        UpLine_Sell = Max;
        DownLine_Sell = Min;
        SellPattern = true;
        Print ("Идентифицирован паттерн");
        Print ("Максимальная цена "+DoubleToStr(Max));
        Print ("Минимальная цена "+DoubleToStr(Min));
        }
        else {SellPattern = false;}
        
      if((Close3 < Open3) && New_Bar == true)
        {
        UpLine_Buy = Max;
        DownLine_Buy = Min;
        BuyPattern = true;
        Print ("Идентифицирован паттерн");
        }
        else {BuyPattern = false;}
      }
}

But this approach leads to analysis of bars from the current working timeframe M5. I need bar1 and bar2 parameters to be taken from M15

How to implement this?

 

I have a feeling the problem is somewhere in here.

Max = High[iHighest(NULL, TimeFrameRZ, MODE_HIGH, bar2, bar1)]; //1. Ищем High и Low на отрезке [bar1, bar2].
   Min = Low[iLowest(NULL, TimeFrameRZ, MODE_LOW, bar2, bar1)];

Who's to say what?

 
voron_026:

I have a feeling the problem is somewhere in here.

Who's to say what?

Well, yeah, specify the right timeframe.

 
STARIJ:

Right, specify the correct timeframe

So I said...

TimeFrameRZ = PERIOD_M15
It's an external variable.
 
double array[10];
array[0]=0.1;

I declare an array and fill in the elements.

Why do I get a declaration without type error on the second line?

 
Juer:

I declare an array and fill in the elements.

Why do I get a declaration without type error on the second line?

Write code in void OnTick() and everything will work.

Or writearray[0]=0.1; in void OnTick()

 
Juer:

I declare an array and fill in the elements.

Why do I get a declaration without type error on the second line?

Are you declaring the array in the area of global variables?

Then declare it at once with values (since you fill them yourself in the code, so they are predefined), for example:

double array[10]={0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0};

... Or fill the array with values in OnInit() or in the function, where it will be filled.

 
Can you tell me how to output ZigZag indicator values into an EA? The others are output by writing iMA, iStochastic, iWPR ... How do I manually calculate ZigZag?
 
ZZuretc:
Please advise how to output the values of the ZigZag indicator into the EA? The others are printed by iMA, iStochastic, iWPR ... How do I manually calculate ZigZag?

Decided to use? The ZigZag indicator values are zero everywhere. Only in the tops the zigzag value is equal to the price at the top.

You have to go through the bars in a loop. See example

Files:
Zig2fl.mq4  4 kb
Reason: