Login Page - Create Account

Support Board


Date/Time: Fri, 03 May 2024 20:03:26 +0000



[Programming Help] - Disable Trading Time Formula

View Count: 991

[2020-07-16 01:03:25]
User355030 - Posts: 163
I'm looking to write a formula (most likely in "J28") that allows for up to 1 total trade (J52) between 00:00:00 - 07:00:00 and up to 1 total trade (J52) between 09:00:00.

Any ideas?
[2020-07-16 01:04:11]
User355030 - Posts: 163
@tomgilb
[2020-07-16 01:18:19]
Sawtooth - Posts: 3992
What is the end time of the second time window?
[2020-07-16 01:23:32]
User355030 - Posts: 163
Sorry 09:00:00-15:00:00
[2020-07-16 01:23:54]
User355030 - Posts: 163
@tomgilb
[2020-07-16 01:46:53]
Sawtooth - Posts: 3992
Try this:

J28:
=AND(J8 = 0, OR(OR(FRACTIME(J41) < TIMEVALUE("00:00:00"), FRACTIME(J41) > TIMEVALUE("15:00:00")), AND(FRACTIME(J41) > TIMEVALUE("07:00:00"), FRACTIME(J41) < TIMEVALUE("09:00:00"))))

This is a modification of this example:
https://www.sierrachart.com/index.php?page=doc/SpreadsheetExampleFormulasAndUsage.php#DisableTradingOutsideOfRegularTradingHoursAnd2HoursMidday

H28:
=OR(AND(FRACTIME(J41) > TIMEVALUE("00:00:00"), FRACTIME(J41) < TIMEVALUE("07:00:00"),J52=0), AND(FRACTIME(J41) > TIMEVALUE("09:00:00"), FRACTIME(J41) < TIMEVALUE("15:00:00"),J52=1))

Reference $H$28 = 1 in your K3/M3 formulas.

Note: I didn't test this.
[2020-07-19 22:26:53]
User355030 - Posts: 163
@tomgilb, thanks for the reply. The formula below doesn't take the "1 trade into consideration."


"J28:
=AND(J8 = 0, OR(OR(FRACTIME(J41) < TIMEVALUE("00:00:00"), FRACTIME(J41) > TIMEVALUE("15:00:00")), AND(FRACTIME(J41) > TIMEVALUE("07:00:00"), FRACTIME(J41) < TIMEVALUE("09:00:00"))))
"
[2020-07-19 22:28:36]
User355030 - Posts: 163
never mind, you are saying to use both of the formulas
[2020-07-19 22:42:34]
User355030 - Posts: 163
@tomgilb, I am confused on how these formulas meet the requirement
[2020-07-20 03:57:47]
Sawtooth - Posts: 3992
The J28 formula disables autotrading outside of your two time windows.
The H28 formula allows autotrading inside of your two time windows, plus J52 must be 0 inside the first time window, and J52 must be 1 inside the second time window.
J52 will be 0 at the start of the day, so H28 will be true inside of the first time window.
J52 will be 1 if a trade occurred in the first time window, so only one trade would occur inside the first time window, but will allow a trade in the second time window.
J52 will be 2 if a trade occurred in the second time window, so only one trade would occur inside the second time window.

If no trade occurred in the first time window, then no trade would occur in the second time window. If you want a trade in the second time window when none occurred in the first time window, use this formula instead in H28:
=OR(AND(FRACTIME(J41) > TIMEVALUE("00:00:00"), FRACTIME(J41) < TIMEVALUE("07:00:00"),J52<1), AND(FRACTIME(J41) > TIMEVALUE("09:00:00"), FRACTIME(J41) < TIMEVALUE("15:00:00"),J52<2))

Then you reference H28 in your K3/M3 formulas, like this:
=AND(YourEntryConditions,$H$28=1)
[2020-07-22 01:58:58]
User355030 - Posts: 163
@tomgilb

