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

Exit strategy question

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

    Exit strategy question

    Hi Ninjas,

    I need your assistance with an exit strategy. I am looking to exit a short position after the 2nd green bar closes above a moving average. If a bar a red bar closes below the moving average after the first green bar closes above it, I want it to start counting again.

    ie:

    scenario 1:
    green bar closes above MA - that's 1
    next bar is also green and closes above the MA -that's 2
    exit position

    scenario 2:
    green bar closes above MA - that's 1
    next bar is red and closes below the MA - reset count
    green bar closes above MA - that's 1
    next bar is red but closes above the MA - count is still at 1
    next bar is green and closes above the MA -that's 2
    exit position

    I know arrays and possibly the intseries class are involved but I am not sure how to apply them and reset the count. Any thoughts?

    Thanks,
    Casey

    #2
    To do this you do not necessarily need to use arrays or the IntSeries class. What you can do is just have a counter variable.

    Code:
    if (Close[0] > SMA(5)[0] && FirstTickOfBar)
         counter++;
    else if (Close[0] < SMA(5)[0] && FirstTickOfBar)
         counter = 0;
    Josh P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by bmarovets, Today, 06:33 PM
    0 responses
    1 view
    0 likes
    Last Post bmarovets  
    Started by ETFVoyageur, Yesterday, 07:05 PM
    4 responses
    33 views
    0 likes
    Last Post ETFVoyageur  
    Started by JGriff5646, Yesterday, 10:02 PM
    2 responses
    21 views
    0 likes
    Last Post JGriff5646  
    Started by DawnTreader, Today, 05:58 PM
    0 responses
    5 views
    0 likes
    Last Post DawnTreader  
    Started by ntram, Today, 05:39 PM
    0 responses
    5 views
    0 likes
    Last Post ntram
    by ntram
     
    Working...
    X