Announcement

Collapse
No announcement yet.

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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    62 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    33 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    44 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    58 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    47 views
    0 likes
    Last Post CarlTrading  
    Working...
    X