I'm making an indicator where I need open close high low of each bar.
the problem is that open[i] == close[i] == high[i] == low[i] so if I need to compute Log(close[i]/open[i]); I always get zero!!
why is that happening?
I've used the debugger on mt5 built in indicators (ex ATR) that uses OHLC and the same equality occurs.
for example ATR uses:
where in the debugger I get High[i] == Low[i]
can someone explain?
why the same is happening in ATR code? I don't think it's bugged since it's mql5 built in indicator
am I using wrongly the debugger?
here the oncalculate of ATR indicator made by metaquote programmers (I suppose)
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 &TickVolume,
const long &Volume,
const int &Spread)
//--- check for bars count
return(0); // not enough bars for calculation
//--- preliminary calculations
//--- filling out the array of True Range values for each period
for(i=1;i<rates_total && !IsStopped();i++)
//--- first AtrPeriod values of the indicator are not calculated
//--- calculating the first value of the indicator
//--- the main loop of calculations
for(i=limit;i<rates_total && !IsStopped();i++)
//--- return value of prev_calculated for next call
if in debugging I add a watch on Low[i] and High[i] whatever "i" is they have the same value.
btw you wrote that i=index of current candle in case H==L==C==O so should I use i-1 to get the previous (formed) candle?
Here a screenshot of a debugging session for ATR indicator, debug point on the first line of the loop :
This is for i=21 so an old candle. The current candle in this case has an index of rates_total-1 (10389) and the last closed candle an index of rates_total-2 (10388).
Next is the values for the first tick of a new candle :
Here, as you see all values are equal (open, high, low, close). i = rates-total-1 so current (open) candle.
Is that help ?
yes it helps a lot, I don't know what have i done wrong during debugging, but the concept is clear now. I'm going to debug again and let you know if it works.
I'm sorry there's something I'm still missing.
the following screenshot is dureing ATR debugging:
i=77 is an old completely formed candle but O==C==H==L
and it's the same for all i>14 up to 77 then I stopped clicking
the concept you explained is clear but the output of my debugger is different from yours.
do you have any clue?
data corrupted? bars not formed properly?
what can I check?
You probably have bad or corrupted data. Do you checked the corresponding chart ? You can also try with other symbol/timeframe.
yes it is bad data on other pairs everything works fine, even my indicator
thanks a lot