PDA

View Full Version : Trailing Stop problem


Avn_0903
04-07-2010, 09:07 PM
I enter 2 positions for each direction when my strategy give me a signal: ShortTIa and ShortTIb, LongTIa and LongTIb. I then set a target for ShortTIa and LongTIa at 30 cents and a target for ShortTIb and LongTIb for 60 cents. I have different trailing stop for each order (4 in total). However, whenever I backtest this strategy, it only execute the LongTIa and ShortTIa orders. Here is my code:

Add(EMA(EMASlow));
Add(EMA(EMAFast));
Add(ADX(14));
Add(ADX(14));
Add(EMA(EMASlow));
Add(EMA(EMAFast));
Add(ADX(14));
Add(ADX(14));
SetTrailStop("LongTIa", CalculationMode.Ticks, TrailStopV, true);
SetTrailStop("LongTIb", CalculationMode.Ticks, TrailStopV, true);
SetProfitTarget("LongTIa", CalculationMode.Ticks, TargetV_a);
SetProfitTarget("ShortTIa", CalculationMode.Ticks, TargetV_a);
SetProfitTarget("LongTIb", CalculationMode.Ticks, TargetV_b);
SetProfitTarget("ShortTIb", CalculationMode.Ticks, TargetV_b);
SetTrailStop("ShortTIa", CalculationMode.Ticks, TrailStopV, false);
SetTrailStop("ShortTIb", CalculationMode.Ticks, TrailStopV, false);

CalculateOnBarClose = true;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(EMA(EMASlow), EMA(EMAFast), 1)
&& ADX(14)[0] > ADX(14)[1]
&& ADX(14)[0] > 20)
{
EnterLong(100, "LongTIa");
EnterLong(100, "LongTIb");
}

// Condition set 2
if (CrossBelow(EMA(EMASlow), EMA(EMAFast), 1)
&& ADX(14)[0] > ADX(14)[1]
&& ADX(14)[0] > 20)
{
EnterShort(100, "ShortTIa");
EnterShort(100, "ShortTIb");
}
}

#region Properties
[Description("EMA Fast")]
[Category("Parameters")]
public int EMAFast
{
get { return eMAFast; }
set { eMAFast = Math.Max(1, value); }
}

[Description("EMA Slow")]
[Category("Parameters")]
public int EMASlow
{
get { return eMASlow; }
set { eMASlow = Math.Max(1, value); }
}

[Description("AdxPedriod")]
[Category("Parameters")]
public int AdxPedriod
{
get { return adxPedriod; }
set { adxPedriod = Math.Max(1, value); }
}

[Description("TrailStopV")]
[Category("Parameters")]
public int TrailStopV
{
get { return trailStopV; }
set { trailStopV = Math.Max(1, value); }
}

[Description("StartingTime")]
[Category("Parameters")]
public int StartingTime
{
get { return startingTime; }
set { startingTime = Math.Max(1, value); }
}

[Description("TargetV_a")]
[Category("Parameters")]
public int TargetV_a
{
get { return targetV_a; }
set { targetV_a = Math.Max(1, value); }
}

[Description("TargetV_b")]
[Category("Parameters")]
public int TargetV_b
{
get { return targetV_b; }
set { targetV_b = Math.Max(1, value); }
}
#endregion
}
}


Can you guys tell my what is wrong and how to fix it?

Sleeping Troll
04-07-2010, 10:52 PM
Your EnterLong will cancel or close your short Order and visa-versa.

Avn_0903
04-07-2010, 11:10 PM
Found the problem:
I have to add this
EntriesPerDirection (http://www.ninjatrader-support.com/HelpGuideV6/MaxEntriesPerDirection.html) = 2;