Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ratio Moving Average

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

    Ratio Moving Average

    I am new to NT Strategy development. In my strategy, how can I create a Simple Moving Average for the ratio of 2 instrument daily close prices?

    For example if I have 2 Bond ETF's:
    -HYLD
    -SHY

    In my strategy, I need to create a 20 day Simple Moving Average of the ratio of the daily close prices:
    SMA(HYLD Close Price / SHY Close Price)

    Do I need to manually create a new DataSeries with the price ratio and pass that to SMA in the OnBarUpdate event? I would also like to plot this SMA.

    Any sample code would be greatly appreciated.

    #2
    Hello fperugini,

    Thank you for your post and welcome to the forums!

    You can use the Closes[][] to select which data series to grab and which bar to use. You will also want to create a new data series to store this value
    I have attached an indicator that will show an example of this. I also included a BarsInProgress check as to not get double values from the multiple data series.

    Let me know if I can be of further assistance
    Attached Files
    Cal H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    60 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    146 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    161 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    97 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    284 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X