Login Page - Create Account

Support Board


Date/Time: Wed, 19 Mar 2025 23:23:04 +0000



[Programming Help] - Programming Spreadsheets - Exit/Entry Signal On Same Bar

View Count: 733

[2022-10-13 22:52:12]
GG - Posts: 20
Hello TIA,

When my 'Flatten Order and Cancel Orders at set time" is set to a certain time, then a buy/sell signal is triggered on that same bar, there is a glitch that opens said order and carries through until the time to trade begins again which throws off results drastically.

Is there a way to avoid this? I only open 1/day by referencing K3/M3=AND($J$52=0, my conditions) but the glitch(?) still happens.


Grace
[2022-10-14 01:43:17]
Sawtooth - Posts: 4186
Is there a way to avoid this?
You might also need to disable entries just before the flatten time. Try this:

I don't use J85-J89. Instead I use J28 and J29, like this:
J28:
=AND(J8 = 0, OR(FRACTIME(J41) < TIMEVALUE("09:30:00"), FRACTIME(J41) > TIMEVALUE("16:00:00")))
J29:
=FRACTIME(J41) > TIMEVALUE("16:15:00")

Including J8=0 in the J28 formula disallows entries after 16:00, but allows exits.
And since Autotrading is not disabled (J28) until you are flat, J29 is not disabled and can execute.
This assumes that the time in J29 is >= the later time in J28.
[2022-10-14 14:33:57]
GG - Posts: 20
Thank you.

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

J29

=FRACTIME(J41) > TIMEVALUE("09:40:00")

When 9:40 rolled around, the code said Flatten and Cancel has been ignored because autotrading has been disabled Cell J28.

I can see with my eyes that J8 = -1 yet the order is still rolling over onto the next day.


Grace
[2022-10-14 21:20:00]
Sawtooth - Posts: 4186
Be sure to set J85 and J88 to FALSE (0).

1. If you are flat (a true), and J41 is in the time window (a false), J28 is FALSE (autotrading enabled).
2. If you have a position (a false), and J41 is in the time window (a false), J28 is FALSE (autotrading enabled).
3. If you have a position (a false), and J41 is outside the time window (a true), J28 is FALSE (autotrading enabled).
4. If you are flat (a true), and J41 is outside the time window (a true), J28 is TRUE (autotrading disabled).
(This is the only situation when autotrading is disabled.)

One scenario:
- You are flat at 09:25 (#1 above)
- You take a position at 09:30 (#2 above)
- You are still in a position and J41 is between 09:35 and 09:40 (#3 above)
- You are flat because J41 > 09:40 (#4 above)

Another scenario:
- You are flat at 09:25 (#1 above)
- You take a position at 09:30 (#2 above)
- You hit your target between 09:35 and 09:40 (#3 above)
- You are flat but another entry signal is ignored because J41 is outside the time window, between 09:35 and 09:40 (#4 above)

J29 will be TRUE (1) from 09:40 to midnight, so you will be flat during this time window, unless...
If your session times do not encompass 09:40, J41 will never contain the FRACTIME needed to make J29 go TRUE.
[2022-10-17 13:25:45]
GG - Posts: 20
Thank you, not sure what I'd do without your many well thought out & knowledgeable answers. You are my Yoda xD

Grace
[2022-10-27 21:30:05]
GG - Posts: 20
Hey there,

The system: opens one trade/day at 9:25 toward VWAP if it is within the 2nd standard deviation, closed by 9:35 (or cross of VWAP).

The formulas:
K3
=AND($J$53=0,ID0.SG4@3>ID5.SG9@3,ID0.SG4@3<ID5.SG1@3)
L3
=CROSSFROMBELOW(E3:E4, ID5.SG1@3:ID5.SG1@4)
M3
=AND($J$53=0,ID0.SG4@3>ID5.SG1@3,ID0.SG4@3<ID5.SG8@3)
N3
=CROSSFROMABOVE(E3:E4, ID5.SG1@3:ID5.SG1@4)
I28
=AND(J8 = 0, OR(FRACTIME(J41) < TIMEVALUE("09:25:00"), FRACTIME(J41) > TIMEVALUE("09:35:00")))
I29
=FRACTIME(J41) > TIMEVALUE("09:35:00")
I85
=FALSE


The problem: It doesn't enter half the time with error "Spreadsheet order has been ignored because Auto Trading has been disabled. (J28/85).
J28 will read a 0 and the green/red arrow appears yet still no entry.


TIA
[2022-10-28 03:32:05]
Sawtooth - Posts: 4186
Try this in J28:
=AND(J8 = 0, OR(FRACTIME(J41) < TIMEVALUE("09:24:59"), FRACTIME(J41) > TIMEVALUE("09:35:00")))

You might also try this:
=AND(J8 = 0, OR(FRACTIME(J41) < TIME(9,24,59,999), FRACTIME(J41) > TIME(9,35,0)))
or some variation thereof.

I'm not sure exactly what's going on, but something is not aligning at 09:25:00.000

A chart's time does not advance by the second or the millisecond; it advances at the next chart update.
J41 doesn't tick off each millisecond, it updates when the next price moves in the market.

You might also need to have your session times encompass 09:25:00, where the session start time is earlier.

If your bar period produces a bar on a 5 min interval, you might use A3 instead of J41:
=AND(J8 = 0, OR(FRACTIME(A3) < TIMEVALUE("09:25:00"), FRACTIME(A3) > TIMEVALUE("09:35:00")))
[2022-10-31 15:07:17]
GG - Posts: 20
I'm going to have to play around a bit more with the formulas because these don't seem to work. It is now entering the trades only when it crosses the 0 standard deviation within the time frame, but not at 9:25 regardless. Referencing the timeframe in K3/M3 doesn't seem to work either.

TIA
[2022-10-31 15:51:27]
Sawtooth - Posts: 4186
I would need more details of your setup to offer anything else.
You can Direct Message me if you like.
Date Time Of Last Edit: 2022-11-02 13:26:22

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

Login

Login Page - Create Account