Login Page - Create Account

Support Board


Date/Time: Tue, 26 Nov 2024 06:56:04 +0000



[Programming Help] - REPORT CODING ISSUE -8998

View Count: 281

[2023-12-21 09:59:36]
User103688 - Posts: 9
Good Morning,
I'm trying to make my first Custom Study for automatic trading and I recive this error from Message Log:
-8998
;
Surfing in the web I found that in Sierra Chart, when encountered during order placement, typically indicates an issue with the order configuration or a problem with the connection to the trading service.
I'm with Stage5 for the connection with Denali Data Feed and I specify the symbol like
newOrder.Symbol = "ESH24_FUT_CME";
and nothing changes.
Can Someone help me, please?

The entire code is:

#include "sierrachart.h"
SCDLLName("MyTradingSystem")

SCSFExport scsf_SimpleEMiniLimitOrderBot(SCStudyInterfaceRef sc)
{
SCInputRef OrderPlacedFlag = sc.Input[0];

if (sc.SetDefaults)
{
// Set the configuration
sc.GraphName = "Simple E-Mini Limit Order Bot - 4 Ticks Below";
    sc.GraphRegion = 0; // Set the study to display in region 1
sc.StudyDescription = "Places a limit order for the E-mini S&P 500, 4 ticks below the current price.";
sc.AutoLoop = 0;

OrderPlacedFlag.Name = "Order Placed Flag";
OrderPlacedFlag.SetInt(0);

return;
}

if (OrderPlacedFlag.GetInt() == 1)
{
return; // Exit if order has already been placed
}

// Get the current market price
float currentPrice = sc.Close[sc.ArraySize - 1];

// Define the order
s_SCNewOrder newOrder;
  newOrder.OrderQuantity = 1;
  newOrder.OrderType = SCT_ORDERTYPE_MARKET;
  newOrder.TextTag = "Trading example tag";
  newOrder.Symbol = "ESH24_FUT_CME";
  newOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;

// Send the order
  int OrderID = 0;
  SCString logMessage;
  int result = sc.BuyEntry(newOrder, OrderID);

  if (result != 1) { // Assuming '1' indicates a successful order placement
logMessage.Format("Order placement failed with error code: %d", result);
sc.AddMessageToLog(logMessage, 1); // Logging in the Trade Service Log
  logMessage.Format("Attempting to place order. Price: %f, Quantity: %d, Symbol: %s", currentPrice, newOrder.OrderQuantity, newOrder.Symbol);
  sc.AddMessageToLog(logMessage, 1);
  } else {
    logMessage.Format("Order placed successfully. Order ID: %d", OrderID);
    sc.AddMessageToLog(logMessage, 0); // Logging in the Message Log
  }

// Set the flag indicating that the order has been placed
OrderPlacedFlag.SetInt(1);
}

[2023-12-21 13:38:36]
User431178 - Posts: 541
Order error -8998 means skipped due to full recalculation.

Before your order entry logic, insert the following line, this will mean that the order execution is not done until after the full calculation.

if (sc.UpdateStartIndex==0)
return;

Also, the element below is not quite right.

// Send the order
int OrderID = 0;
SCString logMessage;
int result = sc.BuyEntry(newOrder, OrderID);

The second parameter of sc.BuyEntry is not for the OrderID, you set it to the current bar index, in your case sc.ArraySize-1.
Automated Trading From an Advanced Custom Study: Buy Entry | Buy Order
Date Time Of Last Edit: 2023-12-21 13:39:03

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account