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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    47 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    22 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    15 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    21 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    23 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X