I am using Two EMA's (Fast EMA= 21, Slow EMA= 50) for crossover condition to place long and short order. My strategy is not using the trail stop code instead only reversing position per crossover condition or if met profit target. Below is my strategy code.
I also tried to follow the trailstop thread given on this form but not sure what I am doing wrong.
I appreciate if somebody can help me!!
privateint fast = 21; // Default setting for Fast
privateint slow = 50; // Default setting for Slow
privateint profitTargetTicks = 50;
#endregion
protectedoverridevoid Initialize()
{
CalculateOnBarClose = true;
}
protectedoverridevoid OnBarUpdate()
{
if (CrossAbove(EMA(Fast), EMA(Slow), 1))
{
SetTrailStop(CalculationMode.Price, EMA(50)[0]);
EnterLong(1, "Long1");
SetProfitTarget(CalculationMode.Ticks, profitTargetTicks);
}
if (CrossBelow(EMA(Fast), EMA(Slow), 1))
{
SetTrailStop(CalculationMode.Price, EMA(50)[0]);
EnterShort(1, "Short1");
SetProfitTarget(CalculationMode.Ticks, profitTargetTicks);
}

Comment