Login Page - Create Account

Support Board


Date/Time: Sat, 27 Jul 2024 01:34:29 +0000



[Programming Help] - LIMIT ORDER BEHAVIOUR - STOP QUANTITY NOT UPDATING AS LIMIT TARGETS GET HIT

View Count: 400

[2024-04-01 13:50:29]
User312901 - Posts: 12
Hi!

I've been now trying to figure out this by going through settings and support board, without coming across with an solution.
So let's try with a new support request.

Ultimately I'm trying to set up an automated Spreadsheet strategy, using "Spreadsheet System for Trading".
A strategy where entry will be sent as market order, through "Entry"-columns. Open position will then be followed by placement of Stop-limit order for full quantity of the position and three limit orders for targets, each with one 3rd of the position size. Limit orders for targets and Stop-limit order will be executed through "Exit"-columns.

How do I get the quantity of the Stop-limit order to be updated as targets get hit one by one?
IE if the original position size is 9 and each target (limit orders) are size of 3, the stop should be reduced to 6 when first target hit and so on.
And surely all the remaining limit orders should be cancelled when ever the stop hits.

I don't want to pre-determine these orders through trade window settings as I need to be able to control the price levels for each order (Limit-stop and 3 separate limit targets) through Spreadsheet calculations. So I would be using order types "SL" and "L" at Spreadsheet, which I believe are equal to manually executing Buy/Sell Stop-limit and Buy/Sell Limit, respectively.

So how can I get these OCO or attached orders created using SL and L -orders without setting it up at the trade window Targets-tab?

Alternative approach would be if there is a way to control trade window settings through spreadsheet (stop and target distances, not just picking up pre-determined presets).

Much appreciated if some one can help me solve this, to be able continue with my project.
[2024-04-01 16:25:41]
John - SC Support - Posts: 33316
There is not a way to what you are wanting, as the Spreadsheet System for Trading is simply not setup to handle multiple Stops/Targets.

To do what you want, you would need to create a custom study. Refer to the following:
Automated Trading From an Advanced Custom Study

List of Third Party Sierra Chart Study and System Programmers
For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2024-04-01 16:58:00]
Sierra_Chart Engineering - Posts: 15584
You must use Attached Orders, to manage Target and Stop orders properly. We strongly recommend not doing this yourself.
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
Date Time Of Last Edit: 2024-04-01 16:58:12
[2024-04-01 17:09:08]
User61168 - Posts: 369
Lack of Dynamic order management capability via simple alerts is a big hurdle in SC. All my orders are market orders so introducing new capability via simple alerts to manipulate/set trade order qty would be AWESOME! Just two new functions please.... GetPositionQty() and SetOrderQty() to include in Buy/Sell Entry/Exit/Flatten Alert formula trading condition study would be extremely beneficial feature.

Could you please add this to your future enhancement bucket?
[2024-04-01 17:24:30]
John - SC Support - Posts: 33316
Exactly which study are you are referring to?

Your position quantity can be accessed by using the "Trading: Position Quantity" study.
For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2024-04-01 18:05:11]
Sawtooth - Posts: 4051
Alternative approach would be if there is a way to control trade window settings through spreadsheet (stop and target distances, not just picking up pre-determined presets).
One workaround would be to use the Trade Management by Study study.
Attached Orders: Study Controlled Targets and Stops

This study can move a Trade Window Attached Orders to a calculated price in a spreadsheet Formula Column.
The limitation is that it will only move the Nearest, so you'd need to initially place the farthest 2 of the 3 targets at a predetermined price.
As each target is reached the new nearest would be moved to its calculated price.
This might not work as expected in a fast market.

You can control the exit quantity, separate from the J26 quantity, in cells J82/J83, but you'd need complex formulas in J22-J25 for exit prices.
And you could replicate an OCO with a complex formula in J29.
Also, when using only L3/N3, or J29, for your exits, you don't have a stop loss in the market.
This is why it is highly recommended to use the Trade Window's Attached Orders.
[2024-04-01 18:08:43]
User61168 - Posts: 369
Glad you asked John. I am quite aware of all the available trading studies. I use "Trading system based on Alert Condition" for all my Buy/Sell/Flatten entries and exits. There is no way for me to programmatically read and/or change the amount of set quantity on the Trade window (Trade window is attached to chart). Every buy/sell entry/exit study is dependent on what is set in the trade window.
GetPositionQty() is not needed (my bad)... only SetOrderQty() is needed to programatically alter the position size of the order you want to scale in or out. Hope this clarifies further.
[2024-04-01 18:12:58]
User61168 - Posts: 369
To add further clarity, making a order Qty size a "variable/calculated number" based on signal condition or strength is not possible via simple alert condition study especially when ScaleIn/ScaleOut is enabled. Only Fixed order qty is supported with restricts the ability to increase/decrease position sizing based on signal strength or frequency.
[2024-04-01 19:51:23]
John - SC Support - Posts: 33316
You are correct, there is not a way to set the quantity through an Alert condition or any built-in method, apart from the Spreadsheet System for Trading, but that does not have the full capabilities for what you want to do.

