Login Page - Create Account

Support Board


Date/Time: Mon, 21 Apr 2025 13:11:42 +0000



[Programming Help] - Code error

View Count: 260

[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();
}
}

[2025-02-13 14:00:08]
cmet - Posts: 690
What does this mean?: "there is no way it triggers"

Is the order not being updated/moved? Is it not being placed at all? Is it not being executed?

Make sure you're updating the order and not trying to send a new one with (or cancel first, then send, if you are).
[2025-02-13 14:15:13]
Tin43 - Posts: 141
Sorry.

I wanted to say, the order is not being placed.

When system execute the trade, the entry order and the TP order placed but the stop loss isn't.

Apologies, English is not my mother tongue.
[2025-02-13 16:34:45]
cmet - Posts: 690
How are you entering the other two orders?

Looks like you're going long and entering a Sell stop with a Buy order? Also try adding stop price.

This might point you in the right direction:

// 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

// Place initial stop if it hasn’t been set yet
if (r_TrailingStopPrice == 0.0f)
{
r_TrailingStopPrice = newStopPrice; // Set initial stop
}

// 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;
UpdatedStop.Price1 = newStopPrice; // Set Stop Price

// Submit stop order
int Result = sc.SellOrder(UpdatedStop);

if (Result > 0)
{
r_TrailingStopPrice = newStopPrice; // Update stop price

SCString message;
message.Format("Updated Long Stop to %.2f at index %d", newStopPrice, sc.Index);
sc.AddMessageToLog(message.GetChars(), 0);
}
else
{
SCString errorMsg;
errorMsg.Format("Trailing Stop FAILED at index %d with result %d", sc.Index, Result);
sc.AddMessageToLog(errorMsg.GetChars(), 1);
}
}

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

Date Time Of Last Edit: 2025-02-13 18:01:56
[2025-02-13 20:52:31]
Tin43 - Posts: 141
THANK you so much for your time.

I'm tired. Extremely tired. It's been like more than 30 hours with this IA.

I don't consider myself unintelligent. I have always got above average marks. It's true that I don't know how to program/code, I didn't study for it and I'm doing what I can with this AI (claude sonnet). And it's true that it has helped me a lot, but in this trading thing, a 1% missing code or a 10% missing code means losing money.

I will try to fix this somehow and later I will contact a developer.

Does anyone have any idea what the going rate is. If it is per hour, lines of code etc?

My code has a base of 100 lines. When I add the trading logic it is about 200 lines long.

Is this considered a massive project? short?

I am just testing the waters. I don't want to get it cheap or free, but I don't have a lot of money to be honest.
[2025-02-14 01:27:24]
cmet - Posts: 690
What happened when you used the above code?
[2025-02-16 17:50:06]
ForgivingComputers.com - Posts: 1042
I will try to fix this somehow and later I will contact a developer.

I am a developer that can help you. I sent you a DM.

Brad H
[2025-03-02 21:08:05]
Tin43 - Posts: 141
What happened when you used the above code?

Sorry for being late. I didn't use the part of the code you gave me because the system was failing in too many things. I will keep that part of the code to implement it when my system works.

THANK YOU!

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

Login

Login Page - Create Account