thanks for your time in advance
note: this strategy is set to calculate on bar close to false - could that be causing this? the executions could be happening before the atmstrategyid & orderid are assigned a value.
i do have a template named TEST STRATEGY
attached code is that one that i am trying to debug
if(Close[0]>Open[0]
&& orderId.Length == 0 && atmStrategyId.Length == 0)
{
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, Close[0], 0, TimeInForce.Gtc, orderId, "TEST STRATEGY",atmStrategyId);
}
if(Close[0]<Open[0]
&& orderId.Length == 0 && atmStrategyId.Length == 0 )
{
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(OrderAction.Sell, OrderType.Limit, Close[0], 0, TimeInForce.Gtc, orderId, "TEST STRATEGY",atmStrategyId);
}
//ENDING ENTRY CONDITIONS
[SIZE=3]
// Check for a pending entry order
if (orderId.Length > 0)
{
string[] status = GetAtmStrategyEntryOrderStatus(orderId);
//only change order once an order is submitted and reset it when done
AtmStrategyChangeEntryOrder(Close[0], 0, orderId);
// If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
if (status.GetLength(0) > 0)
{
if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
orderId = string.Empty;
}
}
// If the strategy has terminated reset the strategy id
//Don't change the else if - its needed!
else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat
&& orderId.Length == 0)
/*//before you empty the atmstrategyid, make sure the previous order is filled [empty order id from above] (gauranteed to fill eventually b/c of change entry order. Else, you will get multiple positions*/
{
atmStrategyId = string.Empty;
}
//____________________________________________Trade Management
if (atmStrategyId.Length > 0)
{
// You can change the stop price
if (GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Long)
{
AtmStrategyChangeStopTarget(0, GetAtmStrategyPositionAveragePrice(atmStrategyId) - ATR(100)[0]*0.333, "STOP1", atmStrategyId);
AtmStrategyChangeStopTarget(GetAtmStrategyPositionAveragePrice(atmStrategyId) + ATR(100)[0]*1, 0, "TARGET1", atmStrategyId);
}
if (GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Short)
{
AtmStrategyChangeStopTarget(0, GetAtmStrategyPositionAveragePrice(atmStrategyId) + ATR(100)[0]*0.333, "STOP1", atmStrategyId);
AtmStrategyChangeStopTarget(GetAtmStrategyPositionAveragePrice(atmStrategyId) - ATR(100)[0]*1, 0, "TARGET1", atmStrategyId);
}
}[/SIZE]

Comment