초보자의 질문 MQL5 MT5 MetaTrader 5 - 페이지 990

 

질문: 한 기간 동안 설정된 핸들 이 다른 기간의 CopyBuffer 로 값을 전송하지 않는 이유는 무엇입니까? 그리고 무엇을 해야 할까요?

문제가 다른 시간 프레임에서 버퍼 배열 요소 의 이동에 있었다면 문제를 해결했을 것입니다. 그래서 그것은 전혀 명확하지 않습니다.

 
kopeyka2 :

질문: 한 기간 동안 설정된 핸들 이 다른 기간의 CopyBuffer 로 값을 전송하지 않는 이유는 무엇입니까? 그리고 무엇을 해야 할까요?

문제가 다른 시간 프레임에서 버퍼 배열 요소 의 이동에 있었다면 문제를 해결했을 것입니다. 그래서 그것은 전혀 명확하지 않습니다.

핸들이 성공적으로 생성되었으면 핸들을 생성할 때 전달한 매개변수로 생성된 것입니다. 그리고 그것은 어떤 시간대에 지표 데이터를 줄 것입니다. 그것은 그가 생성할 때 주어진 기간을 제공할 데이터일 뿐입니다. 그리고 작업 시간 프레임에 올바르게 표시하려면 표시기 핸들에서 수신된 데이터를 표시기가 작동하는 TF로 변환해야 합니다.

 
kopeyka2 :

방금 확인했습니다. 그러나 문제는 핸들을 하나의 일정한 기간 동안 설정함으로써

다른 시간대의 CopyBuffer 값은 전송되지 않습니다. 설정된 핸들 기간에 값은 이었고 더 작은 기간에는 0.0(영)이었습니다. 버퍼를 찾아 이동... 0. CopyBuffer에 전달되지 않는 이유는 무엇입니까?

복사중입니다...

 //--- Подготовка данных
   int count=(limit> 1 ? rates_total : 2 ),copied= 0 ;
       ResetLastError ();
   if ( CopyBuffer (handle_ma, 0 , 0 , 1 ,BufferPrice)< 0 )
     {
       PrintFormat ( "Failed to copy data from the handle_ma indicator, error code %d" , GetLastError ());
       return ( 0.0 );
     }
//   copied=CopyBuffer(handle_ma,0,0,count,BufferPrice);
Print (BufferPrice[ 0 ]);

또 다른 질문은 복사되는 내용입니다. 대부분의 경우 해당 TF에 있는 것보다 복사할 막대를 더 많이 요구할 것입니다. 인쇄

 Print ("count=",count," Bars =", Bars ( Symbol (),Timeframes));
 
Artyom Trishkin :

핸들이 성공적으로 생성되었으면 핸들을 생성할 때 전달한 매개변수로 생성된 것입니다. 그리고 그것은 모든 시간대에 지표 데이터를 제공할 것입니다. 그것은 그가 생성할 때 주어진 기간을 제공할 데이터일 뿐입니다. 그리고 작업 시간 프레임에 올바르게 표시하려면 표시기 핸들에서 수신된 데이터를 표시기가 작동하는 TF로 변환해야 합니다.

나는 실험을 올바르게 수행했는가?

1) 기간 D1에 대한 핸들을 만들었습니다.
2) 다음으로 CopyBuffer에서 지침에 따라 값을 배치합니다(어디에서 어디까지).
0에서 N번째 마디까지 씁니다.
이 간격 내에서 이론상 핸들 값을 기록해야 합니다. 다른 시간대로 전환하는 경우에도 값은 세트 D1에서 가져와야 합니다. 그리고 이것은 정확히 내가 보지 못하는 것입니다. 아니면 문제가 있습니까? 핸들을 설치할 때 추가해야 할 사항이 있습니까? 버퍼로의 전송이 없기 때문입니다.
 
kopeyka2 :
나는 실험을 올바르게 수행했는가?

1) 기간 D1에 대한 핸들을 만들었습니다.
2) 다음으로 CopyBuffer에서 지침에 따라 값을 배치합니다(어디에서 어디까지).
0에서 N번째 마디까지 씁니다.
이 간격 내에서 이론상 핸들 값을 기록해야 합니다. 다른 시간대로 전환하는 경우에도 값은 세트 D1에서 가져와야 합니다. 그리고 이것은 정확히 내가 보지 못하는 것입니다. 아니면 문제가 있습니까? 핸들을 설치할 때 추가해야 할 사항이 있습니까? 버퍼로의 전송이 없기 때문입니다.

