MQL4 및 MQL5에 대한 초보자 질문, 알고리즘 및 코드에 대한 도움말 및 토론 - 페이지 305

 
mila.com :

고맙지만 null을 반환합니다. 이유는 무엇입니까?

그리고 다른 것은 있을 수 없습니다. 1970년보다 작은 컴퓨터는 없습니다. 브로커가 나열한 연도부터 시작하십시오.

 
Alexey Viktorov :

그리고 다른 것은 있을 수 없습니다. 1970년보다 작은 컴퓨터는 없습니다. 브로커가 나열한 연도부터 시작하십시오.

뭐, 보통은 정해져 있어, 우리 시대의 원년)

 
Vitaly Muzichenko :

뭐, 보통은 정해져 있어, 우리 시대의 원년)

A -1은 BC 첫 해가 됩니다.
 
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); 

그러나 효과는 상당히 다릅니다. 코드가 작동하지 않고 논리가 다른 곳에 있습니다 - xs ...
 

누군가가 도움이 될 수 있습니다. 표시기의 본질은 평소와 같이 Donchian 채널 을 그린 다음 마지막 채널 값의 선을 음수 막대 뒤로 이동하는 것입니다.

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 :

누군가가 도움이 될 수 있습니다. 표시기의 본질은 평소와 같이 Donchian 채널을 그린 다음 마지막 채널 값의 선을 음수 막대 뒤로 이동하는 것입니다.

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);
  }
//+------------------------------------------------------------------+

결과:


ZY: 코드가 변경되었습니다. ME가 변경되지 않았습니다.