Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 James650, 05-07-2024, 08:25 AM
    3 responses
    14 views
    0 likes
    Last Post NinjaTrader_ChristopherJ  
    Started by xepher101, 05-10-2024, 12:19 PM
    5 responses
    67 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by Vitamite, Yesterday, 12:48 PM
    3 responses
    19 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by aligator, Today, 02:17 PM
    0 responses
    17 views
    0 likes
    Last Post aligator  
    Started by lorem, 04-25-2024, 09:18 AM
    22 responses
    96 views
    0 likes
    Last Post lorem
    by lorem
     
    Working...
    X