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

Two multi-timeframe hosted indicators doesn't showing in chart (Strategy)

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

    Two multi-timeframe hosted indicators doesn't showing in chart (Strategy)

    Hi!

    I can't see in the chart a second hosted indicator with second series input. Just I see the indicator but with primary data series besides is declarated with second data series.

    I'm on two minutes chart.
    ---------------------------------------------------------------------------------

    public class test : Strategy
    {

    private SMA sma50;
    private SMA sma50_2;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {​
    ....
    }
    else if (State == State.Configure)
    {​

    AddDataSeries(BarsPeriodType.Minute, 15);


    sma50 = SMA(Close, 50);
    sma50.Plots[0].Brush = Brushes.White;​

    sma50_2 = SMA(Closes[1], 50);
    sma50_2.Plots[0].Brush = Brushes.Yellow;​

    }
    else if (State == State.DataLoaded)
    {​
    AddChartIndicator(sma50);
    AddChartIndicator(sma50_2);
    }​


    protected override void OnBarUpdate()
    {​
    ....
    }
    }

    #2
    Hello franjcy,

    Thanks for your post.

    The code you shared adds a secondary 15-minute data series to the script to use for calculations.

    The sma50_2 indicator is an SMA indicator set to use the Close series of the added secondary series for its calculation.

    Note that AddDataSeries() adds a secondary series to use for calculations within the script. The secondary series will NOT be visible on the Chart window when enabling the strategy on the Chart. There are no means available for having the secondary series be displayed on the chart when the strategy is enabled on the chart.

    See this help guide page for more information about AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm

    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_BrandonH View Post
      Hello franjcy,

      Thanks for your post.

      The code you shared adds a secondary 15-minute data series to the script to use for calculations.

      The sma50_2 indicator is an SMA indicator set to use the Close series of the added secondary series for its calculation.

      Note that AddDataSeries() adds a secondary series to use for calculations within the script. The secondary series will NOT be visible on the Chart window when enabling the strategy on the Chart. There are no means available for having the secondary series be displayed on the chart when the strategy is enabled on the chart.

      See this help guide page for more information about AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm
      I read it but I still have doubts.

      You said "The sma50_2 indicator is an SMA indicator set to use the Close series of the added secondary series for its calculation." but when I print "sma50[0] and "sma50_2[0]" they print the same output.

      As well I read the hosted indicator has to be the same "AddDataSeries()" inside her code. So, Would I have to modify the source font of the original SMA if i want to use the 2 SMAs ?
      Last edited by franjcy; 02-12-2024, 10:04 AM.

      Comment


        #4
        Hello franjcy,

        Thanks for your notes.

        When testing this on my end I am seeing different values print to the NinjaScript Output window for the SMA calculating from the primary series and the SMA calculating from the secondary series.

        See the attached screenshot.

        I have also attached the test script used to test this so you may try it on your end.

        "As well I read the hosted indicator has to be the same "AddDataSeries()" inside her code."

        No, you do not need to modify the SMA indicators code to also call AddDataSeries().

        "Should your script be the host for other scripts that are creating indicators and series dependent resources in State.DataLoaded, please make sure that the host is doing the same AddDataSeries() calls as those hosted scripts would. For further reference, please also review the 2nd example below and the 'Adding additional Bars Objects to NinjaScript' section in Multi-Time Frame & Instruments​"

        This note from the AddDataSeries() help guide indicates that if the indicator script calls AddDataSeries() and a custom NinjaScript strategy is the host for the indicator, you must call the same AddDataSeries() call in the strategy that the indicator is using.

        For example, if an indicator calls AddDataSeries() to add a 15-minute secondary series and you use the indicator in a NinjaScript strategy, that NinjaScript strategy also needs to call AddDataSeries() to add a 15-minute secondary series.

        AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm
        Attached Files
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_BrandonH View Post
          Hello franjcy,

          Thanks for your notes.

          When testing this on my end I am seeing different values print to the NinjaScript Output window for the SMA calculating from the primary series and the SMA calculating from the secondary series.

          See the attached screenshot.

          I have also attached the test script used to test this so you may try it on your end.

          "As well I read the hosted indicator has to be the same "AddDataSeries()" inside her code."

          No, you do not need to modify the SMA indicators code to also call AddDataSeries().

          "Should your script be the host for other scripts that are creating indicators and series dependent resources in State.DataLoaded, please make sure that the host is doing the same AddDataSeries() calls as those hosted scripts would. For further reference, please also review the 2nd example below and the 'Adding additional Bars Objects to NinjaScript' section in Multi-Time Frame & Instruments​"

          This note from the AddDataSeries() help guide indicates that if the indicator script calls AddDataSeries() and a custom NinjaScript strategy is the host for the indicator, you must call the same AddDataSeries() call in the strategy that the indicator is using.

          For example, if an indicator calls AddDataSeries() to add a 15-minute secondary series and you use the indicator in a NinjaScript strategy, that NinjaScript strategy also needs to call AddDataSeries() to add a 15-minute secondary series.

          AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm
          Thanks Brandon for your reply.

          Thanks to your example i saw my error: I'd putted the assignment of EMAs inside " (State == State.Configure)" so when i putted on DataLoaded it prints different values.

          Also I understood about hosted indicators and multi time series.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by fx.practic, 10-15-2013, 12:53 AM
          5 responses
          5,404 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by Shai Samuel, 07-02-2022, 02:46 PM
          4 responses
          95 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by DJ888, Yesterday, 10:57 PM
          0 responses
          8 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by MacDad, 02-25-2024, 11:48 PM
          7 responses
          159 views
          0 likes
          Last Post loganjarosz123  
          Started by Belfortbucks, Yesterday, 09:29 PM
          0 responses
          8 views
          0 likes
          Last Post Belfortbucks  
          Working...
          X