안내를 드렸는데...

배우다 :


//+------------------------------------------------------------------+
//|                                                     MTF_LRMA.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                                 https://mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link        "https://mql5.com"
#property version    "1.00"
#property description "Multi Timeframe Linear Regression Moving Average with signal line"
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_plots    2
//--- plot LWMA
#property indicator_label1    "LRMA"
#property indicator_type1    DRAW_LINE
#property indicator_color1    clrLimeGreen
#property indicator_style1    STYLE_SOLID
#property indicator_width1    1
//--- plot Signal
#property indicator_label2    "Signal"
#property indicator_type2    DRAW_LINE
#property indicator_color2    clrRed
#property indicator_style2    STYLE_SOLID
#property indicator_width2    1
//--- enums
enum ENUM_DRAW_MODE
  {
   DRAW_MODE_STEPS,   // Steps
   DRAW_MODE_SLOPE   // Slope
  };
//--- input parameters
input uint               InpPeriod      =   34 ;               // LRMA period
input uint               InpSignal      =   5 ;                 // Signal period
input ENUM_TIMEFRAMES    InpTimeframe   =   PERIOD_H1 ;         // LRMA timeframe
input ENUM_DRAW_MODE    InpDrawMode    =  DRAW_MODE_STEPS;   // Drawing mode
//--- indicator buffers
double          BufferLRMA[];
double          BufferSignal[];
double          BufferLRMATmp[];
double          BufferSignalTmp[];
double          BufferLWMA[];
double          BufferSMA[];
//--- global variables
ENUM_TIMEFRAMES    timeframe1;
int                period_lrma;
int                signal;
int                handle_lwma;
int                handle_sma;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit ()
  {
//--- timer
   EventSetTimer ( 90 );
//--- set global variables
   period_lrma= int (InpPeriod< 1 ? 1 : InpPeriod);
   signal= int (InpSignal< 1 ? 1 : InpSignal);
   timeframe1=(InpTimeframe> Period () ? InpTimeframe : Period ());
//--- indicator buffers mapping
   SetIndexBuffer ( 0 ,BufferLRMA, INDICATOR_DATA );
   SetIndexBuffer ( 1 ,BufferSignal, INDICATOR_DATA );
   SetIndexBuffer ( 2 ,BufferLRMATmp, INDICATOR_CALCULATIONS );
   SetIndexBuffer ( 3 ,BufferSignalTmp, INDICATOR_CALCULATIONS );
   SetIndexBuffer ( 4 ,BufferLWMA, INDICATOR_CALCULATIONS );
   SetIndexBuffer ( 5 ,BufferSMA, INDICATOR_CALCULATIONS );
//--- setting indicator parameters
   string label=TimeframeToString(timeframe1)+ " LRMA(" +( string )period_lrma+ "," +( string )signal+ ")" ;
   IndicatorSetString ( INDICATOR_SHORTNAME ,label);
   IndicatorSetInteger ( INDICATOR_DIGITS , Digits ());
//--- setting plot buffer parameters
   PlotIndexSetString ( 0 , PLOT_LABEL ,TimeframeToString(timeframe1)+ " LRMA(" +( string )period_lrma+ ")" );
   PlotIndexSetString ( 1 , PLOT_LABEL ,TimeframeToString(timeframe1)+ " Signal(" +( string )signal+ ")" );
//--- setting buffer arrays as timeseries
   ArraySetAsSeries (BufferLRMA, true );
   ArraySetAsSeries (BufferSignal, true );
   ArraySetAsSeries (BufferLRMATmp, true );
   ArraySetAsSeries (BufferSignalTmp, true );
   ArraySetAsSeries (BufferLWMA, true );
   ArraySetAsSeries (BufferSMA, true );
//--- create handles
   ResetLastError ();
   handle_lwma= iMA ( NULL ,timeframe1,period_lrma, 0 , MODE_LWMA , PRICE_CLOSE );
   if (handle_lwma== INVALID_HANDLE )
     {
       Print ( __LINE__ , ": The " ,TimeframeToString(timeframe1), " iMA(" ,( string )period_lrma, ") object was not created: Error " , GetLastError ());
       return INIT_FAILED ;
     }
   handle_sma= iMA ( NULL ,timeframe1,period_lrma, 0 , MODE_SMA , PRICE_CLOSE );
   if (handle_sma== INVALID_HANDLE )
     {
       Print ( __LINE__ , ": The " ,TimeframeToString(timeframe1), " iMA(" ,( string )period_lrma, ") object was not created: Error " , GetLastError ());
       return INIT_FAILED ;
     }
//--- get timeframe
   Time ( NULL ,timeframe1, 1 );
//---
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//--- Проверка количества доступных баров
   if (rates_total< fmax (signal, 4 )) return 0 ;
//--- Проверка и расчёт количества просчитываемых баров
   int limit=rates_total-prev_calculated;
   if (limit> 1 )
     {
      limit=rates_total-signal- 2 ;
       ArrayInitialize (BufferLRMA, 0 );
       ArrayInitialize (BufferSignal, 0 );
       ArrayInitialize (BufferLRMATmp, 0 );
       ArrayInitialize (BufferSignalTmp, 0 );
       ArrayInitialize (BufferLWMA, 0 );
       ArrayInitialize (BufferSMA, 0 );
     }
//--- Подготовка данных
   if ( Time ( NULL ,timeframe1, 1 )== 0 )
       return 0 ;
   int bars=(timeframe1== Period () ? rates_total : Bars ( NULL ,timeframe1));
   int count=(limit> 1 ? fmin (bars,rates_total) : 1 ),copied= 0 ;
   copied= CopyBuffer (handle_lwma, 0 , 0 ,count,BufferLWMA);
   if (copied!=count) return 0 ;
   copied= CopyBuffer (handle_sma, 0 , 0 ,count,BufferSMA);
   if (copied!=count) return 0 ;
      
//--- Расчёт индикатора
   for ( int i=limit; i>= 0 && ! IsStopped (); i--)
     {
      BufferLRMATmp[i]= 3.0 *BufferLWMA[i]- 2.0 *BufferSMA[i];
      BufferSignalTmp[i]=GetSMA(bars,i,signal,BufferLRMATmp);
     }
   for ( int i=limit; i>= 0 && ! IsStopped (); i--)
     {
      DataConversion(rates_total, NULL ,timeframe1,i,BufferLRMATmp,BufferLRMA,InpDrawMode);
      DataConversion(rates_total, NULL ,timeframe1,i,BufferSignalTmp,BufferSignal,InpDrawMode);
     }

//--- return value of prev_calculated for next call
   return (rates_total);
  }
