Announcement

Collapse
No announcement yet.

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 -

    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 Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            597 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            343 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            556 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            555 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X