NinjaTrader Support Forum  

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 06-06-2010, 01:55 PM   #1
traderT
Member
 
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
Default Exit on same bar

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.

protected
overridevoid 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
Attached Images
File Type: png EMA Strat.png (13.6 KB, 9 views)
traderT is offline  
Reply With Quote
Old 06-06-2010, 02:13 PM   #2
Rienb
Member
 
Join Date: Feb 2010
Posts: 84
Thanks: 0
Thanked 0 times in 0 posts
Default

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
Rienb is offline  
Reply With Quote
Old 06-06-2010, 02:27 PM   #3
traderT
Member
 
Join Date: Nov 2008
Location: London
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
Default Exit on same bar as entry

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.
traderT is offline  
Reply With Quote
Old 06-06-2010, 08:07 PM   #4
NinjaTrader_Tim
NinjaTrader Customer Service
 
NinjaTrader_Tim's Avatar
 
Join Date: Nov 2009
Location: Denver, CO
Posts: 1,424
Thanks: 0
Thanked 3 times in 3 posts
Default

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
NinjaTrader_Tim 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
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


All times are GMT -6. The time now is 07:39 PM.