PDA

View Full Version : Exit from position not intended


winja
02-18-2009, 09:58 PM
I have a simple strategy that takes a short position on SMA(3) cross below HMA(20) when Stochastics(20,90,3) is above 80. Here is my code:

protectedoverridevoid OnBarUpdate()
{
// Enter position
if (CrossBelow(SMA(Fast), HMA(Slow), 1) && CrossAbove(Stochastics(20,90,3), 80, 1))
EnterShort();
}

When I place this strategy on a 30 min SPY chart I get exited from the position even though I did not code any exit. See image. What do I need to do to prevent being exited from this position and why did it occur? Thanks.
http://www.ninjatrader-support2.com/vb/attachment.php?attachmentid=4677&stc=1&d=1235019344

NinjaTrader_Bertrand
02-19-2009, 04:24 AM
Hi winja, please set ExitOnClose to false in your Initialize() - http://www.ninjatrader-support.com/HelpGuideV6/ExitOnClose.html

This is used to exit all open strategy positions by the session end, to define how much in advance ExitOnCloseSeconds can be used - http://www.ninjatrader-support.com/HelpGuideV6/ExitOnCloseSeconds.html