Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

MultiTF and Indicator Instances

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

    MultiTF and Indicator Instances

    Hi NT Support,

    is it possible to use stored indicator instances on secondary time frames, or must the indicator be instantiated with each on-bar-update? If you could review the attached and let me know if I've done something wrong, I would greatly appreciate it.

    Example attached. Strategy adds a secondary time frame of one minute. I create two instances of SMA(50), one on primary series (plot SMA0) and one on secondary series plot SMA1) . For demonstration purposes I also add plot SMA2 and SMA3 which are a SMA(50) instantiated on bar update for each series. So, 4 plots in total. Red, orange, yellow, green.

    When activating the strategy on a 5-minute chart, I would expect Red and Yellow to plot together (tracking SMA 50 primary series) , and Orange and Green to plot together (tracking SMA 50 on secondary series). But the result is that only the green plot which is not using a stored indicator-instance plots the correct secondary-bar-series value.

    I've attached a screenshot with the data box showing that plot SMA1 (which I want to show the same value as SMA3) is instead using the primary dataseries and getting the same values as those plots instead.

    snippet:
    Code:
    //…...
     AddPlot(Brushes.Red, "SMA0");
        AddPlot(Brushes.Orange, "SMA1");
        AddPlot(Brushes.Yellow, "SMA2");
        AddPlot(Brushes.Green, "SMA3");
       }
       else if (State == State.Configure)
       {
        AddDataSeries(Data.BarsPeriodType.Minute, 1);
        sma0 = SMA(50); // an SMA using the primary bar series
        sma1 = SMA(BarsArray[1], 50); // an SMA using the 1-minute bar series?
       }
      }
    
      protected override void OnBarUpdate()
      {
       //Add your custom strategy logic here.
       if (BarsInProgress == 0)
       {
        if (CurrentBar > 50 && sma0.IsValidDataPoint(0)) SMA0[0] = sma0[0]; //set red plot using primary bar series
        if (CurrentBar > 50 && sma1.IsValidDataPoint(0)) SMA1[0] = sma1[0]; //set orange plot using bar series 1
        if (SMA(50).IsValidDataPoint(0) && CurrentBar > 50) SMA2[0] = SMA(50)[0]; // set yellow plot using primary bar series
       }
    
       if (BarsInProgress == 1)
       {
        if (SMA(50).IsValidDataPoint(0) && CurrentBar > 50) SMA3[0] = SMA(50)[0]; // set green plot using bar series 1
    
       }
      }
    Attached Files

    #2
    Hello greagrea,

    The call to AddDataSeries() is in the correct place.

    However, indicators should not be called until the State becomes State.DataLoaded.

    Below is a public link to the help guide on OnStateChange().


    Also, the script does not add the indicators to the chart with AddChartIndicator. So the indicators already on the chart, were manually added and are probably not using the data that the indicator in the strategy is using.

    Below is a public link to the help guide on AddChartIndicator().


    Also, where you call 'SMA(50).IsValidDataPoint(0)', I think you were meaning to have 'sma0.IsValidDataPoint(0)'.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello greagrea,

      The call to AddDataSeries() is in the correct place.

      However, indicators should not be called until the State becomes State.DataLoaded.
      Thank you for the reminder about State.DataLoaded. Placing the indicator calls in the State.DataLoaded state fixed my issue. The bit about AddChartIndicator I don't think applies -- there are no indicators on the chart and no indicators were added manually in my example -- I am using Plots added within the strategy, and setting the strategy plots from the indicator values within the strategy script.

      I can see why it may be easier in some cases to just use AddChartIndicator and appreciate the tip.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by judysamnt7, 03-13-2023, 09:11 AM
      4 responses
      53 views
      0 likes
      Last Post DynamicTest  
      Started by ScottWalsh, Today, 06:52 PM
      4 responses
      33 views
      0 likes
      Last Post ScottWalsh  
      Started by olisav57, Today, 07:39 PM
      0 responses
      5 views
      0 likes
      Last Post olisav57  
      Started by trilliantrader, Today, 03:01 PM
      2 responses
      19 views
      0 likes
      Last Post helpwanted  
      Started by cre8able, Today, 07:24 PM
      0 responses
      6 views
      0 likes
      Last Post cre8able  
      Working...
      X