PDA

View Full Version : double exit strategy


duck_CA
02-19-2009, 08:52 PM
the following is "OnBarUpdate() which compliles but not giving the result intended.

the goal is to have an exit either 10 ticks profit,10 ticks stop, or when price touches the SMA (10)

if (Position.MarketPosition == MarketPosition.Long)
ExitLongLimit(SMA(10)[0]);

if (Position.MarketPosition == MarketPosition.Long)
SetStopLoss("", CalculationMode.Ticks, 10, true);

if (Position.MarketPosition == MarketPosition.Long);
SetProfitTarget("", CalculationMode.Ticks, 10);

NinjaTrader_Josh
02-20-2009, 07:26 AM
The Set() methods need to be placed before you acquire a long position for them to take affect on the long position.

You should call the Set() methods right before you call EnterLong().

duck_CA
02-20-2009, 09:28 AM
is this considered a set method?
if (Position.MarketPosition == MarketPosition.Long)
ExitLongLimit(SMA(10)[0]);

NinjaTrader_Josh
02-20-2009, 09:30 AM
Set() methods are SetStopLoss(), SetTrailStop(), and SetProfitTarget().

duck_CA
02-20-2009, 01:53 PM
protectedoverridevoid Initialize()
{
CalculateOnBarClose = true;///does this need to be "false"?
}
protectedoverridevoid OnBarUpdate()
{
if
(
(High[0]>High[1])
{
SetStopLoss("", CalculationMode.Ticks, 10, true);
SetProfitTarget("", CalculationMode.Ticks, 10);
EnterLong(DefaultQuantity, "");
}


}


does this go into the "intialize()?
ExitLongLimit(SMA(10)[0]);

NinjaTrader_Josh
02-20-2009, 01:57 PM
No. No logic should ever be placed in Initialize().

duck_CA
02-20-2009, 02:09 PM
protectedoverridevoid Initialize()
{
CalculateOnBarClose = true;///does this need to be "false"?
}
protectedoverridevoid OnBarUpdate()
{
if
(
(High[0]>High[1])
)
{
SetStopLoss("", CalculationMode.Ticks, 10, true);
SetProfitTarget("", CalculationMode.Ticks, 10);
EnterLong(DefaultQuantity, "");
}
if
(
(High[0]>SMA(18)[0])
)
{
ExitLong();
}
}

NinjaTrader_Josh
02-20-2009, 02:11 PM
That should work.