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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      639 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      366 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      107 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      569 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      572 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X