I appreciate all your help. I want the two time windows to be completely independent from another. Meaning that if there is a trade in the first window, there can be a trade in the second window. If there is no trade in the first window, there can still be a trade in the second window. Both time windows are aloud one daily trade.
[2020-07-22 02:25:50]
User355030 - Posts: 163
Actually your original is fine
Date Time Of Last Edit: 2020-07-22 02:25:57
[2020-07-22 02:59:17]
User355030 - Posts: 163
@tomgilb

Last piece is having the positions flatten at 07:00:00 & 15:00:00
[2020-07-22 03:59:59]
Sawtooth - Posts: 3992
Last piece is having the positions flatten at 07:00:00 & 15:00:00
Cell J29:
=OR(AND(FRACTIME(J41) >= TIMEVALUE("07:00:00"),FRACTIME(J41) < TIMEVALUE("09:00:00")),FRACTIME(J41) >= TIMEVALUE("15:00:00"))
[2020-07-22 17:12:31]
User355030 - Posts: 163
@tomgilb

this formula actually doesn't work because if 00:00:00 - 07:00:00 doesn't have a trade, then 09:00:00 - 15:00:00 can have potentially two trades.

=OR(AND(FRACTIME(J41) > TIMEVALUE("00:00:00"), FRACTIME(J41) < TIMEVALUE("07:00:00"),J52<1), AND(FRACTIME(J41) > TIMEVALUE("09:00:00"), FRACTIME(J41) < TIMEVALUE("15:00:00"),J52<2))
[2020-07-22 19:25:21]
Sawtooth - Posts: 3992
Try this in H28:
=OR(AND(FRACTIME(J41) > TIMEVALUE("00:00:00"), FRACTIME(J41) < TIMEVALUE("07:00:00"),J52=0), IF(AND(FRACTIME(J41) > TIMEVALUE("09:00:00"), FRACTIME(J41) < TIMEVALUE("15:00:00"),J52=0),AND(FRACTIME(J41) > TIMEVALUE("09:00:00"), FRACTIME(J41) < TIMEVALUE("15:00:00"),J52=0),AND(FRACTIME(J41) > TIMEVALUE("09:00:00"), FRACTIME(J41) < TIMEVALUE("15:00:00"),J52=1)))

Note: I didn't test this.
[2020-07-26 21:44:40]
User355030 - Posts: 163
Hey Tom this formula does not work, it fires off two trades from 09:00:00 -15:00:00 when there is no trade from 00:00:00 - 07:00:00

Try this in H28:
=OR(AND(FRACTIME(J41) > TIMEVALUE("00:00:00"), FRACTIME(J41) < TIMEVALUE("07:00:00"),J52=0), IF(AND(FRACTIME(J41) > TIMEVALUE("09:00:00"), FRACTIME(J41) < TIMEVALUE("15:00:00"),J52=0),AND(FRACTIME(J41) > TIMEVALUE("09:00:00"), FRACTIME(J41) < TIMEVALUE("15:00:00"),J52=0),AND(FRACTIME(J41) > TIMEVALUE("09:00:00"), FRACTIME(J41) < TIMEVALUE("15:00:00"),J52=1)))
[2020-07-27 02:15:38]
Sawtooth - Posts: 3992
Try this in H28:

=OR(AND(FRACTIME(J41) > TIMEVALUE("00:00:00"), FRACTIME(J41) < TIMEVALUE("07:00:00"),J52=0), AND(FRACTIME(J41) > TIMEVALUE("09:00:00"), FRACTIME(J41) < TIMEVALUE("15:00:00"),OR(J52=0, AND(J52=1, FRACTIME(J43) > TIMEVALUE("00:00:00"), FRACTIME(J43) < TIMEVALUE("07:00:00")))))

Note: I didn't test this.

If this formula doesn't work for you, you can use these examples to create a formula on your own that does what you want.
[2020-07-27 14:55:45]
User90125 - Posts: 715
At this point the OP might want to contact Tom directly at https://www.sawtoothtrade.com/contact as he does this for a living.

Pay a few shekels and get a working answer.

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

Login

Login Page - Create Account