![]() |
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
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Aug 2008
Posts: 3
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |