Login Page - Create Account

Support Board


Date/Time: Thu, 28 Nov 2024 22:35:27 +0000



[Programming Help] - Modifying a Stop Limit Opened Order

View Count: 483

[2023-04-04 14:07:23]
User687593 - Posts: 6
Hi there ...!

I'm working on a Order Modification app to change price of a Stop Limit Opened order, tick by tick, using a keyboard.

I managed to identify the order I want to modify, but no way I'm able to change the price.

Any help will be appreciated.

Thanks.



if( shiftPressed && sPressed ){

while(sc.GetOrderByIndex(i, order) != SCTRADING_ORDER_ERROR)
{
i++;

if (order.OrderStatusCode == SCT_OSC_OPEN && order.OrderTypeAsInt == SCT_ORDERTYPE_STOP_LIMIT)
{
s_SCNewOrder ModifyOrder;
ModifyOrder.InternalOrderID = order.InternalOrderID;
ModifyOrder.OrderType = SCT_OSC_OPEN;
float price = 4160.25;
ModifyOrder.Price1 = price;
sc.ModifyOrder(ModifyOrder);
break;

}
}

}


[2023-04-04 15:02:14]
Sierra_Chart Engineering - Posts: 17210
This is the correct way to change the price:


ModifyOrder.Price1 = price;

Check the Trade >> Trade Activity Log to see what might be happening.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2023-04-04 17:01:11]
User687593 - Posts: 6
Oh .. good point.

I've modified the code to print the Log, and I'm getting Price = 0

So, the question is now why the price of the order that I've identified and want to change, has the price 0 ?

Log attached.

Thanks for your support !



if( shiftPressed && sPressed ){

SCString Message;

while(sc.GetOrderByIndex(i, order) != SCTRADING_ORDER_ERROR)
{
i++;

if (order.OrderStatusCode == SCT_OSC_OPEN && order.OrderTypeAsInt == SCT_ORDERTYPE_STOP_LIMIT)
{
s_SCNewOrder ModifyOrder;

Message.Format("Order Price: %i",order.Price1);
sc.AddMessageToLog(Message, 1);

ModifyOrder.InternalOrderID = order.InternalOrderID;
ModifyOrder.OrderType = SCT_OSC_OPEN;
float price = 4160.25;
ModifyOrder.Price1 = price;

Message.Format("ModifyOrder Price: %i",ModifyOrder.Price1);
sc.AddMessageToLog(Message, 1);

sc.ModifyOrder(ModifyOrder);
break;

}
}

}

imageLog File.PNG / V - Attached On 2023-04-04 16:59:04 UTC - Size: 8.6 KB - 76 views
[2023-04-04 21:32:26]
User687593 - Posts: 6
Now, I've included the Internal Order ID, to confirm that I'm getting the Order I'm looking for.

I've attached the Log, showing the Order ID, but the price is cero before and after modifying it.

Thanks for your support.



if( shiftPressed && sPressed ){

SCString Message;

while(sc.GetOrderByIndex(i, order) != SCTRADING_ORDER_ERROR)
{
i++;

if (order.OrderStatusCode == SCT_OSC_OPEN && order.OrderTypeAsInt == SCT_ORDERTYPE_STOP_LIMIT)
{
s_SCNewOrder ModifyOrder;

Message.Format("Order ID: %i and Order Price: %i",order.InternalOrderID, order.Price1);
sc.AddMessageToLog(Message, 1);

ModifyOrder.InternalOrderID = order.InternalOrderID;
ModifyOrder.OrderType = SCT_OSC_OPEN;
float price = 4160.25;
ModifyOrder.Price1 = price;

Message.Format("ModifyOrder ID: %i and ModifyOrder Price: %i",ModifyOrder.InternalOrderID, ModifyOrder.Price1);
sc.AddMessageToLog(Message, 1);

sc.ModifyOrder(ModifyOrder);
break;

}
}

}


imageLog File 2.PNG / V - Attached On 2023-04-04 21:32:19 UTC - Size: 12.62 KB - 79 views
[2023-04-05 08:31:28]
User431178 - Posts: 544
but the price is cero before and after modifying it.

Message.Format("ModifyOrder ID: %i and ModifyOrder Price: %i",ModifyOrder.InternalOrderID, ModifyOrder.Price1);

%i is not correct for price, should be %f

ModifyOrder.OrderType = SCT_OSC_OPEN;
Maybe remove this line as SCT_OSC_OPEN is not an order type, nor do you have to set the order type when modifying the price level using sc.ModifyOrder
SCT_OSC_OPEN is type SCOrderStatusCodeEnum and implicitly converts to int with value 5, which actually makes it equivalent to SCT_ORDERTYPE_LIMIT_CHASE


Maybe do what is suggested previously by Sierra Chart Engineering and check the Trade >> Trade Activity Log to see what might be happening.

You could also add the code below to print a message to the log if the modify action fails
        
auto result = sc.ModifyOrder(ModifyOrder);

if (result < 0)
sc.AddMessageToLog(sc.GetTradingErrorTextMessage(result), 0, 1);

[2023-04-05 12:25:07]
User687593 - Posts: 6
That worked ...!

Thanks for your support, really appreciated.

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

Login

Login Page - Create Account