//+------------------------------------------------------------------+
//| Custom indicator timer function                                  |
//+------------------------------------------------------------------+
void OnTimer ()
  {
   Time ( NULL ,timeframe1, 1 );
  }
//+------------------------------------------------------------------+
//| Transfering data from the source timeframe to current timeframe  |
//+------------------------------------------------------------------+
void DataConversion( const int rates_total,
                     const string symbol_name,
                     const ENUM_TIMEFRAMES timeframe_src,
                     const int shift,
                     const double &buffer_src[],
                     double &buffer_dest[],
                    ENUM_DRAW_MODE mode=DRAW_MODE_STEPS
                   )
  {
   if (timeframe_src== Period ())
     {
      buffer_dest[shift]=buffer_src[shift];
       return ;
     }
   int bar_curr=BarToCurrent(symbol_name,timeframe_src,shift);
   if (bar_curr>rates_total- 1 )
       return ;
   int bar_prev=BarToCurrent(symbol_name,timeframe_src,shift+ 1 );
   int bar_next=(shift> 0 ? BarToCurrent(symbol_name,timeframe_src,shift- 1 ) : 0 );
   if (bar_prev== WRONG_VALUE || bar_curr== WRONG_VALUE || bar_next== WRONG_VALUE )
       return ;
   buffer_dest[bar_curr]=buffer_src[shift];
   if (mode==DRAW_MODE_STEPS)
       for ( int j=bar_curr; j>=bar_next; j--)
         buffer_dest[j]=buffer_dest[bar_curr];
   else
     {
       if (bar_prev>rates_total- 1 ) return ;
       for ( int j=bar_prev; j>=bar_curr; j--)
         buffer_dest[j]=EquationDirect(bar_prev,buffer_dest[bar_prev],bar_curr,buffer_dest[bar_curr],j);
       if (shift== 0 )
         for ( int j=bar_curr; j>= 0 ; j--)
            buffer_dest[j]=buffer_dest[bar_curr];
     }
  }
