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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    67 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    36 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    60 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    62 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    53 views
    0 likes
    Last Post CarlTrading  
    Working...
    X