Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Distance between SMA and EMA lines

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

    Distance between SMA and EMA lines

    How do I create a line on my chart that plots the changing difference between an SMA and EMA line (both the SMA and EMA will have the same time periods)?

    #2
    Hello Kal33,

    Thanks for your post.

    The AddPlot() method could be used to add a plot to your script.

    You could then assign the plot a value of the SMA minus the EMA to plot the difference between those two indicators on a chart. For example, the code might look something like this.

    Code:
    //OnStateChange() section
    if (State == State.SetDefaults)
    {​
        // Adds a blue line style plot
        AddPlot(Brushes.Blue, "MyPlot");​
    }
    
    //OnBarUpdate() section
    protected override void OnBarUpdate()
    {
        MyPlot[0] = SMA(20)[0] - EMA(20)[0]​;
    }​
    See the help guide documentation linked below for more information and sample code.

    AddPlot: https://ninjatrader.com/support/help...t8/addplot.htm
    SMA: https://ninjatrader.com/support/help...simple_sma.htm
    EMA: https://ninjatrader.com/support/help...onential_e.htm

    Let me know if I may assist further.
    <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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    63 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    87 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    47 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    104 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    63 views
    0 likes
    Last Post PaulMohn  
    Working...
    X