//+------------------------------------------------------------------+
//| Возвращает бар заданного таймфрейма как бар текущего таймфрейма  |
//+------------------------------------------------------------------+
int BarToCurrent( const string symbol_name, const ENUM_TIMEFRAMES timeframe_src, const int shift, bool exact= false )
  {
   datetime time= Time (symbol_name,timeframe_src,shift);
   return (time!= 0 ? BarShift(symbol_name, Period (),time,exact) : WRONG_VALUE );
  }
//+------------------------------------------------------------------+
//| Возвращает смещение бара по времени                              |
//| https://www.mql5.com/ru/forum/743/page11#comment_7010041&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
//+------------------------------------------------------------------+
int BarShift( const string symbol_name, const ENUM_TIMEFRAMES timeframe, const datetime time, bool exact= false )
  {
   int res= Bars (symbol_name,timeframe,time+ 1 , UINT_MAX );
   if (exact) if ((timeframe!= PERIOD_MN1 || time> TimeCurrent ()) && res== Bars (symbol_name,timeframe,time- PeriodSeconds (timeframe)+ 1 , UINT_MAX )) return ( WRONG_VALUE );
   return res;
  }
//+------------------------------------------------------------------+
//| Возвращает Time                                                  |
//+------------------------------------------------------------------+
datetime Time ( const string symbol_name, const ENUM_TIMEFRAMES timeframe, const int shift)
  {
   datetime array[];
   ArraySetAsSeries (array, true );
   return ( CopyTime (symbol_name,timeframe,shift, 1 ,array)== 1 ? array[ 0 ] : 0 );
  }
//+------------------------------------------------------------------+
//| Уравнение прямой                                                 |
//+------------------------------------------------------------------+
double EquationDirect( const int left_bar, const double left_price, const int right_bar, const double right_price, const int bar_to_search)
  {
   return (right_bar==left_bar ? left_price : (right_price-left_price)/(right_bar-left_bar)*(bar_to_search-left_bar)+left_price);
  }
//+------------------------------------------------------------------+
//| Timeframe to string                                              |
//+------------------------------------------------------------------+
string TimeframeToString( const ENUM_TIMEFRAMES timeframe)
  {
   return StringSubstr ( EnumToString (timeframe), 7 );
  }
//+------------------------------------------------------------------+
//| Simple Moving Average                                            |
//+------------------------------------------------------------------+
double GetSMA( const int rates_total, const int index, const int period, const double &price[], const bool as_series= true )
  {
//---
   double result= 0.0 ;
//--- check position
   bool check_index=(as_series ? index<=rates_total-period- 1 : index>=period- 1 );
   if (period< 1 || !check_index)
       return 0 ;
//--- calculate value
   for ( int i= 0 ; i<period; i++)
      result+=(as_series ? price[index+i]: price[index-i]);
//---
   return (result/period);
  }
//+------------------------------------------------------------------+
 
Aleksey Vyazmikin :

복사중입니다...

또 다른 질문은 복사되는 내용입니다. 대부분의 경우 해당 TF에 있는 것보다 복사할 막대를 더 많이 요구할 것입니다. 인쇄

