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

Applying Different Time Frame Moving Average

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

    Applying Different Time Frame Moving Average

    Hello,

    I would like to add a moving average to my 5-minute chart but base the calculation on a 15-minute time frame. I've been looking through the indicator settings but can't seem to find the option to adjust the time frame for the moving average independently of the chart's time frame.

    Could you guide me on how to apply a 15-minute moving average to a 5-minute chart? Your help would be greatly appreciated!

    Thank you!​

    #2
    Hello Hezi100,

    Thanks for your post.

    You could call the AddDataSeries() method in the script to add a 15-minute secondary data series to use for calculations.

    Then, you would pass in the BarsArray of the added series into the indicator when instantiating the indicator in State.DataLoaded.

    BarsArray[0] would be the BarsArray of the primary series. BarsArray[1] would be the BarsArray of the first added series, and so on.

    For example:

    //class-level variable
    private SMA mySMA;

    //State.Configure
    else if (State == State.Configure)
    {
    AddDataSeries(BarsPeriodType.Minute, 15);
    }

    //State.DataLoaded
    else if (State == State.DataLoaded)
    {
    mySMA = SMA(BarsArray[1], 14);
    }


    The SMA (mySMA) would then calculate from the added 15-minute series.

    You could then call AddPlot() in the script and assign mySMA[0] to the plot to plot the value on the chart.

    See the help guide documentation below for more information.

    AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm
    BarsArray: https://ninjatrader.com/support/help.../barsarray.htm
    Working with Multi-TimeFrame/Multi-Instrument NinjaScripts: https://ninjatrader.com/support/help...nstruments.htm
    AddPlot(): https://ninjatrader.com/support/help...t8/addplot.htm
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by LiamTwine, Today, 08:10 AM
    0 responses
    0 views
    0 likes
    Last Post LiamTwine  
    Started by Balage0922, Today, 07:38 AM
    0 responses
    5 views
    0 likes
    Last Post Balage0922  
    Started by JoMoon2024, Today, 06:56 AM
    0 responses
    6 views
    0 likes
    Last Post JoMoon2024  
    Started by Haiasi, 04-25-2024, 06:53 PM
    2 responses
    19 views
    0 likes
    Last Post Massinisa  
    Started by Creamers, Today, 05:32 AM
    0 responses
    6 views
    0 likes
    Last Post Creamers  
    Working...
    X