Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Subtract and plot difference between two symbols

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

    Subtract and plot difference between two symbols

    Hi there

    I would like to Subtract and plot the differens between two symbols?

    I allso would like to plot the ratio between to symbols?

    All help welcome
    cheers

    #2
    Hello Granit,

    Thanks for your post.

    AddPlot() would be used to add plots to your script. AddDataSeries() could be used to add additional secondary data series to your script.

    You could create two double variables named something like close1 and close2 that will hold the Close value of each data series. Then you could create a Series<double> variable named something like diff and assign close1-close2 to that Series<double> variable and assign the diff variable to a plot.

    For example, you could use close1 = Closes[0][0] to assign the Close price of the primary series to your first variable. close2 = Closes[1][0] would be used to assign the Close price of the added series to the close2 variable. You would subtract those variables and assign the value to diff, such as diff[0] = close1 - close2. Then assign the diff value to the plot, such as Values[0][0] = diff[0].

    See the attached example script demonstrating this.

    Something similar would be done to plot the ratio between two instruments. You would need to calculate the ratio between both instruments and assign that value to a plot.

    See the help guide documentation below for more information.

    AddPlot(): https://ninjatrader.com/support/help...t8/addplot.htm
    AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm
    BarsInProgress: https://ninjatrader.com/support/help...inprogress.htm
    Series<T>: https://ninjatrader.com/support/help...t8/seriest.htm
    Closes: https://ninjatrader.com/support/help...nt8/closes.htm
    Working with Multi-Instrument/Muti-Timeframe scripts: https://ninjatrader.com/support/help...nstruments.htm

    Let us know if we may assist further.
    Attached Files
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    578 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    334 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    554 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    551 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X