iBars() does not work on weekends?

 

Dear Members

I am iBars() in a indicator Class and it was working perfectly fine even on Saturday (Weekend).

I than updated MT5 to the latest update released and after starting again, I was getting 0 values from iBars().

I wasted couple of hours to find cause in my code, just to realize that iBar() was returning 0, instead of actual bars. Though before update it was returning the actual bars.

Can someone please explain me the correct status, so I can rely on iBar or not?

Thanks in advance

Regards.

 

It was not “working perfectly fine even on Saturday.” Most markets are closed. No ticks. No running code. You just saw the last value.

You now see zero, because you created the display in OnInit, but OnCalculate has not run.

 
William Roeder #:

It was not “working perfectly fine even on Saturday.” Most markets are closed. No ticks. No running code. You just saw the last value.

You now see zero, because you created the display in OnInit, but OnCalculate has not run.

Thanks @William Roeder for confirmation about 'No Ticks' which I thought could be the reason.

I have actually created indicator class (using one of tutorial from YouTube), which acts as an indicator itselft (with manual management buffer, rates_total and prev_calculated values), so I can access indicator values in EA directly from this Class.

However, while testing I need to visualize indicator results so I have created an indicator, which simply calls data from IndicatorClass buffers.

Currently I have resolved this issue by passing in rates_total values (instead of calculating it by use of iBar()) to the indicatorClass.

I can foresee problem when I use this IndicatorClass in EA directly and will be forced to use iBars to find the rates_total value. On weekend this may cause IndicatorClass to get false or zero results and 'array out of range' error will stop EA from running.

Is there a way I can use OnCalculate() in IndicatorClass(mqh file) or any other method to find number of bars on chart (Buffers will be managed based on this information)?

Thanks once again for your valuable suggestion.

 

Anil Varma #:so I can access indicator values in EA directly from this Class.

I can foresee problem when I use this IndicatorClass in EA directly and will be forced to use iBars to find the rates_total value. 

  1. Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:
    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password, connection to server begins.
    6. New history is received, OnCalculate called again.
    7. A new tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

  2. There is no rates_total in EAs. You will have to use iBars, in OnTick, not in OnInit.

 
William Roeder #:
  1. Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:
    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password, connection to server begins.
    6. New history is received, OnCalculate called again.
    7. A new tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

  2. There is no rates_total in EAs. You will have to use iBars, in OnTick, not in OnInit.


Thanks a lot @William Roeder for the complete step by step process of EA/Indicator working. A great piece of information.

"There is no rates_total in EAs. You will have to use iBars, in OnTick, not in OnInit."

... by this I meant that my IndicatorClass have method UpdateData(int pRates_Total,int pIdx) and I call this method from Indicator with cCandlePatterns.UpdateData(rates_total,currIdx). This enables me to receive rates_total value in the IndicatorClass.

Currently I have following checks in the EA:

                // CHECK AND EXIT, IF TRADING IS NOT ALLOWED
          if(!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED))        return;
          if(!MQLInfoInteger(MQL_TRADE_ALLOWED))                  return;
          if(!AccountInfoInteger(ACCOUNT_TRADE_EXPERT))           return;
          if(!AccountInfoInteger(ACCOUNT_TRADE_ALLOWED))          return;

and following check in the StrategyBase and CBaseExpert Class(s)

          // IF NOT CONNECTED TO BROKER SERVER, EXIT AND TRY AGAIN
          if(!SymbolInfoTick(mSymbol,mLastTick))            	  return;
void CBaseExpert::OnTick() {

// SANITY CHECK, IF TRADING ALLOWED ON THE CBaseExpert's SYMBOL AT CURRENT TIME
if(!cAuxiliary.IsMarketOpen(vSymbolParam.symbol,TimeCurrent())) {
	PrintFormat("%s IsMarketOpen[%s]",vMethod,(string)cAuxiliary.IsMarketOpen(vSymbolParam.symbol,TimeCurrent()));
        return;
}

cBaseStrategy.OnTick();

cMeanReversion.OnTick();

} // END of function OnTick()

Seems I am facing this problem due to the fact that I am using Indicator class independently while testing the indicator, and not through EA or StrategyBase Class.

I can also think of using SymbolInfoTick() along with iBars() to make sure that the new tick has arrived, so will not be getting Zero values from iBars()

Let me continue developing IndicatorClass fully and incorporate into EA, if I still face problem I will revert back to the forum.

Thanks again and regards.