모든 것이 더 겸손합니다. 무리가 놓여 있지 않습니다. D1에 1-2개의 막대가 있습니다. 보다 정확하게는 int lm=IBarShift(NULL,PERIOD_D1, iTime(NULL, PERIOD_CURRENT , limit));
int bar=PeriodSeconds(PERIOD_D1/PeriodSecond(_Period);

int startbar=lm-(lm-bars);

CopyBuffer의 count가 limit 및 rate_total 없이 시도했습니다.

간단히 말해서, CopyByffer를 사용한 문지름 실험은 당신이 그것에 넣어야 하는 것입니다. 하지만 없습니다.
 

kopeyka2 :
Верно ли я провел эксперемент.?

...

... 다른 시간대로 전환하는 경우에도 값은 세트 D1에서 가져와야 합니다. 그리고 이것은 정확히 내가 보지 못하는 것입니다. 아니면 문제가 있습니까? 핸들을 설치할 때 추가해야 할 사항이 있습니까? 버퍼로의 전송이 없기 때문입니다.

간단히 말해서, CopyByffer를 사용한 문지름 실험 은 당신이 그것에 넣어야 하는 것입니다. 하지만 없습니다 .

데이터의 가용성을 확인하지 않았지만 복사를 시도하고 있습니다. 위의 코드를 보세요. 두 번째 타이머에는 1.3분마다 네이티브가 아닌 시간 프레임에 대한 호출이 있습니다. 따라서 데이터를 지속적으로 최신 상태로 유지합니다. 그리고 코드에서 요청된 데이터의 가용성을 먼저 확인합니다. 아직 준비되지 않은 경우 다음 눈금에 대해 0을 반환하고 표시기 계산을 완료합니다. 그러나 모든 데이터가 이미 수신 및 계산되고 표시되면 계산된 데이터의 양이 마지막에 반환되어 다음 틱에서 전체 재계산을 수행하지 않습니다.

 
고맙습니다. 나는 모든 것을 읽었다. 나는 찾을 것이다.
 
kopeyka2 :
고맙습니다. 나는 모든 것을 읽었다. 내가 찾을 것이다.

무엇을 찾아야 할까요? 위는 완전히 작동하는 코드입니다. 원하는 대로 해부할 수 있습니다. 나는 당신의 실수를 지적했습니다 - 당신은 데이터의 가용성을 확인하지 않습니다.

이 줄에서도 :

int lm=IBarShift(NULL,PERIOD_D1, iTime(NULL, PERIOD_CURRENT , limit));

iTime()이 무엇을 반환했는지에 대한 수표는 어디에 있습니까? 확인이 없습니다. 그러나 알 수 없는 결과를 즉시 iBarShift()에 밀어넣습니다. 당신이 기대하는 기능을 제공하고 있다고 확신합니까?

 
Artyom Trishkin :

핸들이 성공적으로 생성되었으면 핸들을 생성할 때 전달한 매개변수로 생성된 것입니다. 그리고 그것은 모든 시간대에 지표 데이터를 제공할 것입니다. 그것은 그가 생성할 때 주어진 기간에 제공할 데이터일 뿐입니다. 그리고 작업 시간 프레임에 올바르게 표시하려면 표시기 핸들에서 수신된 데이터를 표시기가 작동하는 TF로 변환해야 합니다.

그게 바로 내가 생각한 것입니다. "매개변수"라는 단어에 대한 오해의 문제입니다. 그리고 핸들 --> CopyBuffer와 관련된 모든 변수를 살펴보기 시작했습니다.

1) 처음부터 내 질문은 핸들 데이터를 저장하기 위해 시간 프레임을 SCREEN으로 전환하는 것입니다. 글쎄, 그것은 MT4에서처럼.

그리고 실제로 다음과 같이 밝혀졌습니다.

handle_ma= iMA ( NULL , PERIOD_H1 ,period, 0 , MODE_SMA , PRICE_CLOSE ); 

 Comment(handle_ma);  // ВСЕГДА 10

ALWAYS 및 on ALL 기간 은 동일한 값 10을 제공합니다.

여기에서 아무것도 받지 못한 나는 계속 이동했습니다.

2) 나는 인용한다: " 지정된 양의 지정된 인디케이터의 지정된 버퍼의 데이터를 버퍼 배열로 수신".

 CopyBuffer (handle_ma, 0 , 0 ,count,BufferPrice);  //

즉, 손으로 count를 설정하여 값이 있는 INTERVAL이 있어야 합니다. 그리고 그들은! 하지만!!!!!! 처리 기간이 일치하는 경우에만

모니터 화면의 시간대 PERIOD_H1. 모든 값은 명확하게 전송됩니다. 그러나 데이터 화면에서 다른 시간대로 이동하는 것은 NO입니다.

그들은 전송하지 않습니다!!!! 그리고 제 질문은 바로 이것이었습니다. 그리고 계산을 위한 막대의 수는 여기에 없으면 그다지 중요하지 않습니다!!!


제안된 지표 MTF_LRMA.mq5 를 살펴보았지만 동일한 내용이 있습니다. 화면의 다른 시간 프레임으로 전환하고 데이터는 화면의 시간 프레임을 따릅니다. 그리고 손잡이가 필요합니다.

예: iClose(NULL, PERIOD_H1, 5); 모든 시간 프레임에서 동일한 값을 제공합니다: H1의 5번째 막대에서 마감.

지금까지 모든 예제는 CopyBuffer 버퍼의 카운트를 조정하는 것이었습니다. 하지만 어레이가 비어 있습니다.


사유: