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

Getting SMA values of a specific-period bar chart

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

    Getting SMA values of a specific-period bar chart

    Hi all,

    I want to know how to get the value of 10-period SMA, where the lengh of a period is configurable (e.g. 1 period can be 30 minutes (30-minute bar) or 1 hour (1-hour bar) and so on) or 1 hour using Ninjascript. How can I do that? Please advise.

    #2
    You will need to Add your needed time frame in the Initialize of your strategy and then calculate the SMA value for your desired period on this frame using this BarsArray then as input for the IDataSeries input -

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      You will need to Add your needed time frame in the Initialize of your strategy and then calculate the SMA value for your desired period on this frame using this BarsArray then as input for the IDataSeries input -

      http://www.ninjatrader-support.com/H...BarSeries.html
      Thanks for you advice and information given.

      Actually I am not going to write a strategy, but instead write an indicator showing the absolute difference between two SMAs of different time frames. When I tried to compile the program, the following compile-time error is shown:

      No overload for Method "Add" takes "2" arguments.

      What happened? Below is a part of my code:

      protected override void Initialize()
      {
      Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
      Add(new Line(Color.FromKnownColor(KnownColor.DarkOliveGree n), 20, "Convergence"));
      Add(PeriodType.Minute, timeFrame1);
      Add(PeriodType.Minute, timeFrame2);
      CalculateOnBarClose = true;
      Overlay = false;
      PriceTypeSupported = false;
      }

      Comment


        #4
        DGMan, if you're using NT6.5, multi-instrument indicators are not possible. If you're using NT7, please try hardcoding the values for timeFrame1 and timeFrame2.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Austin View Post
          DGMan, if you're using NT6.5, multi-instrument indicators are not possible. If you're using NT7, please try hardcoding the values for timeFrame1 and timeFrame2.
          I am currently using NT6.5, and I am not going to upgrade it to NT 7 unless it is a non-beta release.

          Speaking back to my issue, I am not intending to develop a custom mult-INSTRUMENT indicator, but an indicator with the same underlying instrument (e.g. ES) but with different timeframes. Is it possible in NT6.5?

          Comment


            #6
            DGMan, unfortunately an indicator with the same instrument but different time frames is still classified as a multi-instrument indicator. As such, it is not possible in NT6.5.
            AustinNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by GussJ, 03-04-2020, 03:11 PM
            16 responses
            3,280 views
            0 likes
            Last Post Leafcutter  
            Started by WHICKED, Today, 12:45 PM
            2 responses
            19 views
            0 likes
            Last Post WHICKED
            by WHICKED
             
            Started by Tim-c, Today, 02:10 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by Taddypole, Today, 02:47 PM
            0 responses
            5 views
            0 likes
            Last Post Taddypole  
            Started by chbruno, 04-24-2024, 04:10 PM
            4 responses
            53 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Working...
            X