I have an indicator that returns the values "Neutral ","Long", and "Short". Depending on these values I have a strategy that creates and discards ATM strategies. The code is given below. The problem is that the system is very very slow, I have a screencast link to that as well. Please help solve this issue.
protected override void OnBarUpdate()
{
// Enters Long Position when the CDA AID is Long and when the existing position is Flat//
if (CDA("Neutral", true, Color.Bisque, "Alert2.wav", 1, 14,0 , 2,0 , 14, 3, 0.7, 0.25, Color.Honeydew, "Alert1.wav", 1000000, 1).aid1[0].ToString() == "Long"
&& Position.MarketPosition == MarketPosition.Flat)
{
s = CDA("Neutral", true, Color.Bisque, "Alert2.wav", 1, 14,0 , 2,0 , 14, 3, 0.7, 0.25, Color.Honeydew, "Alert1.wav", 1000000, 1).Support[0];
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, s +(entryTicksOffset*TickSize) ,0,
TimeInForce.Day,orderId, "MyTemplate",
atmStrategyId);
}
// Enters Short Position when the CDA AID is Short and when the existing position is Flat//
if (CDA("Neutral", true, Color.Bisque, "Alert2.wav", 1, 14,0 , 2,0 , 14, 3, 0.7, 0.25, Color.Honeydew, "Alert1.wav", 1000000, 1).aid1[0].ToString() == "Short"
&& Position.MarketPosition == MarketPosition.Flat)
{
r = CDA("Neutral", true, Color.Bisque, "Alert2.wav", 1, 14,0 , 2,0 , 14, 3, 0.7, 0.25, Color.Honeydew, "Alert1.wav", 1000000, 1).Resistance[0];
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, r -(entryTicksOffset*TickSize) ,0,
TimeInForce.Day, orderId, "MyTemplate",
atmStrategyId);
}
// Enters Long Position when the CDA AID is Long and when the existing position is Short//
if (CDA("Neutral", true, Color.Bisque, "Alert2.wav", 1, 14,0 , 2,0 , 14, 3, 0.7, 0.25, Color.Honeydew, "Alert1.wav", 1000000, 1).aid1[0].ToString() == "Long"
&& Position.MarketPosition == MarketPosition.Short)
{
s = CDA("Neutral", true, Color.Bisque, "Alert2.wav", 1, 14,0 , 2,0 , 14, 3, 0.7, 0.25, Color.Honeydew, "Alert1.wav", 1000000, 1).Support[0];
AtmStrategyClose(orderId);
AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, s +(entryTicksOffset*TickSize) ,0,
TimeInForce.Day, orderId, "MyTemplate",
atmStrategyId);
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
}
// Enters Short Position when the CDA AID is Short and when the existing position is Long//
if (CDA("Neutral", true, Color.Bisque, "Alert2.wav", 1, 14,0 , 2,0 , 14, 3, 0.7, 0.25, Color.Honeydew, "Alert1.wav", 1000000, 1).aid1[0].ToString() == "Short"
&& Position.MarketPosition == MarketPosition.Long)
{
r = CDA("Neutral", true, Color.Bisque, "Alert2.wav", 1, 14,0 , 2,0 , 14, 3, 0.7, 0.25, Color.Honeydew, "Alert1.wav", 1000000, 1).Resistance[0];
AtmStrategyClose(orderId);
AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, r -(entryTicksOffset*TickSize) ,0,
TimeInForce.Day, orderId, "MyTemplate",
atmStrategyId);
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
}
// Exits all positions//
if (CDA("Neutral", true, Color.Bisque, "Alert2.wav", 1, 14,0 , 2,0 , 14, 3, 0.7, 0.25, Color.Honeydew, "Alert1.wav", 1000000, 1).aid1[0].ToString() == "Neutral"
&& Position.MarketPosition != MarketPosition.Flat)
{
AtmStrategyClose(orderId);
}
}
Comment