Support Board
Date/Time: Sat, 23 Nov 2024 15:21:10 +0000
Post From: Trade Result -8998
[2024-08-20 17:58:06] |
PS - Posts: 40 |
Hello, I have a strategy I am back testing that keeps on getting TRade result error -8998. I saw on some other posts that this means it is trying to send an order during "full recalculation" but I am unclear on exactly what that means or how to resolve it. Below is the section of my code that contains order entry logic. This error is occurring when I run a replay backtest on Standard Replay mode. It is the only strategy / indicator on the chart. I've used arrow drawings to indicate where a buy / sell signal "should" take place, and those arrows are all being placed correctly on the chart. It is simply a matter of getting the actual orders to be sent. I'm not entirely sure if this is deemed as programming help since the only issue here is resolving an order error command. Thank you in advance for your assistance. // Trading logic
bool enable_trading = true; // Enable trading int trade_quantity = 1; // Trade 1 contract if (enable_trading) { s_SCPositionData PositionData; sc.GetTradePosition(PositionData); double current_position = PositionData.PositionQuantity; // Check for short trades for (auto& zone : active_resistance_zones) { if (!zone.traded && high >= zone.start_price && high <= zone.end_price && sc.Close[sc.Index - 1] < zone.start_price) { SCString logMessage; logMessage.Format("Sell conditions met: Start Price: %f, End Price: %f, Close Price: %f, Time: %s", zone.start_price, zone.end_price, close, sc.FormatDateTime(sc.BaseDateTimeIn[sc.Index]).GetChars()); sc.AddMessageToLog(logMessage, 0); float stop_price = zone.end_price + 3.0f; if (sc.UpdateStartIndex==0) return; s_SCNewOrder NewOrder; NewOrder.OrderQuantity = trade_quantity; NewOrder.OrderType = SCT_ORDERTYPE_MARKET; NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED; NewOrder.AttachedOrderStop1Type = SCT_ORDERTYPE_STOP; // Specify the type of the attached stop order NewOrder.Stop1Offset = std::abs(stop_price - close); // Set the stop offset int Result = sc.SellEntry(NewOrder); SCString traderesult; traderesult.Format("Trade result = %i", Result); sc.AddMessageToLog(traderesult, 0); // Mark the zone as traded zone.traded = true; // Draw a red arrow for sell entry s_UseTool SellArrow; SellArrow.Clear(); SellArrow.ChartNumber = sc.ChartNumber; SellArrow.DrawingType = DRAWING_MARKER; SellArrow.MarkerType = MARKER_ARROWDOWN; SellArrow.MarkerSize = 8; SellArrow.Color = RGB(255, 0, 0); // Red color SellArrow.BeginIndex = sc.Index; SellArrow.BeginValue = close; sc.UseTool(SellArrow); } } // Check for long trades for (auto& zone : active_support_zones) { if (!zone.traded && low >= zone.end_price && low <= zone.start_price && sc.Close[sc.Index - 1] > zone.start_price) { SCString logMessage; logMessage.Format("Buy conditions met: Start Price: %f, End Price: %f, Close Price: %f, Time: %s", zone.start_price, zone.end_price, close, sc.FormatDateTime(sc.BaseDateTimeIn[sc.Index]).GetChars()); sc.AddMessageToLog(logMessage, 0); float stop_price = zone.end_price - 3.0f; if (sc.UpdateStartIndex==0) return; s_SCNewOrder NewOrder; NewOrder.OrderQuantity = trade_quantity; NewOrder.OrderType = SCT_ORDERTYPE_MARKET; NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED; NewOrder.AttachedOrderStop1Type = SCT_ORDERTYPE_STOP; // Specify the type of the attached stop order NewOrder.Stop1Offset = std::abs(1 * (stop_price - close)); // Set the stop offset int Result = sc.BuyEntry(NewOrder); SCString traderesult; traderesult.Format("Trade result = %i", Result); sc.AddMessageToLog(traderesult, 0); // Mark the zone as traded zone.traded = true; // Draw a green arrow for buy entry s_UseTool BuyArrow; BuyArrow.Clear(); BuyArrow.ChartNumber = sc.ChartNumber; BuyArrow.DrawingType = DRAWING_MARKER; BuyArrow.MarkerType = MARKER_ARROWUP; BuyArrow.MarkerSize = 8; BuyArrow.Color = RGB(0, 255, 0); // Green color BuyArrow.BeginIndex = sc.Index; BuyArrow.BeginValue = close; sc.UseTool(BuyArrow); } } // Trailing stop logic if (current_position < 0) // Short position { for (auto& zone : active_support_zones) { if (sc.Close[sc.Index] > zone.start_price) // If a support zone forms and we are in a short position, exit { int Result = sc.FlattenAndCancelAllOrders(); SCString traderesult; traderesult.Format("Exiting short position due to support zone formation, Result = %i", Result); sc.AddMessageToLog(traderesult, 0); break; } } } else if (current_position > 0) // Long position { for (auto& zone : active_resistance_zones) { if (sc.Close[sc.Index] < zone.end_price) // If a resistance zone forms and we are in a long position, exit { int Result = sc.FlattenAndCancelAllOrders(); SCString traderesult; traderesult.Format("Exiting long position due to resistance zone formation, Result = %i", Result); sc.AddMessageToLog(traderesult, 0); break; } } } } |