What's fron with referencing the indicator?

Created at 06 Aug 2013, 22:03
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!
IR

iRobot

Joined 17.02.2013

What's fron with referencing the indicator?
06 Aug 2013, 22:03


I want to reference to DEMA indicator in my robot, but I don't understand why I can't do that.

Indicator is working, I reference it in the robot, I declare it, but it's not recognized.

I know it is super simple question, but pls help someone.

 

Indicator:

 

using System;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true)]
    public class DEMA : Indicator
    {
        [Parameter]
        public DataSeries DataSource { get; set; }
        
        [Output("DEMA",Color = Colors.Yellow)]
        public IndicatorDataSeries dema { get; set; }

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

        private ExponentialMovingAverage ema;
        private ExponentialMovingAverage ema2;
        
        protected override void Initialize()
        {
            ema = Indicators.ExponentialMovingAverage(DataSource,Period);//i need the correct DataSeries
            ema2 = Indicators.ExponentialMovingAverage(ema.Result,Period);
        }
        
        public override void Calculate(int index)
        {
           dema[index] = (2* ema.Result[index] - ema2.Result[index]);
        }
    }
}


@iRobot
Replies

cAlgo_Fanatic
07 Aug 2013, 09:59

RE:

iRobot said:

I want to reference to DEMA indicator in my robot, but I don't understand why I can't do that.

Indicator is working, I reference it in the robot, I declare it, but it's not recognized.

I know it is super simple question, but pls help someone.

Please follow these steps to add a reference of the indicator in the robot.

  1. Click the Add Reference button next to Build button in the text editor and 
  2. Locate the indicator file from the cAlgo\Sources\Indicators folder. Make sure you build the indicator first.
  3. Declare the indicator
    private DEMA demaIndicator;
  4. Initialize it
    protected override void OnStart()
    {
         demaIndicator =  Indicators.GetIndicator<DEMA>(DataSource, Period);
    }
  5. Now you can access the Indicator values in a method like OnBar or OnTick
    protected override void OnBar()
    {
        double lastValue = demaIndicator.dema.LastValue;
        //...
    }

 

 


@cAlgo_Fanatic