I'm running a custom strategy on NT 6.5.1000.11 using Interactive Brokers (with live trading).
It's a simple EMA cross strategy, and this morning when the fast crossed below the slow EMA, it entered a short order, but then it was immediately cancelled.
Thus, I had to enter a sell order manually on the Orders tab (which worked fine), but I'm trying to figure out why this happened. I had no existing positions open at the time, and my strategy does not have any stop loss / profit target setup.
I should mention that on the orders tab, for the strategy order (the cancelled order), the order type is SellShort. By contrast, for my manual order, the order type is Sell (but the Side column does show it as a short trade on the Positions tab).
So, I'm wondering what I might have done wrong in my code? I followed the simple SMA cross example that you folks provide. Could someone take a quick look at my OnBarUpdate() and 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