PDA

View Full Version : Exit strategy question


twaydow
09-30-2008, 10:24 AM
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

NinjaTrader_Josh
09-30-2008, 10:34 AM
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.

if (Close[0] > SMA(5)[0] && FirstTickOfBar)
counter++;
else if (Close[0] < SMA(5)[0] && FirstTickOfBar)
counter = 0;