Support Board
Date/Time: Wed, 27 Nov 2024 10:34:22 +0000
Post From: ASCIL Different OrderIDs for Same Order
[2023-08-21 13:06:14] |
Gradient - Posts: 89 |
Looking at the code block below, you can see that it's not possible to create a long order or short order id without the following conditions being true 1)drawdown not met, 2) policy (i.e. a buy or sell signal) and 3) and response from sending the order that's greater than zero. In the screenshots provided I showed the timestamp, of which was within the same minute of the most recent sell order, in which a new ShortOrderId was being created and from the code block below as well as the fact that no new sell signals appeared on the chart, that this was not due to a logic error. It also wouldn't explain why those numbers are negative. If you see an error in the logic below that would cause several new order ids to be created despite the default constraints of only taking one position at a time, no trade reversals still being in place, max position allowed=1, please point them out. //only trade if drawdown not met if(drawdown_met ==0){ if (policy==1){ //create new order s_SCNewOrder LongParentOrder; LongParentOrder.OrderQuantity=1; LongParentOrder.OrderType=SCT_ORDERTYPE_LIMIT_TOUCH_CHASE; LongParentOrder.TimeInForce=SCT_TIF_IMMEDIATE_OR_CANCEL; LongParentOrder.Price1=sc.Open[sc.Index]; LongParentOrder.MaximumChaseAsPrice=1; //send order int response=static_cast<int>(sc.BuyEntry(LongParentOrder)); if(response >0){ //store order id LongOrderId=LongParentOrder.InternalOrderID; //plot arrow at low of entry bar Subgraph_BuyEntry[sc.Index]=sc.Low[sc.Index]; if(LongOrderId !=0){ //lookup working properly per alert debug below sc.SetAlert(1,"Long Order Lookup Alert"); //get the order by order id s_SCTradeOrder TradeOrder; sc.GetOrderByOrderID(LongOrderId, TradeOrder); //sc.AddMessageToLog("Current Bar Time %d, Long Bar Entry Time %d".SCString::Format(CurrentBarTime,LongBarEntryTime),0); //find order if (TradeOrder.InternalOrderID == LongOrderId) { ExecutionTime=TradeOrder.LastActivityTime; double FillPrice = TradeOrder.LastFillPrice; //DEBUG: alert executiontime sc.SetAlert(1,"Capturing Long Order Execution Time"); //Note, Execution time is as of time of the signal; order is transmitted at close of bar; thus actual actual execution time is t+1 SCString Message; SCString ExecutionTimeString; SCString TimeDelta; SCString MinuteDelta; Message.Format("Current Bar Date-Time: %s", sc.FormatDateTime(sc.BaseDateTimeIn[sc.Index]).GetChars()); ExecutionTimeString.Format("Current Execution Date-Time: %s", sc.FormatDateTime(ExecutionTime).GetChars()); TimeDelta.Format("Current Time Delta %s",sc.FormatDateTime((ExecutionTime.GetTimeAsSCDateTime()-sc.BaseDateTimeIn.TimeAt(sc.Index))).GetChars()); sc.AddMessageToLog(Message,1); sc.AddMessageToLog(ExecutionTimeString,1); sc.AddMessageToLog(TimeDelta,1); ExecutionMinute = ExecutionTime.GetMinute(); //SCString ExecutionMinuteString; ExecutionMinuteString.Format("Current Execution Minute %d",ExecutionMinute); sc.AddMessageToLog(ExecutionMinuteString,1); }//end of long order id lookup }//end of long order id }//end of positive response for long entry }//end of policy 1 if (policy == -1){ //execute short //create new order s_SCNewOrder ShortParentOrder; ShortParentOrder.OrderQuantity=1; ShortParentOrder.OrderType=SCT_ORDERTYPE_LIMIT_TOUCH_CHASE; ShortParentOrder.TimeInForce=SCT_TIF_IMMEDIATE_OR_CANCEL; ShortParentOrder.Price1=sc.Open[sc.Index]; ShortParentOrder.MaximumChaseAsPrice= 1; //send order int response=static_cast<int>(sc.SellEntry(ShortParentOrder)); if(response > 0){ //store order id ShortOrderId=ShortParentOrder.InternalOrderID; //plot arrow at high of entry bar Subgraph_SellEntry[sc.Index]=sc.High[sc.Index]; //if elapsed time met and order not filled cancel order if(ShortOrderId !=0){ //get the order by order id s_SCTradeOrder TradeOrder; sc.GetOrderByOrderID(ShortOrderId, TradeOrder); // Order has been found. if (TradeOrder.InternalOrderID == ShortOrderId) { sc.SetAlert(1,"Short order lookup alert"); ExecutionTime=TradeOrder.LastActivityTime;//.EntryDateTime; //DEBUG: alert executiontime sc.SetAlert(1,"Capturing Short Order Execution Time"); SCString Message; SCString ExecutionTimeString; SCString TimeDelta; SCString MinuteDelta; Message.Format("Current Bar Date-Time: %s", sc.FormatDateTime(sc.BaseDateTimeIn[sc.Index]).GetChars()); ExecutionTimeString.Format("Current Execution Date-Time: %s", sc.FormatDateTime(ExecutionTime).GetChars()); TimeDelta.Format("Current Time Delta %s",sc.FormatDateTime((ExecutionTime.GetTimeAsSCDateTime()-sc.BaseDateTimeIn.TimeAt(sc.Index))).GetChars()); sc.AddMessageToLog(Message,1); sc.AddMessageToLog(ExecutionTimeString,1); sc.AddMessageToLog(TimeDelta,1); ExecutionMinute = ExecutionTime.GetMinute(); ExecutionMinuteString.Format("Current Execution Minute %d",ExecutionMinute); sc.AddMessageToLog(ExecutionMinuteString,1); } //end of short order lookup } //end of short order id positive }//end of if short policy positive response }//end of short policy |