NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 09-30-2008, 10:24 AM   #1
twaydow
Junior Member
 
Join Date: Aug 2008
Posts: 3
Thanks: 0
Thanked 0 times in 0 posts
Default 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
twaydow is offline  
Reply With Quote
Old 09-30-2008, 10:34 AM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

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;
NinjaTrader_Josh is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
'Exit on Close' in Strategy Wizard Elliott Wave Strategy Development 1 05-07-2008 10:14 PM
ninja script strategy exit grav_rat Automated Trading 2 04-20-2008 04:19 PM
Entry / Exit Strategy Edgar V. Strategy Analyzer 19 03-17-2008 07:29 AM
Strategy Realised Profit and Loss on session exit richa61416 Strategy Development 2 10-09-2007 02:56 PM
Exit Strategy in Initialize() Oli Automated Trading 10 03-30-2007 03:06 AM


All times are GMT -6. The time now is 04:36 PM.