Login Page - Create Account

Support Board


Date/Time: Fri, 14 Jun 2024 15:22:14 +0000



[User Discussion] - Combining two conditions in spreadsheet studies

View Count: 3601

[2014-01-27 21:11:42]
User57878 - Posts: 24
Hi,

I have two indocators that i want to automatise.
One is the Psar, and the other is a crossover system.
The conditions taken solely works like a charm.
The Psar is in the AA column, the last price in E, and the 2 moving averages are on AE(short ema) and AF(long ema).
For the buy conditions it's:

Psar: =AND(AA4>E4;E3>AA3)
Crossover: =AND(AE4<AF4;AE3>AF3)

Theses codes works, and i want now to combine them in one code in these ways:
1- psar AND crossover conditions respected
2-psar OR crossover conditions respected.

Can someone help me with this please? how way can i link them with AND and OR ?


Date Time Of Last Edit: 2014-01-27 21:12:03
[2014-01-28 01:37:03]
Sawtooth - Posts: 4023
Try this:

=OR(AND(AA4>E4;E3>AA3;AE3>AF3);AND(E3>AA3;AE4<AF4;AE3>AF3))

This will signal when the MAs cross and the PSAR has already changed direction, OR when the PSAR changes direction and the MAs have already crossed.

[2014-01-28 08:02:16]
User57878 - Posts: 24
Hi,
thanks for your help, but it doesn't work.
I also forgot to precise that It's a spreadsheet system for trading, not for alert.

What i want is 2 codes liking the psar and the crossover in 2 ways.

1-One code for buy when the psar dot appears AND the ma's crossover happens and
2- another code for buy when the psar dot appears AND the ma's crossover happens.

Thanks again

Date Time Of Last Edit: 2014-01-28 09:09:46
[2014-01-28 16:35:53]
User57878 - Posts: 24
Up! Help please ?
[2014-01-28 16:46:04]
Sawtooth - Posts: 4023
It seems I don't understand what you want. Please explain again


[2014-01-28 17:02:44]
User57878 - Posts: 24
Attached is the spreadsheet file.
I want 2codes, for backtesting purposes, to know the better one.
The case 1 is when the psar dot appears, and the case 2 is when the crossover of the Zlag emas happens.
So, talking about the buy case:

1- One code to buy when the psar dot appears AND the ma's crossover happens(case1 and case 2 respected for the buy)
2- One code to buy when the psar dot appears OR the ma's crossover happens.(case 1 or case 2 respected for the buy)
The problem is i don't know how to melt many conditions together with the AND OR.

Thanks again
attachmentVERCRO TEST.scwbf - Attached On 2014-01-28 17:02:35 UTC - Size: 152.9 KB - 405 views
[2014-01-28 17:33:09]
Sawtooth - Posts: 4023
Try these:

1) =AND(AA4>E4;E3>AA3;AE4<AF4;AE3>AF3)
This will signal when both are TRUE in the same bar.
You can also do it this way if it is clearer for you:
=AND(AND(AA4>E4;E3>AA3);AND(AE4<AF4;AE3>AF3))

2) =OR(AND(AA4>E4;E3>AA3);AND(AE4<AF4;AE3>AF3))
This will signal when either are TRUE.
[2014-01-29 10:06:18]
User57878 - Posts: 24
Thanks for the time you give me.

Your codes works, but i think my logic is a bit more complicated.
Because i want two condiitons to enter a trade, Psar and crossover, the order of happening isn't important as soon as the 2condtions happens.
The problem is the automated system misses many good trade opportunities because he only track the n-1 and the n time state(with row 4 and 3 on K column for the buy, and M column for the sell).
For example, talking about the code 1) you gave me, when i got my crossover, and the psar dot on the same candle, it's a ok signal and your codes works very well.
But when i got a psar dot, and 2candles later the crossover happens, i want it to launch a trade too. But as it's not on the same candle, the system considers it as a no go trade.
I wonder how i can code it to take a trade as soon as the two conditions are met, no mattering it's on the same candle, or if it's 2,3 or 4 candles later( psar dot + crossover or crossover + psar dot, no mattering the order of the signals).

[2014-01-29 15:47:45]
User57878 - Posts: 24
Up
[2014-01-29 22:31:24]
User57878 - Posts: 24
Help please
[2014-01-30 03:03:01]
Sawtooth - Posts: 4023
What you want to do is more complicated than combining OR and AND statements. It requires formulas in several columns, using double IF statements, the first to start a TRUE, the second to end the TRUE.

For example, a buy entry:
K3: =AND(O3,P3)
O3: =IF(AND(AA4>E4,E3>AA3),TRUE,IF(AND(AE5<AF5,AE4>AF4),FALSE,O4))
P3: =IF(AND(AE4<AF4,AE3>AF3),TRUE,IF(AND(AA5>E5,E4>AA4),FALSE,P4))

Notice the end TRUE offsets the rows by one row.



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

Login

Login Page - Create Account