Login Page - Create Account

Support Board


Date/Time: Tue, 06 May 2025 22:36:29 +0000



[Programming Help] - Programming help with setting the Trade Window Order Quantity in ASCIL

View Count: 404

[2024-12-01 03:17:45]
User61168 - Posts: 442
I just learnt about sc.TradeWindowOrderQuantity here >>> Position Sizing | Post: 159825

The most basic functionality for this would be to set the Trade Window Order Quantity and ACSIL does support that:
ACSIL - Variables and Arrays: sc.TradeWindowOrderQuantity

Could someone please create a custom ASCIL study which sets the trade window order quantity using a custom spreadsheet formula study? I already have money mgmt logic built using spreadsheet formula studies. I would appreciate it.
[2024-12-01 11:15:47]
User431178 - Posts: 663
Attached.
Zip file has source and compiled study.

Study sets sc.TradeWindowOrderQuantity based on formula result.
Calculated position size is output to subgraph.
Min/Max position size constraints (set in the study) are output to subgraph.

Example chart used for testing attached, see also image.
attachmentSpreadsheetFormulaPositionSize.Cht - Attached On 2024-12-01 11:10:13 UTC - Size: 4.09 KB - 169 views
imageSpreadsheetFormulaPositionSize.png / V - Attached On 2024-12-01 11:10:19 UTC - Size: 59.81 KB - 50 views
attachmentSpreadsheetFormulaPositionSize.zip - Attached On 2024-12-01 11:10:31 UTC - Size: 56.48 KB - 69 views
[2024-12-01 21:25:31]
User61168 - Posts: 442
Wow! Thanks User431178 for your generosity in sharing. I really appreciate it.
[2024-12-01 21:33:04]
User61168 - Posts: 442
I just tried to do remote build the source coed and it throws an error.

The build failed.
In function 'void scsf_SpreadsheetFormulaModified(SCStudyInterfaceRef)':
error: unable to find numeric literal operator 'operator""i64'
97 | auto formulaResult{ 0i64 };
| ^~~~
-- End of Build -- 16:26:17
[2024-12-01 22:04:58]
User431178 - Posts: 663
You can delete the "i64" part from the initialisation of formulaResult.
[2024-12-01 23:53:35]
User61168 - Posts: 442
Thanks. I tried

auto formulaResult {}; and it would error so tried

int formulaResult; which compiled fine and the study works great.

I just have to copy/paste the position sizing formula from my other spreadsheet formula study into your study... it works like magic.

if it is not too much hassle, could I request adding a "Update on bar open" (i.e. same as calculate once per bar at open) input criteria to spare load on CPU with updating on every tick.
[2024-12-02 09:52:34]
User431178 - Posts: 663

auto formulaResult {}; and it would error so tried

Yes, type deduction can't work if there is no type to deduce from.
Drop the i64 suffix, but keep the 0 (or replace i64 with ll).
Or do as you did and don't use type deduction.


auto formulaResult {0};


Updated code attached, you can now choose "always", "on close" or "on open".
Date Time Of Last Edit: 2024-12-02 09:52:58
attachmentSpreadsheetFormulaPositionSize.cpp - Attached On 2024-12-02 09:51:55 UTC - Size: 3.87 KB - 146 views
[2024-12-04 09:10:00]
User61168 - Posts: 442
Fantastic User431178. You have been such a great help. The revised code compiles without any issues and works great! I wish every study in SC came with a enable/disable and update mode of always/onOpen/onClose option.

I don't want to abuse your generosity so feel free to decline this request. I have accomplished almost everything I need via simple alerts except for these two:
1) ways to programmatically auto-connect and auto-disconnect the data feed (either at the individual chart level or chart book level or for entire platform) based on a value in spreadsheet formula study. Could this be done in ASCIL?
2) is there a way in ASCIL to programmatically "Force" a chart's graph draw type to be always Blank (or any option in the dropdown list under Chart Settings>Bar Period>Graph Draw Type). When running my autotrading algo, I prefer to forcefully hide all the bars and free my mind from over-thinking and let the algo run without my interference. Hope there is a way to do this.

Thanks again for your help.
[2024-12-04 10:37:05]
User431178 - Posts: 663
1) Only for the entire platform, as far as I am aware.
2) Yes it is possible.

See attached for solutions.

Either Connect or Disconnect based on formula result, the action is performed when formula result is non-zero.
You would need two copies of the study, one for each action.
I did not see a way to expose the live system date/time to spreadsheet/alert formula so made a study for this purpose.
attachmentSpreadsheetFormulaPositionSize.cpp - Attached On 2024-12-04 10:37:00 UTC - Size: 7.54 KB - 129 views
[2024-12-07 10:07:46]
User61168 - Posts: 442
You rock dude. Thanks again for your assistance.

Only for the entire platform, as far as I am aware.
I will test this out over the weekend. Is it possible to conditionally connect/disconnect at the sub-instance level? If not, then I am hoping there is a way in ASCIL to conditionally disable the entire study collection. use case: once the daily max profit or loss is reached, I want to completely reduce load on CPU caused by the chart. The CPU keeps running hot until session close as I have over 25+ spreadsheet formula studies in the collection doing the number crunching on every tick. I only use simple alerts and formulas in my collection on daily NY session candle with No fancy indicators or DOM or advanced features involved.


