Login Page - Create Account

Support Board


Date/Time: Thu, 25 Apr 2024 20:27:48 +0000



[User Discussion] - Alert Condition that is only valid within X minutes of one of the conditions being TRUE

View Count: 723

[2021-07-26 09:21:38]
BenjaminR - Posts: 168
I have an alert condition that is only valid within X minutes of one of the conditions being TRUE.

To illustrate, for Condition 1, an indicator is above the zero line. Condition 2 needs to be TRUE within X minutes of Condition 1 being TRUE, or it is invalid. But I do not know how to mark the time that Condition 1 is first true, and start the "timer" waiting for Condition 2 to be true as well. If both conditions are true, but it's been longer than X minutes since Condition 1 is true, then the signal is invalid.

If anyone has some experience with something like this, please share how you worked it out.

Thank you!
[2021-07-26 11:29:28]
Sawtooth - Posts: 3976
You would need to create a persistent variable when Condition 1 goes true, then compare its bar's timestamp with either a later bar's timestamp, or J41.
Here is an example, but you'll need to modify it:
Spreadsheet Example Formulas and Usage: Cancel Unfilled Working Order n Minutes After Entry

You'll need another IF statement in the formula to cancel the persistent variable so that it's ready for the next signal.
There are some examples here, but you'll need to modify them:
Spreadsheet Example Formulas and Usage: Persistent and Incrementing Variables
[2021-07-27 00:38:11]
BenjaminR - Posts: 168
Well, I've tried to figure this out for several hours today- & I can't seem to work it out.

The signal is on a tick chart, but the signal is only valid within 5 minutes from when the MACD is above the zero line. I used Study/Price overlay to have the data from a 1 minute chart in the spreadsheet. But I've tried the timestamp formula for a buy entry on both the last price of the 1 Min. data, & the MACD differential, & for both- I get decimal numbers I don't know what to do with.

I created a Boolean 1 or 0 in a column for when the MACD is positive, & tried to apply the 'buy entry return timestamp' example formula on that. I just get a different decimal number. I'm at a loss at how to read that in terms of time.

I looked into the IF THEN ELSE format, but with the OR, I still don't understand the persistent variable/count from an event example, as it does work for counting, but it just keeps counting- I don't know how to tie it to count to 5 minutes, then reset. Seems it's counting bars on the tick chart.

Would you be so kind as to please help me through this?
Date Time Of Last Edit: 2021-07-27 00:38:56
[2021-07-27 17:19:06]
Sawtooth - Posts: 3976
I just get a different decimal number. I'm at a loss at how to read that in terms of time.
If the decimal number is the result of FRACTIME(A3), then it is the portion of the 24hr day from midnight.
To convert this to minutes, multiply it by 1440, the number of minutes in 24 hours.
Spreadsheet Example Formulas and Usage: Using Date Time

Try this to persist Condition 1, e.g. in cell O3:
=IF(AND(ID1.SG3@4>0,ID1.SG3@3<0),0,IF(AND(ID1.SG3@4<0,ID1.SG3@3>0),FRACTIME(A3)*1440,O4))
where ID1.SG3 is the MACD study's MACD Diff.
This will persist the number of minutes since midnight at the bar where the MACD Diff crossed 0 from below,
and will cancel the persist when the MACD Diff crosses 0 from above.

Then subtract it from FRACTIME(A3) of the current bar, where the difference must be <5 but not <=0, e.g. in P3:
=AND(Condition2,FRACTIME($J$41)*1440-O3<5,O3>0)

***********
You could also do this:
O3:
=IF(AND(ID1.SG3@4>0,ID1.SG3@3<0),0,IF(AND(ID1.SG3@4<0,ID1.SG3@3>0),FRACTIME(A3),O4))
P3:
=AND(Condition2,FRACTIME($J$41)-O3<5/1440,O3>0)
***********

Then find the first occurrence of the TRUE in column P for the buy signal, in K3:
=AND(P4=0,P3=1)
[2021-07-28 19:02:37]
BenjaminR - Posts: 168
I tried these yesterday, but they didn't seem to work- however I didn't run it in replay. I was going by the 1's & 0's in the K column, as once I placed the 2nd formula in P3, it all goes to 0; however, I'm going to study these formulas & work with it for awhile & try & sort this out- I'll let you know how it goes. Thank you again for your generous help!
[2021-08-05 12:12:58]
BenjaminR - Posts: 168
tomgilb:

So I must have made a typographical error or something, because I am indeed getting signals (1's in the spreadsheet & arrows on the chart). As you already know, the solutions you offered do indeed work... But I've was immediately stymied/confounded by a resulting problem, which is that the time component of the signal isn't consistently accurate between the two charts (a problem that I created another thread for, as you already know).

Thank you again for helping me hammer out these issues!

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

Login

Login Page - Create Account