Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with input series in indicator

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Problem with input series in indicator

    I am attempting to develop an indicator that plots 5 minute time series 21 sma and 9 ema line on any timeframe chart. Following is the code, however, the lines plot as the data series' "Input Series" is configured. Does this code not override the setting in the properties of the indicator?

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class MyCustomIndicator : Indicator
    {
    private SMA sma21;
    private EMA ema9;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Adds 5-minute 21 SMA and 9 EMA to any chart";
    Name = "5 Minute 21 sma and 9 ema";
    Calculate = Calculate.OnEachTick;
    IsOverlay = true;
    DisplayInDataBox = true;
    //AddPlot(new Stroke(Brushes.Crimson, 2), PlotStyle.Line, "sma");
    //AddPlot(new Stroke(Brushes.Goldenrod, 2), PlotStyle.Line, "ema");
    AddPlot(new Stroke(Brushes.Pink, DashStyleHelper.Dash, 3, 100), PlotStyle.Line, "sma");
    AddPlot(new Stroke(Brushes.Purple, DashStyleHelper.Dash, 2, 75), PlotStyle.Line, "ema");
    //AddPlot(Brushes.Goldenrod, "ema");
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minute, 5);
    sma21 = SMA(BarsArray[1], 21);
    ema9 = EMA(BarsArray[1], 9);

    // Set the plot colors
    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBars[1] < 1)
    return;

    Values[0][0] = sma21[0];
    Values[1][0] = ema9[0];
    //Print(Time[0] + " SMA " + Values[0][0]);
    //Print(Time[0] + " EMA " + Values[1][0]);

    }
    }
    }

    #2
    Hello qwiksilver96,

    Thank you for your post.

    I see you are adding the 5-minute data series in State.Configure, though when you are setting the plot values to equal the indicator values, you will need to refer to the desired input series. We have a page about multi-time frame and instruments that includes a section about using different bars objects as the input for indicators here:


    Once you specify the input series for the indicator, the plots should match the EMA and SMA for the desired series.

    Please let us know if we may be of further assistance.

    Comment


      #3
      THANK YOU! I overlooked that one small detail. Your answer helped me correct the issue. It is now working.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      67 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      150 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      162 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      99 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      287 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X