ATR Example

Created at 01 Aug 2013, 01:21
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!
DO

DomnikInvest

Joined 18.04.2013

ATR Example
01 Aug 2013, 01:21


Hi,

 

can you pleas show one example how to use AverageTrueRange with robot.


@DomnikInvest
Replies

cAlgo_Fanatic
02 Aug 2013, 17:52

You can use any of the cAlgo.API.Indicators in Robots by declaring, initializing and then accessing them by the given name.

An example with AverageTrueRange is such as this:

        // Declare
        private AverageTrueRange atrIndicator;

        [Parameter(DefaultValue = 20)]
        public int Period { get; set; }

        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MAType { get; set; }

        [Parameter(DefaultValue = 0.002)]
        public double ATRValue { get; set; }

        protected override void OnStart()
        {
            // Initialize
            atrIndicator = Indicators.AverageTrueRange(Period, MAType);            
        }

        protected override void OnTick()
        {            
            //If atrIndicator last value is greater than the ATRValue input
            if (atrIndicator.Result.LastValue > ATRValue)
            {
                //Do something
                Print("LastValue {0}", atrIndicator.Result.LastValue);
            }
            //...
        }




@cAlgo_Fanatic