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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    628 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    359 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    562 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    568 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X