Trouble Accessing Custom Indicators DataSeries

Created at 27 Nov 2020, 09:14
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!
RO

RoboHedge.Fund

Joined 27.11.2020

Trouble Accessing Custom Indicators DataSeries
27 Nov 2020, 09:14


Overview

I have developed a zero-lag MACD custom indicator Which works fine. The indicator also generates buy/sell signals both visually on the indicator chart and as two output IndicatorDataSeries as follows:

 

 [Output("SellSignalOutput")]
  public IndicatorDataSeries SellSignalOutput { get; set; }

  [Output("BuySignalOutput")]
  public IndicatorDataSeries BuySignalOutput { get; set; } 

The Problem

I am having trouble accessing these two output variables successfully.

The code below shows how i am trying to use them. The code inside the if statements never executes.

 

protected override void OnTick()
        {
            double BuySignal = myZlag.BuySignalOutput.LastValue;
            double SellSignal = myZlag.SellSignalOutput.LastValue;

            if (BuySignal == 1 )
            {
                //Do Stuff
            }
            else if (SellSignal == 1 )
            {
                //Do Stuff
            }
        }

Other Useful Info

Within the indicator set or cancel buy/sell signals like this.

if (_buy)
{
              
  BuySignalOutput[0] = 1;
  SellSignalOutput[0] = 0;
 
}else if (_sell)
{

  SellSignalOutput[0] = 1;
  BuySignalOutput[0] = 0;

}

I am creating an instance of the indicator as follows in the onStart() of my cBot

protected override void OnStart()
        {
            //import the zero lag indicator
            myZlag = Indicators.GetIndicator<ZLagMACDIndicator>(Source, FastPeriod, SlowPeriod, SignalPeriod);
        }

 

Thanks in advance for your help 

Kind Regards

Geoff

 


@RoboHedge.Fund
Replies

RoboHedge.Fund
27 Nov 2020, 09:34 ( Updated at: 27 Nov 2020, 09:35 )

SOLVED

Hi All, I found the issue - there was some code that sometimes failed before assigning the signals I have moved the assignment of the signals above that code and will add some error handling to prevent in the future.

 

I also changed 

double BuySignal = myZlag.BuySignalOutput.LastValue;

to

double BuySignal = myZlag.BuySignalOutput.Last(0);

 

I'll leave this post here incase this helps someone else in the future


@RoboHedge.Fund