Login Page - Create Account

Support Board


Date/Time: Mon, 21 Apr 2025 17:18:43 +0000



Post From: Code error

[2025-02-13 10:07:48]
Tin43 - Posts: 141
I'm coding with Claude Sonnet 3.5

I don't know why I get this error in the Sierra Chart Log:

Sell Entry FAILED at index 49051 with result -1 *

By the way, i'm trying to set a trailing stop loss and there is no way it triggers.

// Trailing Stop Logic
if (PositionData.PositionQuantity != 0 && sc.Index > 0)
{
if (PositionData.PositionQuantity > 0) // Long position
{
float newStopPrice = sc.Low[sc.Index - 1]; // Previous bar's low

// Only move stop up
if (newStopPrice > r_TrailingStopPrice)
{
s_SCNewOrder UpdatedStop;
UpdatedStop.OrderQuantity = PositionData.PositionQuantity;
UpdatedStop.OrderType = SCT_ORDERTYPE_STOP;
UpdatedStop.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;

// Submit updated stop
sc.BuyOrder(UpdatedStop);
r_TrailingStopPrice = newStopPrice;

SCString message;
message.Format("Updated Long Stop to %.2f at index %d", newStopPrice, sc.Index);
sc.AddMessageToLog(message.GetChars(), 0);
}

// Check if stop is hit
if (sc.Low[sc.Index] <= r_TrailingStopPrice)
{
sc.FlattenPosition();
}
}