Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SMA EMA Cross

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

    SMA EMA Cross

    Hi,

    I want to add to my strategy something like

    if ema xy crosses sma xy during the last 30 days
    do something

    does anyone know how the correct syntax looks like ?

    regards ali

    #2
    Hello ali321,

    You can use CrossAbove() or CrossBelow() to define a crossing condition.

    An SMA crossing above and EMA within the last 30 bars looks like this:
    Code:
     
     
    if (CrossAbove(SMA(14), EMA(14), 30))
    If you don't care about the direction of the crossing, you could add || to look for crossing in both directions.

    Code:
    if (CrossAbove(SMA(14), EMA(14), 30) || CrossBelow(SMA(14), EMA(14), 30))
    Ryan M.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by kiffgj, Today, 04:23 AM
    0 responses
    9 views
    0 likes
    Last Post kiffgj
    by kiffgj
     
    Started by Lando Calrissian, Today, 07:30 AM
    1 response
    4 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by lismartin, Yesterday, 04:47 PM
    1 response
    15 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by facuevasm, Today, 07:28 AM
    2 responses
    9 views
    0 likes
    Last Post facuevasm  
    Started by ballston, Today, 06:32 AM
    0 responses
    8 views
    0 likes
    Last Post ballston  
    Working...
    X