Login Page - Create Account

Support Board


Date/Time: Tue, 26 Nov 2024 22:16:08 +0000



How to change trade twconfig based on ATR range values

View Count: 1055

[2023-10-08 17:34:21]
fried4104 - Posts: 66
Hello,
I've seen this can be done in ninja, so I'm wondering if you can steer me in the right direction on how to achieve this.

I use a tick chart, therefore I cannot measure ATR directly. I managed to get the ATR by using Study/Price Overlay Study to link the ATR from a 30s chart.
All is ok, I get the value in the top of my chart.

My issue, is there any way to have my SL and TP automatically adjusted based of a range of the said ATR?
Example ATR reading between 1.5 - 2.0, I would have 10/10 tick (R:R). IF it would be higher 2.5-3.5 ATR my order ticks would increase to 14/14 etc. These values I would set myself based on ATR ranges.

I searched and the closest I found is trade management by study, but I do not know how to code it for my ranges.
Any advice? Thank you very much.

PS: I know this is out of scope of SC support, I was wondering if someone ever needed something similar or had an idea of how could it be achieve.
[2023-10-08 22:08:19]
sgne - Posts: 105
Just make multiple twconfig files and enter a spreadsheet formula in J112 referencing the overlay study.
Date Time Of Last Edit: 2023-10-08 22:48:38
[2023-10-09 08:05:27]
fried4104 - Posts: 66
Thanks, I don't know anything about spreadsheets, I will look into it. Maybe also find some videos about it.
[2023-10-09 16:21:01]
Sawtooth - Posts: 4120
The Trade Management by Study study will move a TP or SL to the price of the study's subgraph it is referencing.
You'd need a instance for each.

Use the Spreadsheet Formula study to return a TP price based on a formula or value in its Formula field.
You'd need another instance for the SL price.
(Note: Despite its name, the Spreadsheet Formula study is not a spreadsheet study.)

As for using cell J112:
This cell function is only available in the Spreadsheet System for Trading study.
This study is for autotrading, so be careful to not put any formulas in columns K-N.

Both options will require writing formulas.
[2023-10-09 19:05:33]
Sierra_Chart Engineering - Posts: 17185
There is no built-in way to do this but certainly a custom solution can be developed using ACSIL:
Table of Contents | (Advanced Custom Study/System Interface and Language (ACSIL))

ACSIL has the ability to reference a study:
ACSIL Programming Concepts: Using or Referencing Study/Indicator Data in an ACSIL Function

And you can control the Trade Window configuration file:
Automated Trading From an Advanced Custom Study: Programmatically Setting Trade Window Configuration
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: 2023-10-09 19:07:19
[2023-10-10 10:13:07]
fried4104 - Posts: 66
Thanks, this is fairly advanced for me. But I will read more on it.

Just to clarify, I do not want autotrading, I just want to rotate through 3 or 4 twconfigs with different tick SL and TP, and these to be auto-selected when I open a trade based on the current ATR reading range at the moment I open my trade.

if ATR 1-1.5 = twconfig1 (8:8 RR)
if ATR 1.5-2.5 = twconfig2 (11:11 RR)
etc.


One question J112 - means row J column 112?
[2023-10-10 15:03:04]
frozentundra - Posts: 91
Just to clarify, I do not want autotrading, I just want to rotate through 3 or 4 twconfigs

@fried - Check out this link: ACSIL Interface Members - Variables and Arrays: sc.TradeWindowConfigFileName
[2023-10-10 17:18:32]
Sawtooth - Posts: 4120
One question J112 - means row J column 112?
Columns are lettered, rows are numbered, so J112 is column J, row 112.

I do not want autotrading, I just want to rotate through 3 or 4 twconfigs with different tick SL and TP, and these to be auto-selected when I open a trade based on the current ATR reading range at the moment I open my trade.

Try this:
Add the Spreadsheet System for Trading study.
- Give it a name in the Spreadsheet Name field.
- Set the 'Number of Rows' to 10.
- Click OK and OK.

On the spreadsheet sheet:
- Enter a formula like this in cell O3:
=AND(ID1.SG1@3>=1,ID1.SG1@3<1.5)
- Enter a formula like this in cell P3:
=AND(ID1.SG1@3>=1.5,ID1.SG1@3<2.5)
where ID1.SG1 is your ATR study; edit to your ATR's ID#.SG#.

- Enter a formula like this in cell J112:
=IF(O3=1,"88RR.twconfig",IF(P3=1,"1111RR.twconfig",0))
Edit to your names for each twconfig file.

- Enter =1 in cell J28.