For what you are wanting to do, you would need to create a custom study. You can always modify the "Trading System Based on Alert Condition" study, as it is in file named 'TradingSystemBasedOnAlertCondition.cpp" in the ACS_Source folder under your main Sierra Chart installation folder. Refer to the following:
How to Build an Advanced Custom Study from Source Code
For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2024-04-01 20:16:18]
User61168 - Posts: 369
Thanks John. I understand all roads lead to ASCIL. I am just advocating on behalf of your non-technical user base to enhance such basic capabilities that would propel the use of SC platform and exploit all the advanced delivered capabilities. Simple alerts are fantastic for quick strategy development and backtesting before hiring a paid ASCIL to go liveā€¦
[2024-04-02 04:47:49]
User312901 - Posts: 12
First of all thanks for the quick responses. Nice to get conversation going around this subject.

I kind of relate to Johns comment of highly recommending the attached orders for target/stop management.
That is exactly what I would like to do instead of trusting it to my spreadsheet logics.

But that would definitely require cells in "Spreadsheet System for Trading" to control offsets/prices of the targets/stops.
Surely depending on the strategy, but one wouldn't want to go in blind with stops/targets. So hard-pre-setting these is not an option.

So please consider adding that as a function.

Order quantity can already be controlled and I have calculations ready for different prices (stops and scale outs).

"All roads lead to ASCIL". Well said. I've kind of got that feeling also as going through the documentations and support board.
I do also understand that there needs to be a clear division for each functionality in a system to keep it organised without becoming a total mess.
But the the target/stop control would make the "Spreadsheet System for Trading" a lot more powerful feature without huge changes.
Also understand that when considering this, there also needs to be consideration over what functionalities from trade window should be controlled by "Spreadsheet System for Trading".


As for now I need to look into that Attached Orders: Study Controlled Targets and Stops.
Maybe if I can move first the nearest target to be the furthest with my price and then the old second nearest and so on.

Lets put it once more here: Please Sierra, consider adding trade window control to "Spreadsheet System for Trading".
That was one of the first things I noticed to be missing to achieve decent control over trade management.
[2024-04-02 13:10:20]
Sawtooth - Posts: 4051
consider adding trade window control to "Spreadsheet System for Trading".
You can control which Trade Window config is selected by using cell J112.
Spreadsheet Systems, Alerts and Automated Trading: Trade Window Configuration File (write-only) [J112]

The entire file name must be enclosed with parentheses, and you can conditionally choose them:
=IF(R3>0,"SimpleBracket.twconfig",IF(S3>0,"Seahawk.twconfig",0))
Date Time Of Last Edit: 2024-04-02 13:10:33
[2024-04-02 16:28:16]
User312901 - Posts: 12
Thanks Sawtooth,

It's just that I will have strict prices for targets. Prices that comes from my calculations and conditions.
So trying to cover it with a huge selection of configs is not eventually gonna cover it, as the prices of each 3 targets doesn't necessarily have any relation to each other. This would lead to endless selection of configs.

But thanks for reminding me of that setting. I'll definitely try it out as I build thinks up.
[2024-04-03 17:38:18]
User312901 - Posts: 12
As trying to figure out how to build automation over trade management, I also ended up wondering the following:

It seems to be so that through "Spreadsheet System for Trading" it is possible to control order quantity (J26) and launch attached orders (K3/M3), having targets and stop specified in trade window. Spreadsheet doesn't seem to change the actual quantity setting at trade window for some reason though.

In order to set up an automated risk management calculation in spreadsheet, that controls the order quantity for manually executed orders, I should somehow get the order entry launched through spreadsheet columns, instead of regular chart trading commands and keyboard shortcuts.
So is there a way to get cell value to chance in spreadsheet through keyboard shortcut? That way I could set up the manual execution to be carried through spreadsheet, with automatically calculated quantity.
Surely the best option for such operation would be if the spreadsheet would be capable of changing the quantity value at trade window.
[2024-04-04 02:18:05]
Sawtooth - Posts: 4051
Spreadsheet doesn't seem to change the actual quantity setting at trade window for some reason though.
Cell J26 overrides the Trade Window's Quantity setting, but it doesn't change it. J26 is in control, regardless.
So is there a way to get cell value to change in spreadsheet through keyboard shortcut?
The short answer is No.
That way I could set up the manual execution to be carried through spreadsheet, with automatically calculated quantity.
The Spreadsheet System for Trading study is primarily meant for automatic entry/exit. To use it for manual entries, you'd need to enter a 1 in K3/M3, and then a 0 to ready it for the next entry.
You can calculate the entry quantity with a formula in J26.
Surely the best option for such operation would be if the spreadsheet would be capable of changing the quantity value at trade window.
J26 is in control of the Quantity, so changing the Trade Window's quantity would be irrelevant.
[2024-04-04 08:49:20]
User312901 - Posts: 12
OK thanks Sawtooth,

So it is a dead end then.
Unless I figure out some workaround.
[2024-04-04 13:30:54]
Sawtooth - Posts: 4051
So it is a dead end then.
Unless I figure out some workaround.
You might consider using AutoHotKey, or an alternative.
https://www.autohotkey.com/

How to setup custom buttons for buy/sell limit order with rest to brackets | Post: 371995
Date Time Of Last Edit: 2024-04-04 16:00:12

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

Login

Login Page - Create Account