I have developed a simple EMA cross strategy. When a cross occurs, it should buy at the beginning of the next period. What I am finding in backtesting is that it buys 15 minutes too late almost consistently.
Can someone tell me what I might be doing wrong? Thank you.
public class SimpleEMA : Strategy
{
private int fast = 1; // Default setting for Fast
private int slow = 1; // Default setting for Slow
private int shares = 100; // Default setting for Shares
protected override void Initialize()
{
EMA(Fast).Plots[0].Pen.Color = Color.Orange;
EMA(Slow).Plots[0].Pen.Color = Color.Green;
Add(EMA(Fast));
Add(EMA(Slow));
CalculateOnBarClose = true;
}
protected override void OnBarUpdate()
{
if (CrossAbove(EMA(Fast), EMA(Slow), 1))
{
ExitShort();
EnterLong(this.Shares, "");
}
else if (CrossBelow(EMA(Fast), EMA(Slow), 1))
{
ExitLong();
EnterShort(this.Shares, "");
}
}
public int Fast
{
get { return fast; }
set { fast = Math.Max(1, value); }
}
public int Slow
{
get { return slow; }
set { slow = Math.Max(1, value); }
}
public int Shares
{
get { return shares; }
set { shares = Math.Max(100, value); }
}
}
}

Comment