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

Multiple Data Series.

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

    Multiple Data Series.

    I was hoping that someone could help me as I am trying to learn NinjaScript. Is is possible to code an sma 8 period with a chart on a 15 minute time frame then code a second sma 8 period pulling data from a daily chart or another minute time frame like a 240 minute time frame?

    Thanks in advance for you help.

    #2
    Hello,

    Thanks for your post.

    This is certainly possible. When you apply your strategy to a chart, the data series in that chart will be the primary data series of the strategy. You would add whatever data series you wanted to State.Configure, in this case your 1 day series and your 240 minute series. Next, you would add your SMA's in OnBarUpdate using Closes[][] as the input. Closes is used whenever you need to access closing prices for multiple instruments or multiple time frames.

    I have created an example of doing this is the code snippet below.

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

    AddDataSeries(Data.BarsPeriodType.Day, 1);

    AddDataSeries(Data.BarsPeriodType.Minute, 240);

    }

    }

    protected override void OnBarUpdate(){
    double mySMA0 = SMA(Closes[0][0],13);

    double mySMA1 = SMA(Closes[1][0],13);

    double mySMA2 = SMA(Closes[2][0],13);

    }


    There is a great strategy reference sample built into NT8 called SampleMACrossover that I recommend checking out as well. You may find this sample in the Strategies folder inside of the NinjaScript editor.

    I am also including a link below to our help guide documentation on Multiple Times Frames and Instruments, SMA, and Closes, for your convenience.

    SMA
    https://ninjatrader.com/support/help...simple_sma.htm

    Closes
    https://ninjatrader.com/support/help...us/?closes.htm

    Multi-Time Frame & Instruments
    https://ninjatrader.com/support/help...nstruments.htm

    Please let me know if you have any further questions.
    Last edited by NinjaTrader_JoshG; 10-26-2017, 03:42 PM.
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your help.

      Comment


        #4
        I attempted to use the code that you provide but I am unable to get the moving average from the Daily chart or the 240 min chart plot on my 15 minute chart. Does this code work for indicators or just strategies?

        Comment


          #5
          Hello,
          This code would work for an indicator or a strategy. Have you added the plots that you wanted to your code, using AddPlot() ?
          AddPlot()
          https://ninjatrader.com/support/help...s/?addplot.htm
          You can always open up one of the pre-existing indicators you like as well to see how this is done.
          Please let me know if you have any further questions.
          Josh G.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by wzgy0920, 04-20-2024, 06:09 PM
          2 responses
          26 views
          0 likes
          Last Post wzgy0920  
          Started by wzgy0920, 02-22-2024, 01:11 AM
          5 responses
          32 views
          0 likes
          Last Post wzgy0920  
          Started by wzgy0920, 04-23-2024, 09:53 PM
          2 responses
          49 views
          0 likes
          Last Post wzgy0920  
          Started by Kensonprib, 04-28-2021, 10:11 AM
          5 responses
          193 views
          0 likes
          Last Post Hasadafa  
          Started by GussJ, 03-04-2020, 03:11 PM
          11 responses
          3,235 views
          0 likes
          Last Post xiinteractive  
          Working...
          X