Login Page - Create Account

Support Board


Date/Time: Thu, 25 Apr 2024 17:55:41 +0000



[Programming Help] - Programming - How to Buy/Sell Exit 2*ATR

View Count: 400

[2022-06-14 21:25:04]
GG - Posts: 20
System is designed to enter buy if gap from previous day's high to current day's open is larger than 2*ATR. System enters sell if gap from previous day's low to current days open is larger than 2*ATR. I am doing this by referencing OHLC (References Days Back: 1).

BuyEntry
=(J16-ID1.SG2@3)>(ID2.SG1@3*2)

BuyExit (Sell)
=OR(AND(J8 > 0, ID0.SG4@3 <= J9-(ID2.SG1@3*2)), AND(J8 > 0, ID0.SG4@3 >= J9+(ID2.SG1@3*2)))

SellEntry
=(ID1.SG3@3-J16)>(ID2.SG1@3*2)

SellExit (Buy)
=OR(AND(J8 < 0, ID0.SG4@3 >= J9+(ID2.SG1@3*2)), AND(J8 < 0, ID0.SG4@3 <= J9-(ID2.SG1@3*2)))


The Problem:
When replaying past days, Daily Open (J16) = 0. So it sends a SellEntry through every bar. I'm not sure how else to reference Daily Open when my OHLC is set to previous day?


Thanks for your help.
[2022-06-15 02:26:21]
Sawtooth - Posts: 3976
I'm not sure how else to reference Daily Open when my OHLC is set to previous day?
You could add another instance of the Daily OHLC study, with Reference Days Back set to 0.

Note: When referencing column J in Formula Columns, use an absolute reference:
=OR(AND($J$8 > 0, ID0.SG4@3 <= $J$9-(ID2.SG1@3*2)), AND($J$8 > 0, ID0.SG4@3 >= $J$9+(ID2.SG1@3*2)))
[2022-06-15 17:21:15]
GG - Posts: 20
Thank you, that worked perfectly.

Now the problem I am running into is the ATR. Is there any way to reference the ATR but only at 9:30?

i.e my BuyEntry isn't triggered at open but since I need the BuyExit to trigger during trade hours, my Chart Start Time is 9:30 and End Time is 17:00. So if ATR slowly decreases throughout the day, the BuyEntry is triggered mid day.


BuyEntry:
=(ID6.SG1@3-ID1.SG2@3)>(ID2.SG1@3*2)
[2022-06-15 18:03:51]
Sawtooth - Posts: 3976
Is there any way to reference the ATR but only at 9:30?
If you want to reference the ATR's level as it was at 09:30:
Create a persistent variable of the ATR*2 at 09:30, like this, e.g. in cell P3:
=IF(FRACTIME(A3)=TIME(09,30,0),ID2.SG1@3*2,P4)

If you want to only signal in the bar that is timestamped 09:30:
=AND(FRACTIME(A3)=TIME(09,30,0) , ID6.SG1@3-ID1.SG2@3 > ID2.SG1@3*2 )

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

Login

Login Page - Create Account