Alternatively, if there is a way in ASCIL to conditionally "pause" the entire study collection OR run the collection at every x milliseconds (x calculated via spreadsheet formula), it would be a better option allowing me to programmatically pause the algo during news time.

Edit: I would be happy to compensate you for your time or donate to your charity of choice. As I further look into all the features I need from ASCIL, I also need the ability to automatically include the name of my study collection as a tag note for every trade. All my entries and exits are market orders without attached SL or TP orders. is this possible?
Date Time Of Last Edit: 2024-12-08 01:35:54
[2024-12-08 01:37:52]
User61168 - Posts: 442
I just tested your latest cpp and everything works great. The enforcement of blank graph is awesome!
[2024-12-08 12:44:25]
User431178 - Posts: 663

Is it possible to conditionally connect/disconnect at the sub-instance level?

Yes, disconnecting the sub-instance would work.


If not, then I am hoping there is a way in ASCIL to conditionally disable the entire study collection

Not exactly, a study collection can be applied via ACSIL though.
As an example you could possibly switch between a specified collection and blank collection.


Alternatively, if there is a way in ASCIL to conditionally "pause" the entire study collection OR run the collection at every x milliseconds (x calculated via spreadsheet formula), it would be a better option allowing me to programmatically pause the algo during news time.

No way of pausing a collection.
Only thing I can think here is changing the chart update interval via ACSIL, how suitable a solution that would be remains to be seen.

I also need the ability to automatically include the name of my study collection as a tag note for every trade. All my entries and exits are market orders without attached SL or TP orders. is this possible?
Not that I am aware of.
You can set text tag in the trade window and save as twconfig, e.g. one config per study collection, but unless you are trading only one collection per chart I am not sure how helpful that is.
If the trading was managed in ACSIL then there would be some options available, though still not exactly what you ask.
[2024-12-08 21:35:12]
ForgivingComputers.com - Posts: 1055
No way of pausing a collection.
Only thing I can think here is changing the chart update interval via ACSIL, how suitable a solution that would be remains to be seen.

You can create a timer in your study by checking the time every pass and returning if x ms hasn't passed.
[2024-12-08 21:55:09]
User431178 - Posts: 663

You can create a timer in your study by checking the time every pass and returning if x ms hasn't passed.

Assuming all of the studies in the collection are custom.
[2024-12-08 22:16:34]
ForgivingComputers.com - Posts: 1055
Assuming all of the studies in the collection are custom.

I meant by switching study collections with a timer. I haven't tried it.
[2024-12-09 00:20:21]
User61168 - Posts: 442
I meant by switching study collections with a timer. I haven't tried it.
not sure if this is really what I need.

Yes, disconnecting the sub-instance would work.
Disconnecting the data feed at the sub-instance level should be fine as long as it disconnects only from the sub-instance where the chart is running from and not all sub-instances. This design would force me to run one chart per sub-instance which is good compromise.

you could possibly switch between a specified collection and blank collection
- Yes. This is a good option to conditionally switch to blank collection but it will also require conditionally toggling from blank to my custom collection at session open. Hopefully, setting the collection at every tick would not cause CPU overhead.


you can set text tag in the trade window
Thinking further, what I really need is a automatic setting of "Order Text Tag Ln:24" field in the SC delivered "trading system based on alert condition" study. Please see screenshot attached. Is this possible? I can manually enter the study collection name in the "tag text" field available in trade ticket>Set" tab. I want this to be automatically set to study collection name (whichever collection I am using on the chart). p.s. this is mostly to tie my 100+ SIM accounts to easily reference the version of collection I used (instead of manually maintaining this collection/sim account mapping in excel)

No way of pausing a collection. Only thing I can think here is changing the chart update interval via ACSIL
This might work Here are the specific use cases 1) conditionally setting chart's CUI setting to 1000ms (one second) after an economic release before algo triggers a trade (to prevent slippage etc) 2) Once my daily profit/loss is met, conditionally set CUI to 1000x60x60 to run every hour until session close 3) if set to 0 (or some number like 99999999), then use whatever I have manually set in my Chart's CUI setting.
Date Time Of Last Edit: 2024-12-09 00:34:26
imageScreenshot 2024-12-08 161426.png / V - Attached On 2024-12-09 00:14:59 UTC - Size: 55.79 KB - 32 views
[2024-12-09 00:44:05]
User61168 - Posts: 442
I want to add one more item to the list of things I am unable to do via simple alert or spreadsheet formula study.

Custom ASCIL study to return "Open Trade Duration" in milliseconds. I could use this study as a "timestop" to automatically exit trades in loss. Subgraph should 1) reset to 0ms every time I Flatten or stop-n-reverse an open trade 2) continue to count if I add to open trade (scale-in) or reduce the size of open position quantity (scale-out).

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

Login

Login Page - Create Account