for example, certain candle has a High-Low= 0.75 (Candle size), I look at the ATR and it 0.80 but the printout of the ATR is 0.0089.
I tried to find a correlation between those values but could not find it, to consecutive ATR values may be 0.160714285714286 and 1.10714285714286 with no significant difference on the candle size.
thie portion of the code was extracted from ATR indicator
double trueRange = Math.Max(Math.Abs(low0 - close1), Math.Max(high0 - low0, Math.Abs(high0 - close1)));
atr = ((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period);
Output for debugging.
22/8/2019 12:58:00 p. m. CandleSize: 1.25 ATR Calcation: 0.0892857142857143
22/8/2019 1:00:00 p. m. CandleSize: 1.25 ATR Calcation: 0.0892857142857143
22/8/2019 1:02:00 p. m. CandleSize: 1.25 ATR Calculation: 0.0892857142857143
22/8/2019 12:30:00 p. m. CandleSize: 2.25 ATR Calculation: 0.160714285714286
22/8/2019 12:31:00 p. m. CandleSize: 2.5 ATR Calculation: 1.10714285714286
Any clue??
Thanks in advance, Marcelo
protected override void OnBarUpdate()
{
double high0 = High[0];
double low0 = Low[0];
double CandleSize=high0-low0;
double atr=0;
if (CurrentBar == 0)
atr = high0 - low0;
else
{
double close1 = Close[1];
double trueRange = Math.Max(Math.Abs(low0 - close1), Math.Max(high0 - low0, Math.Abs(high0 - close1)));
atr = ((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period);
}
if(CandleSize > atr * Multiplier)
{
Print(Time[0] + " CandleSize: " + CandleSize + " ATR Calculation: " + atr);
Value[0]=1;
}
else
{
Value[0]=0;
}
}
Comment