Can't initiate standard indicators in OnInit

To add comments, please log in or register
Philip Pankaj
3539
Philip Pankaj  

Indicator is working fine in OnCalculate,OnTick,OnTimer but why not in OnInit. Is there any other option to load indicator data on Initialization.?

int OnInit()

  {

   double mabuff[];

   ArraySetAsSeries(mabuff,true);

   int ma=iMA(_Symbol,_Period,14,0,MODE_SMA,PRICE_CLOSE);

   if(CopyBuffer(ma,0,0,2,mabuff)==-1)

   {

    Print("error in loading Inidcator data");

   }

   return(INIT_SUCCEEDED);

  }


2020.05.17 21:29:19.736 MA ONINIT (USDCAD,H1) error in loading Inidcator data

Main Idea I'm looking for is,I want to load indicator data only once in beginning.

Thanks,

Philip Pankaj


amando
2908
amando  
Read the documentation for copybuffer, this is wron in oninit
William Roeder
21958
William Roeder  
Perhaps you should read the manual, especially the examples. They all (including iCustom) return a handle (an int.) You get that in OnInit. In OnTick (after the indicator has updated its buffers,) you use the handle, shift and count to get the data.
          Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
          Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08
          How to call indicators in MQL5 - MQL5 Articles 12 March 2010

Also see my example for encapsulating calls
          Detailed explanation of iCustom - MQL4 programming forum 2017.05.23

To add comments, please log in or register