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

Second time frame indicator in strategy

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

    Second time frame indicator in strategy

    I'm afraid this has been discussed a million times in this forum,but I just can't find the solution. I want to plot an indicator that is based on a second time frame by adding it in the Initialize() of a strategy.The second PeriodType is also added in the Initialize(). I tried something like
    Add(PeriodType.Day, 1);
    Add(SMA(200)[1]);
    but that's obviously the wrong syntax.

    #2
    Hello Loki45,

    Thank you for your note.

    You could use the following in NinjaTrader 7,

    Code:
    Add(PeriodType.Minute, 5); 
    Add(SMA(Closes[1], 20));
    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the help, but somehow it didn't do the trick. When I run the strategy analyzer, the indicator plots are based on the timeframe of the analyzer, which happens to be 30 minutes, not on the daily, as it should be per my Initialize();
      Add(PeriodType.Day, 1);
      Add(SMA(Closes[1],200));
      Add(SMA(Closes[1],5));
      What am I doing wrong?

      Comment


        #4
        Hello Loki45,

        So I may test on my end please provide a script which demonstrates this behavior.

        Please export the script using the following format,

        To export a NinjaScript from NinjaTrader 7 do the following:
        From the Control Center window select File -> Utilities-> Export NinjaScript...
        Select the file in the left column then click “>”, then press export and name the file.
        Then attach that file you saved; under My Docs>NT7>Bin>Custom>Select the downloaded .zip file.

        I look forward to you reply.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Here is the script.
          Attached Files

          Comment


            #6
            Hello Loki45,

            Your references to the SMA within OnBarUpdate are not specifying the secondary series.

            For example,

            Code:
                 if (Highs[1][0] > SMA(200)[1]
            Should be,

            Code:
            if (Highs[1][0] > SMA(Closes[1],200)
            If after making the change, do you see the results you’d expect?

            I look forward to your reply.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              I want the conditional entries in the OnBarUpdate() being dependant on the primary series, and the SMA plot in the strategy analyzer chart window on the secondary series.

              Comment


                #8
                Sorry, disregard what I just said.

                Comment


                  #9
                  Ok, so I tried the code you provided, and I'm getting this error message for all 4 lines that I changed according to your suggestion:

                  if (Highs[1][0] > SMA(Closes[1],200)

                  Operator '>' cannot be applied to operands of type 'double' and 'NinjaTrader.Indicator.SMA'

                  What's wrong?

                  Comment


                    #10
                    Hello Loki45,

                    Use,

                    if (Highs[1][0] > SMA(Closes[1],200)[0])

                    Please let us know if you need further assistance.
                    Alan P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Barry Milan, Today, 10:35 PM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by WeyldFalcon, 12-10-2020, 06:48 PM
                    14 responses
                    1,428 views
                    0 likes
                    Last Post Handclap0241  
                    Started by DJ888, Yesterday, 06:09 PM
                    2 responses
                    9 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by jeronymite, 04-12-2024, 04:26 PM
                    3 responses
                    40 views
                    0 likes
                    Last Post jeronymite  
                    Started by bill2023, Today, 08:51 AM
                    2 responses
                    16 views
                    0 likes
                    Last Post bill2023  
                    Working...
                    X