Login Page - Create Account

Support Board


Date/Time: Thu, 26 Sep 2024 23:30:50 +0000



[Programming Help] - Disable Trading Hours with Spreadsheet

View Count: 93

[2024-09-03 14:44:16]
alexo2022 - Posts: 46
I want to create a formula the limit the trading hours,
for example

trading only between 00:00-02:00
04:15-08:00
10:15-15:00

all other hours, disable the trade.

this is the formula I use, and it's not working.


=AND(J8 = 0,
OR(OR(FRACTIME(J41) < TIMEVALUE("00:00:00"), FRACTIME(J41) > TIMEVALUE("23:59:00")), AND(FRACTIME(J41) > TIMEVALUE("04:15:00"), FRACTIME(J41) < TIMEVALUE("08:00")), AND(FRACTIME(J41) > TIMEVALUE("10:15:00"), FRACTIME(J41) < TIMEVALUE("15:00")) )))
Date Time Of Last Edit: 2024-09-03 14:45:44
[2024-09-03 17:18:50]
Sawtooth - Posts: 4092
You need 3 AND portions, each within the same OR, plus an overall AND for the J8.
None of your disable times span Midnight, so you don't need the OR portion within the OR.
And remember, the formula is using times to disable, not enable.

Try this:
=AND(J8=0,OR(AND(FRACTIME(J41)>TIMEVALUE("02:00:00"),FRACTIME(J41)<TIMEVALUE("04:15:00")),AND(FRACTIME(J41)>TIMEVALUE("08:00:00"),FRACTIME(J41)<TIMEVALUE("10:15:00")),AND(FRACTIME(J41)>TIMEVALUE("15:00:00"),FRACTIME(J41)<=TIMEVALUE("23:59:59"))))
Date Time Of Last Edit: 2024-09-03 17:37:04
[2024-09-03 18:21:39]
alexo2022 - Posts: 46
in the formula you wrote, you didn't mention "00:00" at all, why ?

so how can write this formula so I can define which hours I want to enable trading ?
Date Time Of Last Edit: 2024-09-03 18:27:24
[2024-09-03 19:39:08]
Sawtooth - Posts: 4092
in the formula you wrote, you didn't mention "00:00" at all, why ?
so how can write this formula so I can define which hours I want to enable trading ?

Because the formula is used to disable autotrading, not enable it.
So all 3 time windows are disable times, not enable times.
Autotrading will be enabled at all other times not mentioned.
Date Time Of Last Edit: 2024-09-03 19:40:30
[2024-09-04 04:17:15]
alexo2022 - Posts: 46
Now I understand,
thanks a lot !
[2024-09-04 04:24:22]
alexo2022 - Posts: 46
Is it possible to limit the number of trades
for each time period that it can trade.

for example, if it is trading between 10:15-15:00,
I want to limit the up to 5 trades.
after 5 trades, I want to system to stop trading.

also when it is trading between 04:15-08:00
I want to limit up to 4 trades.

etc.
[2024-09-04 04:43:27]
Sawtooth - Posts: 4092
s it possible to limit the number of trades for each time period that it can trade.
It might be possible using the Trading: Total Trades study,
where its value at the start of each period would be made persistent in a Formula Column,
then that value would be subtracted from the Trading: Total Trades value in another Formula Column,
then that Formula Column would be referenced in J28 to disable autotrading.

That's the concept, but I can think of potential issues.
It's more complex than I want to offer in a forum post.

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

Login

Login Page - Create Account