ATR indicator

Created at 12 Nov 2018, 08:17
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
ZH

zhuyeaini

Joined 09.11.2018

ATR indicator
12 Nov 2018, 08:17


Hi:

my code is this:

        DonchianChannel mBreakIndicator;
        AverageTrueRange mAtrIndicator;
        protected override void OnStart()
        {
            mBreakIndicator = Indicators.DonchianChannel(mBreakPeriod);
            mAtrIndicator = Indicators.AverageTrueRange(mAtrPeriod, MovingAverageType.Simple);
        }

        protected override void OnTick()
        {
        }

        protected override void OnBar()
        {
            Print(mBreakIndicator.Bottom);
            Print(mAtrIndicator.Result);
        }

then I start backtest,

And I show the ATR in the chart,but I find that the print value is not same as the value shows in chart!!!

the ATR have same period 14,and same MovingAverageType.Simple,but value not same! why?


@zhuyeaini
Replies

PanagiotisCharalampous
12 Nov 2018, 12:58

Hi zhuyeaini,

I tried it and works fine for me. Can you share some screenshots with what you see?

Best Regards,

Panagiotis

 


@PanagiotisCharalampous

zhuyeaini
13 Nov 2018, 14:43 ( Updated at: 21 Dec 2023, 09:20 )

RE:

Panagiotis Charalampous said:

Hi zhuyeaini,

I tried it and works fine for me. Can you share some screenshots with what you see?

Best Regards,

Panagiotis

 

 

See above screenshot.


@zhuyeaini

PanagiotisCharalampous
13 Nov 2018, 14:59

Hi zhuyeaini,

The reason you see this discrepancy is because you print the value of the bar at the opening of the bar but the indicator calculates the value when the bar closes and the data is finalized. If you want to print finalized calculations of the indicator values, you should print mAtrIndicator.Result.Last(1).

Best Regards,

Panagiotis


@PanagiotisCharalampous