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

 

MQL5

전혀 이해가 되지 않습니다. 여기 누군가 조언을 해 줄 수 있습니까?

거래, 자동 거래 시스템 및 거래 전략 테스트에 관한 포럼

힌트를 구합니다.

세르게이 타볼린 , 2019.03.07 08:14

코드 기반의 하나의 지표를 기반으로 내가 원하는 것의 예를 작성했습니다. 공장. 그러나 시작시 오류가 발생합니다.

2019.03.06 21:24:26.091 my_MA_S (GBPUSD,M15)    array out of range in 'my_MA_S.mq5' (103,59)

어디에 오류가 있는지 알려주실 수 있나요?

 //+------------------------------------------------------------------+
//|                                                       myMA_S.mq5 |
//|                                     Copyright 2019, Tabolin S.N. |
//|                           https://www.mql5.com/ru/users/vip.avos |
//+------------------------------------------------------------------+
#property   copyright    "Copyright 2019, Tabolin S.N."
#property   link          "https://www.mql5.com/ru/users/vip.avos"
#property   version      "1.07"
//#property   icon        "\\Images\\mi2.ico"
//----------------------------------------------------------------------------------------------
#define     GS           1.618
#define     PI           3.14159
//----------------------------------------------------------------------------------------------
#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots    1

#property indicator_label1    "myMA_S"
#property indicator_type1    DRAW_LINE
#property indicator_color1    clrRed
#property indicator_style1    STYLE_SOLID
#property indicator_width1    1 

//--- input parameters
input int       InpPeriodMA          = 45 ; // MA period
input int       InpShiftCorrection   = 9 ;   // Correction shift
//--- indicator buffers
double          Buffer1[];
int             handle_MA;                           // переменная для хранения хэндла индикатора HMA5
double          buffer_MA[];                         // массив для хранения значений индикатора HMA5
int             n= 0 ;
int             ma_bars_calculated = 0 ; 
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit ()
  {
   ArraySetAsSeries (Buffer1,         true );
   ArraySetAsSeries (buffer_MA,       true );

   PlotIndexSetDouble ( 0 , PLOT_EMPTY_VALUE ,- 1 );

   SetIndexBuffer ( 0 ,Buffer1, INDICATOR_DATA );
//--- set shortname and change label
   string short_name= "myMA_S(" +
                               IntegerToString (InpPeriodMA)+ "," +
                               IntegerToString (InpShiftCorrection)+ ")" ;
   IndicatorSetString ( INDICATOR_SHORTNAME ,short_name);
   PlotIndexSetString ( 0 , PLOT_LABEL ,short_name);
//--- set accuracy
   IndicatorSetInteger ( INDICATOR_DIGITS , _Digits );
//--- sets first bar from what index will be drawn
   PlotIndexSetInteger ( 0 , PLOT_DRAW_BEGIN ,InpPeriodMA);

   handle_MA = iMA ( Symbol (), 0 ,InpPeriodMA, 0 , MODE_SMA , PRICE_CLOSE );
   if (handle_MA == INVALID_HANDLE )                                       // проверяем наличие хендла индикатора
   {
       Comment ( "Не удалось получить хендл индикатора handle_MA" );         // если хендл не получен, то выводим сообщение в лог об ошибке
       Print ( "Не удалось получить хендл индикатора handle_MA" );
       return ( INIT_FAILED );                                                 // завершаем работу с ошибкой
   }

   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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[])
  {
   
   int ma_values_to_copy; 
   int ma_calculated = BarsCalculated (handle_MA); 
   if (ma_calculated <= 0 ){ 
       PrintFormat ( "BarsCalculated() вернул %d, код ошибки %d" ,ma_calculated, GetLastError ()); 
       return ( 0 ); 
     }  
   if (prev_calculated == 0 || ma_calculated != ma_bars_calculated || rates_total > prev_calculated + 1 ){ 
       if (ma_calculated > rates_total) ma_values_to_copy = rates_total; 
       else ma_values_to_copy = ma_calculated; 
     } else { 
      ma_values_to_copy = (rates_total - prev_calculated) + 1 ; 
     } 
     
   if ( CopyBuffer (handle_MA, 0 , 0 ,ma_values_to_copy,buffer_MA) < 0 ) // копируем данные из индикаторного массива в массив buffer_HMA5
   {                                                                                 // если не скопировалось
       Print ( "Не удалось скопировать данные из индикаторного буфера в buffer_MA" );    // то выводим сообщение об ошибке
       return ( 0 );                                                                     // и выходим из функции
   }

   for ( int i = 0 ; i < ma_values_to_copy; i++)
     {
      Buffer1[i]  = buffer_MA[i]+(buffer_MA[i+ 1 ]-buffer_MA[i+InpShiftCorrection])/(InpShiftCorrection/GS); //1.314;
     }
   
   return (rates_total);
  }
