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

 
mila.com:

Спасибо, но у меня возвращает нуль. В чём может быть причина?

А другого и быть не может. Ни один компьютер не знает года меньше 1970. Начните с года который присутствует в котировках брокера.

 
Alexey Viktorov:

А другого и быть не может. Ни один компьютер не знает года меньше 1970. Начните с года который присутствует в котировках брокера.

А чё, нормально задано, первый год нашей эры)

 
Vitaly Muzichenko:

А чё, нормально задано, первый год нашей эры)

А -1 это будет первый год до нашей эры.
 
Artyom Trishkin:
Используйте CopyXXX()

Спасибо.


В MT5 можно сдвинуть график таким образом:

PlotIndexSetInteger(0,PLOT_SHIFT,InpChannelPeriod);

Если компилировать в MT4, то ошибок не выдает, однако ничего не работает, есть аналог у MT4?
 
Aleksey Vyazmikin:

Спасибо.


В MT5 можно сдвинуть график таким образом:

PlotIndexSetInteger(0,PLOT_SHIFT,InpChannelPeriod);

Если компилировать в MT4, то ошибок не выдает, однако ничего не работает, есть аналог у MT4?
Пользовательские индикаторы - Справочник MQL4
Пользовательские индикаторы - Справочник MQL4
  • docs.mql4.com
Пользовательские индикаторы - Справочник MQL4
 
Alexey Viktorov:

Там выбрал

SetIndexShift(0,InpChannelPeriod); 

но, эффект совсем другой, т.е. код не работает, логика что ль там иная - хз...
 

Может кто поможет, суть индикатора в том, что б отрисовать как обычно канал Дончиана, а потом за минусовой бар сдвинуть линии последнего значения канала.

В MT5 вроде как все работает, а в MT4 не понимаю, что не так - уж и тут и там переправил, а всё ересь рисует - сдвигает сам канал, хотя я отдельно делаю расчет для значений, которые пойдут на сдвиг....

//+------------------------------------------------------------------+
//|                                             Donchian_Channel.mq5 |
//+------------------------------------------------------------------+
#property copyright "Vyazmikin Aleksey Vyacheslavovich"
#property link      "https://www.mql5.com/ru/users/-aleks-"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2

//--- plot Label1
#property indicator_label1  "High_Prognoz";
#property indicator_type1   DRAW_LINE;
#property indicator_color1  clrAquamarine;
#property indicator_style1  STYLE_DOT;
#property indicator_width1  1;
//--- plot Label2
#property indicator_label2  "Low_Prognoz";
#property indicator_type2   DRAW_LINE;
#property indicator_color2  clrAquamarine;
#property indicator_style2  STYLE_DOT;
#property indicator_width2  1;


//--- input parameters
input int InpChannelPeriod=48; // Period

//--- indicator buffers
double ExtHighBufferPrognoz[];
double ExtLowBufferPrognoz[];
//---
int i,limit,start;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtHighBufferPrognoz,INDICATOR_DATA);
   SetIndexBuffer(1,ExtLowBufferPrognoz,INDICATOR_DATA);
//--- set accuracy
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- set first bar from what index will be drawn
   SetIndexDrawBegin(0,InpChannelPeriod);
   SetIndexDrawBegin(1,InpChannelPeriod);

   SetIndexShift(0,InpChannelPeriod);
   SetIndexShift(1,InpChannelPeriod);

//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {

//--- check for rates
   if(rates_total<InpChannelPeriod*2) return(0);
//--- preliminary calculations
   if(prev_calculated==0) limit=InpChannelPeriod;
   else limit=prev_calculated;
//--- the main loop of calculations

   for(i=limit;i<rates_total && !IsStopped();i++)
     {
      start=i-InpChannelPeriod;
      ExtHighBufferPrognoz[i-InpChannelPeriod]=high[ArrayMaximum(high,InpChannelPeriod,start)];
      ExtLowBufferPrognoz[i-InpChannelPeriod] =low[ArrayMinimum(low,InpChannelPeriod,start)];

     }

   for(int x=rates_total-InpChannelPeriod;x<rates_total && !IsStopped();x++)
     {
      ExtHighBufferPrognoz[x]=ExtHighBufferPrognoz[rates_total-InpChannelPeriod];
      ExtLowBufferPrognoz[x]=ExtLowBufferPrognoz[rates_total-InpChannelPeriod];
     }

