Login Page - Create Account

Support Board


Date/Time: Tue, 30 Apr 2024 05:04:35 +0000



[Programming Help] - False positives using IF statement

View Count: 926

[2020-03-05 21:20:58]
tommartin321 - Posts: 74
Hello,

I'm getting some random false positives from my IF statement below. I want the statement to put a 1 in column if the bar Open is < the three EMA's (ID11, ID12, ID15). And the opposite should produce a -1. However, about 95% of the signals are correct, but every now and then, a false signal appears. See example in attached screenshot.

=IF(AND(B3<ID11.SG1@3,B3<ID12.SG1@3,B3<ID15.SG1@3),1,IF(AND(B3>ID11.SG1@3,B3>ID12.SG1@3,B3>ID15.SG1@3),-1,U4))

Thank you,

Tom
imageEMA5_8_13.png / V - Attached On 2020-03-05 21:19:40 UTC - Size: 20.86 KB - 167 views
[2020-03-05 22:07:20]
Sawtooth - Posts: 3985
Are you using renko bars?

If so, you need to add the Renko Visual Open/Close Values study, and reference its SG1 instead of B3.
[2020-03-05 22:38:29]
tommartin321 - Posts: 74
No, I'm using Range Per Bar - Standard (in ticks).
[2020-03-06 00:32:50]
Sawtooth - Posts: 3985
It could be related to the Value Format setting.
Study/Chart Alerts And Scanning: The Effect of the Value Format on Identifier Values
[2020-03-06 01:56:06]
tommartin321 - Posts: 74
Changing the Value Format didn't work.

The formulas work correctly if I put them directly in K(Buy Entry) and M(Sell Entry).

For example if put =AND(B3<ID11.SG1@3,B3<ID12.SG1@3,B3<ID15.SG1@3) in the K column I get the correct buy signals.

And if I put the second part of the IF statement =AND(B3>ID11.SG1@3,B3>ID12.SG1@3,B3>ID15.SG1@3) in column M I get the correct sell signals.
[2020-03-06 03:57:11]
Sawtooth - Posts: 3985
Is the formula in post #1 in cell U3?
[2020-03-06 09:53:42]
tommartin321 - Posts: 74
Yes, it's in U3, not U4.
[2020-03-06 14:09:23]
Sawtooth - Posts: 3985
Upon closer look at that formula, it won't change to the opposite polarity until B3 has made the full transition to the other side, so there will be some false positives in between.

You could just use two columns:
=IF(AND(B3>ID11.SG1@3,B3>ID12.SG1@3,B3>ID15.SG1@3),1,0)
=IF(AND(B3>ID11.SG1@3,B3>ID12.SG1@3,B3>ID15.SG1@3),-1,0)

If you want the formula in only one column, you'll need a third condition, rewritten using MAX and MIN functions:
=IF(AND(B3>=MIN(ID11.SG1@3,ID12.SG1@3,ID15.SG1@3),B3<=MAX(ID11.SG1@3,ID12.SG1@3,ID15.SG1@3)),0,IF(B3<MIN(ID11.SG1@3,ID12.SG1@3,ID15.SG1@3),1,IF(B3>MAX(ID11.SG1@3,ID12.SG1@3,ID15.SG1@3),-1,U4)))
[2020-03-07 20:16:36]
tommartin321 - Posts: 74
Yes, that works. Thanks tom

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

Login

Login Page - Create Account