Domande dai principianti MQL5 MT5 MetaTrader 5 - pagina 1010

 

MQL5

Non riesco a farlo funzionare. Qualcuno può suggerire qualcosa?

Forum sul trading, sistemi di trading automatico e test di strategia

Qualcuno può per favore darmi un suggerimento.

Sergey Tabolin, 2019.03.07 08:14

Basandomi su un indicatore del codebase ho scritto un esempio di ciò che voglio. Funziona. Ma dà un errore all'avvio:

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

Puoi dirmi dov'è l'errore?

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

Cosa c'era di sbagliato?
File:
my_MA_S.mq5  10 kb
 
Сергей Таболин:

MQL5

Non riesco a farlo funzionare. Qualcuno può darmi un suggerimento?

Cosa c'è che non va?
Due buffer, ma la #proprietà ne specifica uno
 
Artyom Trishkin:
Due buffer e la #proprietà ne specifica uno

Grazie per il suggerimento...

Ma nulla è cambiato. Sono un totale meno negli indicatori (((

#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);
 
Сергей Таболин:

Grazie per il suggerimento...

Ma nulla è cambiato. Sono un totale meno negli indicatori (((

Non posso dirlo da un telefono cellulare
 
Сергей Таболин:

Grazie per il suggerimento...

Ma nulla è cambiato. Sono un totale meno negli indicatori ((

Non ho guardato bene il codice e non è chiaro in quale linea sia l'errore, ma come se l'errore non fosse qui.

Prova a ridurre il limite

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

Non ho guardato bene il codice e non è chiaro in quale linea sia l'errore, ma non è che l'errore sia qui.

Prova a ridurre il limite

L'errore è esattamente in questo ciclo.

   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);// ошибка тут
     }

Ma il tuo suggerimento mi ha spinto a fare un piccolo cambiamento:

   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;
     }

L'errore è sparito. Grazie )))

 
Ho scaricato mt5 per il mio conto di trading. Sono un principiante, dove andare e dove pagare per il trading reale?
 
Раиль Алеев:
Ho scaricato mt5 per il mio conto di trading. Puoi dirmi dove e come pagare per il trading reale? Sono un novellino.

Accendere il computer. Avvia il tuo browser. Nella barra di ricerca digiti le parole "aprire un conto MetaTrader 5".

 
CodeBase ha un EA con la funzione "un trade per barra" (escluso EA "all'apertura della barra")?
 

Ha mai funzionato o no?

Come posso fare in modo che quando si cambia un colore nei parametri di input, questo colore sia in"indicator_color1"? In questo momento, non importa come lo cambi, è l'originale

#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);
  }
Motivazione: