![]() |
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 |
|
Member
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
I have written a simple strategy the buys or sells on a pullback to the EMA, providing price has not reached the EMA within the last 15 bars, using EnterLongLimit or EnterShortLimit and am using a 15 minute chart. The problem that I am having is that if the entry bar is large enough then the strategy exits on the same bar even though price movement does not warrant an exit.
protectedoverridevoid Initialize() { SetProfitTarget("", CalculationMode.Ticks, target); SetStopLoss("", CalculationMode.Ticks, stopLoss, false); CalculateOnBarClose = false; } protectedoverridevoid OnBarUpdate() { EMAValue = (EMA(MAPeriod)[0]); Condition1 = (ToTime(Time[0]) >= 0400 && ToTime(Time[0]) <= 1200); if(High[0] > EMA(MAPeriod)[0]) shortCount = 0; if (High[0] < EMA(MAPeriod)[0])shortCount++; if((shortCount >= other)) { EnterShortLimit(EMA(MAPeriod)[0], "EMAShort"); } } protectedoverridevoid OnOrderUpdate(IOrder order) { if (order.OrderState == OrderState.Filled) { longCount = 0; shortCount = 0; } } Left chart incorrect, right chart correct |
|
|
|
|
|
#2 |
|
Member
Join Date: Feb 2010
Posts: 84
Thanks: 0
Thanked 0 times in 0 posts
|
Somehow the condition that the entry indicator gives changes to a non trading position, thats why it is closing the position try to change that it cant pull out the position
|
|
|
|
|
|
#3 |
|
Member
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
Thanks for the quick reply, however I do not think that this is the case. I have a stop of 20 pips and a target of 20 pips. The problem only occurs if the bar is greater than 20 pips, then it will exit on the same bar as the entry. As you can see from the 2 charts, the right hand chart's entry bar is less than 20 pips, so it has to follow through the trade as normal, whereas the left hand chart's entry bar is greater than 20 pips, so it thinks that the target has been hit on this bar and exits (this is possible, but only if the market comes down to the entry and then reverses more than 20 pips on the same bar, however this is not always the case). In the left hand chart, if you go to a smaller timeframe, at no point after entry does the market reverse 20 pips within the 15 minute timeframe.
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Nov 2009
Location: Denver, CO
Posts: 1,424
Thanks: 0
Thanked 3 times in 3 posts
|
HI traderT,
One option would be to use a BarsSinceEntry() condition. More info at - http://www.ninjatrader-support.com/H...BarsSinceEntry You may also consider adding another series to your strategy for the purpose of exiting on time interval More info at - http://www.ninjatrader.com/support/f...ead.php?t=5787
Tim
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Entry on the Current Bar | brooksrimes | Strategy Development | 5 | 06-02-2010 10:09 AM |
| How can I access to data of last bar? | 10percent | General Programming | 2 | 06-01-2010 02:30 PM |
| My bar chart | saeed | Charting | 1 | 05-31-2010 04:48 AM |
| Today's 9:00 bar | Stem1 | General Programming | 1 | 05-31-2010 03:58 AM |
| Backtest using daily bars (same bar signal) | tradinghumble | Strategy Development | 3 | 05-28-2010 11:30 AM |