//+------------------------------------------------------------------+

어디가 잘못된거야?
파일:
my_MA_S.mq5  10 kb
 
Сергей Таболин :

MQL5

전혀 이해가 되지 않습니다. 여기 누군가 조언을 해 줄 수 있습니까?

어디가 잘못된거야?
두 개의 버퍼가 있지만 하나는 #property에 지정되어 있습니다.
 
Artyom Trishkin :
두 개의 버퍼가 있지만 하나는 #property에 지정되어 있습니다.

팁 고마워...

그러나 아무것도 바뀌지 않았습니다. 지표에서 나는 완전한 빼기입니다(((

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

#property indicator_label1    "myMA_S"
#property indicator_type1    DRAW_LINE
#property indicator_color1    clrRed
#property indicator_style1    STYLE_SOLID
#property indicator_width1    1 

//--- input parameters
input int       InpPeriodMA          = 45 ; // MA period
input int       InpShiftCorrection   = 9 ;   // Correction shift
//--- indicator buffers
double          Buffer1[];
int             handle_MA;                           // переменная для хранения хэндла индикатора HMA5
double          buffer_MA[];                         // массив для хранения значений индикатора HMA5
int             n= 0 ;
int             ma_bars_calculated = 0 ; 
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit ()
  {
   ArraySetAsSeries (Buffer1,         true );
   ArraySetAsSeries (buffer_MA,       true );

   PlotIndexSetDouble ( 0 , PLOT_EMPTY_VALUE ,- 1 );
   PlotIndexSetDouble ( 1 , PLOT_EMPTY_VALUE ,- 1 );

   SetIndexBuffer ( 0 ,Buffer1, INDICATOR_DATA );
   SetIndexBuffer ( 1 ,buffer_MA, INDICATOR_CALCULATIONS );
 
Сергей Таболин :

팁 고마워...

그러나 아무것도 바뀌지 않았습니다. 지표에서 나는 완전한 마이너스입니다 (((

모바일로 구분못함
 
Сергей Таболин :

팁 고마워...

그러나 아무것도 바뀌지 않았습니다. 지표에서 나는 완전한 마이너스입니다 (((

코드가 잘 보이지 않았고 오류가 어느 줄에 있는지 명확하지 않지만 어떻게 든 오류가 여기에 없습니다.

한도를 낮춰보세요

 for ( int i = 0 ; i < ma_values_to_copy - 5 ; i++)
 
Vitaly Muzichenko :

코드가 잘 보이지 않았고 오류가 어느 줄에 있는지 명확하지 않지만 어떻게 든 오류가 여기에 없습니다.

한도를 낮춰보세요

이 주기에 오류가 있습니다.

   for ( int i = 0 ; i < ma_values_to_copy; i++)
     {
      Buffer1[i]  = buffer_MA[i]+(buffer_MA[i+ 1 ]-buffer_MA[i+InpShiftCorrection])/(InpShiftCorrection/GS); // ошибка тут
     }

그러나 당신의 제안으로 인해 약간의 변화가 생겼습니다.

   for ( int i = 0 ; i < ma_values_to_copy-InpShiftCorrection; i++)
     {
      Buffer1[i]  = buffer_MA[i]+(buffer_MA[i+ 1 ]-buffer_MA[i+InpShiftCorrection])/(InpShiftCorrection/GS); //1.314;
     }

오류가 사라졌습니다. 감사해요 )))

 
mt5를 다운로드했습니다. 거래 계정을 위해. 실제 거래에 대한 지불을 어디서 어디서 하는지 알려주세요 ??? 나는 초보자입니다
 
Раиль Алеев :
mt5를 다운로드했습니다. 거래 계정을 위해. 실제 거래에 대한 지불을 어디서 어디서 하는지 알려주세요 ??? 나는 초보자입니다

컴퓨터를 켭니다. 브라우저를 다운로드합니다. 검색 창에서 "MetaTrader 5 계정 열기"라는 단어를 입력하십시오.

 
CodeBase에 "바당 하나의 거래" 기능이 있는 Expert Advisor가 있습니까(EA "바 열기" 제외)?
 

효과가 있었는지 아닌지?

입력 매개변수의 색상을 변경할 때 이 색상이 " indicator_color1 "에 있도록 하는 방법 "? 이제 변경하지 마십시오. 이니셜이 있습니다.

 #property indicator_type1    DRAW_LINE
#property indicator_color1    clrAqua


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[])
  {
   Comment ( indicator_color1 ); // постоянно clrAqua

   return (rates_total);
  }
사유: