Login Page - Create Account

Support Board


Date/Time: Mon, 25 Nov 2024 16:51:31 +0000



[Programming Help] - Multiple limit orders to open

View Count: 450

[2024-02-14 19:38:24]
User509533 - Posts: 57
Hello,

I have three open limit orders for three different symbols (e.g., ES, NQ, YM). I want the limit orders for YM and NQ to be automatically cancelled as soon as the ES order is filled. How can I achieve this either through trading platform settings or by programming?

Thanks!
[2024-02-14 20:26:49]
User43 - Posts: 101
1) You create a study in ACSIL which on ES shows TRUE when there is a position on ES.
2) On YM and NQ you create an study in ACSIL which links to the open position (TRUE / FALSE (1 or 0) ) study on ES.
When the ES Position study changes from 1 to 0 this would then trigger a close of the limit orders on YM and NQ.

Just as a rough concept to get you started
[2024-02-14 21:56:39]
John - SC Support - Posts: 36249
There is not a way to do this using the built-in tools in Sierra Chart. You would have to create a custom study. Refer to the following:
Automated Trading From an Advanced Custom Study
For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2024-02-17 17:52:36]
User509533 - Posts: 57
I maintain open limit orders for ES, NQ, YM, and RTY. Whenever one of these orders is filled, I aim to cancel all remaining open orders for the other symbols.

The following study is applied to every trading chart. It tries to ensure that as soon as an order fills, all other orders on other chart's symbol are canceled.

Given that studies are executed at every bar, this frequency may be insufficient to promptly detect filled orders. Therefore, I'm considering whether
it would be more effective to subscribe to a filled position alert (if there is any) and activate this study across each trading chart book accordingly.

In any case, attached code is not even getting executed once (I have print statements that are not producing any output in the log). I would appreciate any help.

******************************


// The top of every source code file must include this line
#include "sierrachart.h"

SCDLLName("CloseOpenOrders DLL")

/* I maintain open limit orders for ES, NQ, YM, and RTY. Whenever one of these orders is filled, I aim to cancel all remaining open orders for the other symbols.

This strategy is applied to every trading chart. It ensures that as soon as an order fills, all other orders for that specific chart's symbol are canceled.

Given that studies are executed at every bar, this frequency may be insufficient to promptly detect filled orders. Therefore, I'm considering whether it would be more effective to subscribe to a filled position alert and activate this strategy across each trading chart book accordingly.
*/

SCSFExport scsf_CheckPositionAndCloseOrders(SCStudyInterfaceRef sc)
{


if (sc.SetDefaults)
{
// Set default settings
sc.GraphName = "Check Filled Position and Close Open Orders for Other Symbols";

sc.AutoLoop = 1; // NOT Manual looping

sc.FreeDLL = 1;
// This is false by default. Orders will go to the simulation system always.
sc.SendOrdersToTradeService = false;
return;
}


// Get the Trade Position data
s_SCPositionData PositionData;
sc.GetTradePosition(PositionData) ;

SCString PositionSymbol;
PositionSymbol = PositionData.Symbol;

std::cout << "pq is equal to " << PositionData.PositionQuantity;
std::cout << "psym is equal to " << PositionData.Symbol ;
std::cout << "psym is equal to " << PositionSymbol ;
std::cout << "csym is equal to " << sc.Symbol ;

if (PositionData.PositionQuantity == 0)
{
// No open position, no action required
return;
}



if (sc.Symbol != PositionSymbol)
{
// Close all orders for the other symbols
sc.CancelAllOrders;

}


}


attachmentCloseOpenOrders5.cpp - Attached On 2024-02-17 17:48:16 UTC - Size: 1.94 KB - 159 views
Attachment Deleted.
[2024-02-18 05:18:07]
User43 - Posts: 101
your check
if (sc.Symbol != PositionSymbol)
{
// Close all orders for the other symbols
sc.CancelAllOrders;
}

will only be triggered when a new symbol was selected for the current chart.

sc.CancelAllOrders will try to cancel the orders on the new symbol but not the prior one.
see Automated Trading From an Advanced Custom Study: sc.CancelAllOrders

As suggested before for the scenario you described in your first post, the way I'd approach this is having for ES a study which shows the number open position size.
NQ and RTY will have a study which reads the Position size from the ES Chart and when that goes to 0 the study will execute sc.CancelAllOrders closing all orders on NQ and RTY.
[2024-02-26 00:21:14]
User509533 - Posts: 57
Just to close the thread.. Frederik from SST has implemented it here, and you can get it free.

https://sst.frl/req

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

Login

Login Page - Create Account