Note: Do not enter any formulas in K3, L3, M3, N3.
This will not autotrade, it will only choose your twconfig file.

If the ATR goes above 2.5 or below 1, it will retain the previously chosen twconfig.
Date Time Of Last Edit: 2023-10-10 17:21:03
[2023-10-10 18:08:06]
fried4104 - Posts: 66
Many thanks @Sawtooth!!

Will test it tomorrow and post back feedback.
[2023-10-11 11:21:44]
fried4104 - Posts: 66
Hey,
It seems it won't work on my end.
I followed your instructions, but I see no changes when trying to open a trade. The twconfig never changes.

Could it be because the ATR reading is being taken from another chart and shown on my current tick chart (I use Study/Price Overlay Study to link the ATR from a 30s chart)?
Thanks again.
[2023-10-11 12:15:52]
sgne - Posts: 105
Sawtooth's idea seems to work, just from changing a formula cell, with auto-trading disabled. As long as you have a formula cell changing on your trading chart, it should switch twconfig's.
Date Time Of Last Edit: 2023-10-11 14:25:52
[2023-10-11 17:53:47]
Sawtooth - Posts: 4120
It seems it won't work on my end.
It works for me in my testing.

The change of twconfig is not related to opening a trade; it is based only on the ATR value.
Are you referencing the Study/Price Overlay study?
[2023-10-11 18:22:49]
fried4104 - Posts: 66
It does work indeed :)

Sorry, it seems I somehow removed the "Include in Spreadsheet" option from the Study/Price Overlay study to avoid displaying addtional information.
Actually I did this with almost all studies, since I never used it.

It successfully changed configs, many thanks!!!!

One more question, if possible, what would be the syntax if I wanted to add 3 or more options?

e.g. - ATR 0.5-1.10 - notrading.tw
ATR 1.11-1.8 - x1.tw
ATR 1.81-2.2 - x2.tw
ATR 2.3-3.0 - x3.tw
ATR 3.1 - 15.0 - x4.tw

Have a great day and thank you once again for your help!
[2023-10-11 18:30:05]
Sawtooth - Posts: 4120
what would be the syntax if I wanted to add 3 or more options?
Use more Formula Columns for each ATR range, and use more IF statements in J112.
[2023-10-11 18:33:55]
fried4104 - Posts: 66
Amazing, thanks!

=IF(O3=1,"1.twconfig",IF(P3=1,"2.twconfig",IF(Q3=1,"2.twconfig",IF(R3=1,"3.twconfig",IF(S3=1,"4.twconfig",0))

Would the above be correct?
[2023-10-11 18:48:24]
sgne - Posts: 105
You need more right parens.

You can also shift the complex formula to column O, and make J112 simpler.

O3
=if(and(ATR>1.1,ATR<=1.8),"x1",if(...

J112
=concatenate(O3,".twconfig")
[2023-10-11 21:51:40]
Sawtooth - Posts: 4120
Would the above be correct?
You have a double 2, and you need a closing parenthesis for each IF:
=IF(O3=1,"1.twconfig",IF(P3=1,"2.twconfig",IF(Q3=1,"3.twconfig",IF(R3=1,"4.twconfig",IF(S3=1,"5.twconfig",0)))))
[2023-10-12 08:43:41]
fried4104 - Posts: 66
Thanks guys, very helpful.
I'm all good.

Thing I noticed, I cannot manually overwrite a twconfig.
Is there a way to have a custom button on the control bar or something to be able to toggle the study/spreadsheet in case you do not want it enforced?

Many thanks for your support.
[2023-10-12 11:16:47]
fried4104 - Posts: 66
Final version, thanks @sgne, I made it a bit simpler with your suggestion for one liner:

O3
=if(and(ID5.SG1@3>=0.2,ID5.SG1@3<0.9),"3-6",if(and(ID5.SG1@3>=0.9,ID5.SG1@3<1.05),"5-7",if(and(ID5.SG1@3>=1.05,ID5.SG1@3<1.20),"7-8",if(and(ID5.SG1@3>=1.20,ID5.SG1@3<1.45),"8-8",if(and(ID5.SG1@3>=1.45,ID5.SG1@3<2.55),"10-10",if(and(ID5.SG1@3>=2.55,ID5.SG1@3<3.55),"12-10",if(and(ID5.SG1@3>=3.55,ID5.SG1@3<10),"15-15",0)))))))

J112
=concatenate(O3,".twconfig")

Thanks both @Sawtooth and @sgne, amazing!

I need now to search how to make it toggle-able (is this even a word? :)

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

Login

Login Page - Create Account