Любые вопросы новичков по MQL4 и MQL5, помощь и обсуждение по алгоритмам и кодам - страница 2521

 
Maxim Kuznetsov #:

int OnCalculateOne(....) { /* от первого зигзага */ }
int OnCalculateTwo(....) { /* от второго зигзага */ }
// обработчик события :
int OnCalculate (...) {
    OnCalculateOne(...); // посчитали первый
    OnCalculateTwo(...); // посчитали второй
}

Сегодня попробую.
 
Игорь #:
Сегодня попробую.

В строке 24, что нужно поставить ???

int OnCalculateOne(const int rates_total,
        const int prev_calculated,
        const datetime &time[],
        const double &open[],
        const double &high[],
        const double &low[],
        const double &close[],
        const long &tick_volume[],
        const long &volume[],
        const int &spread[])
         { /* от первого зигзага */ }
int OnCalculateTwo(const int rates_total,
        const int prev_calculated,
        const datetime &time[],
        const double &open[],
        const double &high[],
        const double &low[],
        const double &close[],
        const long &tick_volume[],
        const long &volume[],
        const int &spread[]) 
        { /* от второго зигзага */ }
// обработчик события :
24  int OnCalculate (...) 
{
    OnCalculateOne(int i=0;
   int limit=0,extreme_counter=0,extreme_search=0;
   int shift=0,back=0,last_high_pos=0,last_low_pos=0;
   double val=0,res=0;
   double curlow=0,curhigh=0,last_high=0,last_low=0;
//--- initializing
   if(prev_calculated==0)
     {
      ArrayInitialize(Buffer1,0.0);
      ArrayInitialize(Buffer2,0.0);
      ArrayInitialize(Buffer3,0.0);
     }
//---
   if(rates_total<100)
      //return(0);
      //--- set start position for calculations
      if(prev_calculated==0)
         limit=Inp_Depth;
//--- ZigZag was already calculated before
   if(prev_calculated>0)
     {
      i=rates_total-1;
      //--- searching for the third extremum from the last uncompleted bar
      while(extreme_counter<Recalc && i>rates_total-100)
        {
         res=Buffer1[i];
         if(res!=0)
            extreme_counter++;
         i--;
        }
      i++;
      limit=i;
      //--- what type of exremum we search for
      if(Buffer3[i]!=0)
        {
         curlow=Buffer3[i];
         extreme_search=Peak;
        }
      else
        {
         curhigh=Buffer2[i];
         extreme_search=Bottom;
        }
      //--- clear indicator values
      for(i=limit+1; i<rates_total && !IsStopped(); i++)
        {
         Buffer1[i] =0.0;
         Buffer3[i] =0.0;
         Buffer2[i] =0.0;
        }
     }
//--- searching for high and low extremes
   if(rates_total<100)
      return(0);
//--- set start position for calculations
   if(prev_calculated==0)
      limit=Inp_Depth;
//--- ZigZag was already calculated before
   if(prev_calculated>0)
     {
      i=rates_total-1;
      //--- searching for the third extremum from the last uncompleted bar
      while(extreme_counter<Recalc && i>rates_total-100)
        {
         res=Buffer1[i];
         if(res!=0)
            extreme_counter++;
         i--;
        }
      i++;
      limit=i;
      //--- what type of exremum we search for
      if(Buffer3[i]!=0)
        {
         curlow=Buffer3[i];
         extreme_search=Peak;
        }
      else
        {
         curhigh=Buffer2[i];
         extreme_search=Bottom;
        }
      //--- clear indicator values
      for(i=limit+1; i<rates_total && !IsStopped(); i++)
        {
         Buffer1[i] =0.0;
         Buffer3[i] =0.0;
         Buffer2[i]=0.0;
        }
     }
//--- searching for high and low extremes
   for(shift=limit; shift<rates_total && !IsStopped(); shift++)
     {
      //--- low
      val=low[Lowest(low,Inp_Depth,shift)];
      if(val==last_low)
         val=0.0;
      else
        {
         last_low=val;
         if((low[shift]-val)>Inp_Deviation*_Point)
            val=0.0;
         else
           {
            for(back=1; back<=Inp_Backstep; back++)
              {
               res=Buffer3[shift-back];
               if((res!=0) && (res>val))
                  Buffer3[shift-back]=0.0;
              }
           }
        }
      if(low[shift]==val)
         Buffer3[shift]=val;
      else
         Buffer3[shift]=0.0;
      //--- high
      val=high[Highest(high,Inp_Depth,shift)];
      if(val==last_high)
         val=0.0;
      else
        {
         last_high=val;
         if((val-high[shift])>Inp_Deviation*_Point)
            val=0.0;
         else
           {
            for(back=1; back<=Inp_Backstep; back++)
              {
               res=Buffer2[shift-back];
               if((res!=0) && (res<val))
                  Buffer2[shift-back]=0.0;
              }
           }
        }
      if(high[shift]==val)
         Buffer2[shift]=val;
      else
         Buffer2[shift]=0.0;
     }
//--- set last values
   if(extreme_search==0) // undefined values
     {
      last_low=0;
      last_high=0;
     }
   else
     {
      last_low=curlow;
      last_high=curhigh;
     }
//--- final selection of extreme points for ZigZag
   for(shift=limit; shift<rates_total && !IsStopped(); shift++)
     {
      res=0.0;
      switch(extreme_search)
        {
         case 0: // search for an extremum
            if(last_low==0 && last_high==0)
              {
               if(Buffer2[shift]!=0)
                 {
                  last_high=high[shift];
                  last_high_pos=shift;
                  extreme_search=Bottom;
                  Buffer1[shift]=last_high;
                  res=1;
                 }
               if(Buffer3[shift]!=0)
                 {
                  last_low=low[shift];
                  last_low_pos=shift;
                  extreme_search=Peak;
                  Buffer1[shift]=last_low;
                  res=1;
                 }
              }
            break;
         case Peak: // search for peak
            if(Buffer3[shift]!=0.0 && Buffer3[shift]<last_low && Buffer3[shift]==0.0)
              {
               Buffer1[last_low_pos]=0.0;
               last_low_pos=shift;
               last_low=Buffer3[shift];
               Buffer1[shift]=last_low;
               res=1;
              }
            if(Buffer2[shift]!=0.0 && Buffer3[shift]==0.0)
              {
               last_high=Buffer2[shift];
               last_high_pos=shift;
               Buffer1[shift]=last_high;
               extreme_search=Bottom;
               res=1;
              }
            break;
         case Bottom: // search for bottom
            if(Buffer2[shift]!=0.0 && Buffer2[shift]>last_high && Buffer3[shift]==0.0)
              {
               Buffer1[last_high_pos]=0.0;
               last_high_pos=shift;
               last_high=Buffer2[shift];
               Buffer1[shift]=last_high;
              }
            if(Buffer3[shift]!=0.0 && Buffer2[shift]==0.0)
              {
               last_low=Buffer3[shift];
               last_low_pos=shift;
           Buffer1[shift]=last_low;
               extreme_search=Peak;
              }
            break;
         default:
            return(rates_total);
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);); // посчитали первый
   
    OnCalculateTwo(int i=0;
   int limit=0,extreme_counter=0,extreme_search=0;
   int shift=0,back=0,last_high_pos=0,last_low_pos=0;
   double val=0,res=0;
   double curlow=0,curhigh=0,last_high=0,last_low=0;
//--- initializing
   if(prev_calculated==0)
     {
      ArrayInitialize(ZigZagBuffer,0.0);
      ArrayInitialize(HighMapBuffer,0.0);
      ArrayInitialize(LowMapBuffer,0.0);
     }
//---
   if(rates_total<100)
      return(0);
//--- set start position for calculations
   if(prev_calculated==0)
      limit=InpDepth;
//--- ZigZag was already calculated before
   if(prev_calculated>0)
     {
      i=rates_total-1;
      //--- searching for the third extremum from the last uncompleted bar
      while(extreme_counter<ExtRecalc && i>rates_total-100)
        {
         res=ZigZagBuffer[i];
         if(res!=0)
            extreme_counter++;
         i--;
        }
      i++;
      limit=i;
      //--- what type of exremum we search for
      if(LowMapBuffer[i]!=0)
        {
         curlow=LowMapBuffer[i];
         extreme_search=Peak;
        }
      else
        {
         curhigh=HighMapBuffer[i];
         extreme_search=Bottom;
        }
      //--- clear indicator values
      for(i=limit+1; i<rates_total && !IsStopped(); i++)
        {
         ZigZagBuffer[i] =0.0;
         LowMapBuffer[i] =0.0;
         HighMapBuffer[i]=0.0;
        }
     }
//--- searching for high and low extremes
   for(shift=limit; shift<rates_total && !IsStopped(); shift++)
     {
      //--- low
      val=low[Lowest(low,InpDepth,shift)];
      if(val==last_low)
         val=0.0;
      else
        {
         last_low=val;
         if((low[shift]-val)>InpDeviation*_Point)
            val=0.0;
         else
           {
            for(back=1; back<=InpBackstep; back++)
              {
               res=LowMapBuffer[shift-back];
               if((res!=0) && (res>val))
                  LowMapBuffer[shift-back]=0.0;
              }
           }
        }
      if(low[shift]==val)
         LowMapBuffer[shift]=val;
      else
         LowMapBuffer[shift]=0.0;
      //--- high
      val=high[Highest(high,InpDepth,shift)];
      if(val==last_high)
         val=0.0;
      else
        {
         last_high=val;
         if((val-high[shift])>InpDeviation*_Point)
            val=0.0;
         else
           {
            for(back=1; back<=InpBackstep; back++)
              {
               res=HighMapBuffer[shift-back];
               if((res!=0) && (res<val))
                  HighMapBuffer[shift-back]=0.0;
              }
           }
        }
      if(high[shift]==val)
         HighMapBuffer[shift]=val;
      else
         HighMapBuffer[shift]=0.0;
     }
//--- set last values
   if(extreme_search==0) // undefined values
     {
      last_low=0;
      last_high=0;
     }
   else
     {
      last_low=curlow;
      last_high=curhigh;
     }
//--- final selection of extreme points for ZigZag
   for(shift=limit; shift<rates_total && !IsStopped(); shift++)
     {
      res=0.0;
      switch(extreme_search)
        {
         case 0: // search for an extremum
            if(last_low==0 && last_high==0)
              {
               if(HighMapBuffer[shift]!=0)
                 {
                  last_high=high[shift];
                  last_high_pos=shift;
                  extreme_search=Bottom;
                  ZigZagBuffer[shift]=last_high;
                  res=1;
                 }
               if(LowMapBuffer[shift]!=0)
                 {
                  last_low=low[shift];
                  last_low_pos=shift;
                  extreme_search=Peak;
                  ZigZagBuffer[shift]=last_low;
                  res=1;
                 }
              }
            break;
         case Peak: // search for peak
            if(LowMapBuffer[shift]!=0.0 && LowMapBuffer[shift]<last_low && HighMapBuffer[shift]==0.0)
              {
               ZigZagBuffer[last_low_pos]=0.0;
               last_low_pos=shift;
               last_low=LowMapBuffer[shift];
               ZigZagBuffer[shift]=last_low;
               res=1;
              }
            if(HighMapBuffer[shift]!=0.0 && LowMapBuffer[shift]==0.0)
              {
               last_high=HighMapBuffer[shift];
               last_high_pos=shift;
               ZigZagBuffer[shift]=last_high;
               extreme_search=Bottom;
               res=1;
              }
            break;
         case Bottom: // search for bottom
            if(HighMapBuffer[shift]!=0.0 && HighMapBuffer[shift]>last_high && LowMapBuffer[shift]==0.0)
              {
               ZigZagBuffer[last_high_pos]=0.0;
               last_high_pos=shift;
               last_high=HighMapBuffer[shift];
               ZigZagBuffer[shift]=last_high;
              }
            if(LowMapBuffer[shift]!=0.0 && HighMapBuffer[shift]==0.0)
              {
               last_low=LowMapBuffer[shift];
               last_low_pos=shift;
               ZigZagBuffer[shift]=last_low;
               extreme_search=Peak;
              }
            break;
         default:
            return(rates_total);
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }); // посчитали второй
 
Игорь #:

В строке 24, что нужно поставить ???


int OnCalculateOne(....) { /* код расчета первого зигзага */ }
int OnCalculateTwo(....) { /* код расчета второго зигзага */ }
// обработчик события :
int OnCalculate (...)
{
    OnCalculateOne(...); 
    OnCalculateTwo(...); 
}

В  OnCalculate - только вызов функций.

//+------------------------------------------------------------------+
//| ZigZag calculation                                               |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   OnCalculateOne(rates_total,prev_calculated,time,open,high,low,close,tick_volume,volume,spread);
   OnCalculateTwo(rates_total,prev_calculated,time,open,high,low,close,tick_volume,volume,spread);
//--- return value of prev_calculated for next call
   return(rates_total);
  }
 

Здравствуйте! Подскажите, есть ли в MQL5 функция Trailing Stop, похожая на класс Ctrade?

Или самому надо писать.

 
Maxim121285 #:

Здравствуйте! Подскажите, есть ли в MQL5 функция Trailing Stop, похожая на класс Ctrade?

Или самому надо писать.

Раз.

Два.

Как добавить Trailing Stop по индикатору Parabolic SAR
Как добавить Trailing Stop по индикатору Parabolic SAR
  • www.mql5.com
При создании торговой стратегии нам нужно проверить самые разные варианты защитных стопов. И тут напрашивается динамическое подтягивание уровня Stop Loss вслед за ценой. Наилучшим кандидатом для этого является индикатор Parabolic SAR —трудно придумать что-либо проще и нагляднее.
 
Vitaly Muzichenko #:

Если во втором преобразовано в double, то почему в первом в int


Вы сами понимаете, что пишите?

это я так просто проверял. Там в первом случае целое число....

Если дабл делать в первом случае там нули после единицы мешают чтению и пониманию быстрому и сразу, типа 1.00000. Нули лишние. int -  хватает

с явным и неявным преобразованием типов знаком - спасибо. 

 
Artyom Trishkin #:

Раз.

Два.

Спасибо ! 

Конечно, информации для изучения много.

Но я буду стараться.

 

Коллеги - код был написан не мной и давно.

Его задача и он ее выполняет это привести к единому виду и в единую систему координат размеры позиций двух символов спреда для их баланса по сути уравновешивания исходя из значений тиквалуе и тиксайз каждого символа спреда.

Можете пожалуйста мне разъяснить можно подробнее и по- проще если не сложно - что выполняет этот цикл фор?


//============= расчет соотношения лотов по инструментам =====================
   double ynax=MarketInfo(Symbol_1, MODE_TICKVALUE)/MarketInfo(Symbol_2, MODE_TICKVALUE)*
               (iOpen(Symbol_1,0,0)/MarketInfo(Symbol_1, MODE_TICKSIZE))/
               (iOpen(Symbol_2,0,0)/MarketInfo(Symbol_2, MODE_TICKSIZE));

   double minx=0, miny=0, mindelta=9999;

   for(double x=0.01; x<=1; x+=0.01)
     {
      for(double y=0.01; y<=1; y+=0.01)
        {
         double delta=MathAbs(y/x-ynax);
         if(delta<mindelta)
           {
            minx=x;
            miny=y;
            mindelta=delta;
           }
        }
     }
   string LotsS1  = DoubleToStr(minx,2);
   string LotsS2  = DoubleToStr(miny,2);

//======= пишем комментарий в окне индюикатора
   string info = "Размер "+Symbol_1+"="+LotsS1+"  Размер "+Symbol_2+"="+LotsS2+
                 "  Дельта =";
   IndicatorShortName(info);

спс. Индикатор весь во вложении. Полезен для использования.

отдает рекомендованный размер входа по каждому символу (доли объема на вход)- нижний индикатор слева вверху

я примерно знаю - хотел доуточнить... и что означает тут в контексте расчета параметр дельта?


Файлы:
 
Вроде часть понял. Этот цикл выходит на минимальные доли они же лоты двух поз приводя их к балансу.
 
Tretyakov Rostyslav #:


В  OnCalculate - только вызов функций.

Здравствуйте. Вроде сделал как надо. "Вылезло" куча ошибок. Вы извините, я mql5 только начинаю программировать. Файл с индюком я прикрепил ниже. Спасибо Вам, за помощь.

ошибки после компиляции 

Файлы:
temp.mq5  56 kb