//--- return value of prev_calculated for next call
   return(rates_total);
  }
 
Aleksey Vyazmikin:

Может кто поможет, суть индикатора в том, что б отрисовать как обычно канал Дончиана, а потом за минусовой бар сдвинуть линии последнего значения канала.

В MT5 вроде как все работает, а в MT4 не понимаю, что не так - уж и тут и там переправил, а всё ересь рисует - сдвигает сам канал, хотя я отдельно делаю расчет для значений, которые пойдут на сдвиг....

Ну посмотри код аллигатора, там-то работает сдвиг. Хотя, может быть и логика другая.

 
Alexey Viktorov:

Ну посмотри код аллигатора, там-то работает сдвиг. Хотя, может быть и логика другая.


Да сдвиг работает и у меня.

Я заполняю массив со сдвигом, но получается заполнение как будто без сдвига, но сам сдвиг происходит визуально.

Первая часть кода оставляет не заполненным буфер на глубину InpChannelPeriod от последнего бара:

   for(i=limit;i<rates_total && !IsStopped();i++)
     {
      start=i-InpChannelPeriod;
      ExtHighBufferPrognoz[i-InpChannelPeriod]=high[ArrayMaximum(high,InpChannelPeriod,start)];
      ExtLowBufferPrognoz[i-InpChannelPeriod] =low[ArrayMinimum(low,InpChannelPeriod,start)];

     }

А вторая часть должна до заполнить этот участок:

   for(int x=rates_total-InpChannelPeriod;x<rates_total && !IsStopped();x++)
     {
      ExtHighBufferPrognoz[x]=ExtHighBufferPrognoz[rates_total-InpChannelPeriod];
      ExtLowBufferPrognoz[x]=ExtLowBufferPrognoz[rates_total-InpChannelPeriod];
     }

Но по факту получается так:


 

Код в MT5

#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2

//--- plot Label1
#property indicator_label1  "Predicted_high_price";
#property indicator_type1   DRAW_LINE;
#property indicator_color1  clrAquamarine;
#property indicator_style1  STYLE_DOT;
#property indicator_width1  1;
//--- plot Label2
#property indicator_label2  "Predicted_low_price";
#property indicator_type2   DRAW_LINE;
#property indicator_color2  clrAquamarine;
#property indicator_style2  STYLE_DOT;
#property indicator_width2  1;


//--- input parameters
input int InpChannelPeriod=48; // Period

//--- indicator buffers
double ExtHighBufferPrognoz[];
double ExtLowBufferPrognoz[];
//---
int i,limit,start;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtHighBufferPrognoz,INDICATOR_DATA);
   SetIndexBuffer(1,ExtLowBufferPrognoz,INDICATOR_DATA);   
//--- set accuracy
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- set first bar from what index will be drawn
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpChannelPeriod);
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpChannelPeriod);   

   PlotIndexSetInteger(0,PLOT_SHIFT,InpChannelPeriod);
   PlotIndexSetInteger(1,PLOT_SHIFT,InpChannelPeriod);   


//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {

//--- check for rates
   if(rates_total<InpChannelPeriod) return(0);
//--- preliminary calculations
   if(prev_calculated==0) limit=InpChannelPeriod;
   else limit=prev_calculated;
//--- the main loop of calculations
   for(i=limit;i<rates_total && !IsStopped();i++)
     {
      start=i-InpChannelPeriod;          
      ExtHighBufferPrognoz[i-InpChannelPeriod]=high[ArrayMaximum(high,start,InpChannelPeriod)];
      ExtLowBufferPrognoz[i-InpChannelPeriod]=low[ArrayMinimum(low,start,InpChannelPeriod)];

     }

   for(int x=rates_total-InpChannelPeriod;x<rates_total && !IsStopped();x++)
     {
      //int calc=x--;
      ExtHighBufferPrognoz[x]=ExtHighBufferPrognoz[rates_total-InpChannelPeriod-1];
      ExtLowBufferPrognoz[x]=ExtLowBufferPrognoz[rates_total-InpChannelPeriod-1];             
     }
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Результат:


ЗЫ: Код поменял - не из того ME был.
Причина обращения: