IIF or IF ? Stopping conditions from executing signals

Hi,

My buy and sell signals are composed of various conditions,
(this is an example I found online)

Cond1=Cross( MACD ( 12 , 26 ) , Signal ( 12, 26, 9 ) );
Cond2=Cross( StochK ( 15 , 3 ) , StochD ( 15, 3, 3 ) );

Buy = Cond1 and Cond2;


Now, I want to add an "IF (IFF?) condition,

Lets suppose I want that the "Buy" signal is "false" (ie, doesnt actually buys) if another set Conditions are "true"

Let's call Cond3 and Cond4

Cond3=Cross( Signal ( 12, 26, 9 ) , MACD ( 12, 25 ));
Cond4=Cross( StochD ( 15, 3, 3 ) , StochK ( 15 , 3 ) );

so, if Cond3 and Cond4 are TRUE, then Cond1 and Cond2 doesnt trigger the "buy"


I'm new to Amibroker, thanks for the help and I hope this question is written in a valid way for everyone to understand

Not sure if this would be correct or makes sense

(Cond3 and Cond4 are indicators defined in the code somewhere)


IIf (Cond3 < Cond4);
{
(Cond1 AND Cond2 = False);
};

@Bob the code is incorrect. Your conditions are arrays and for this reason, you should be using IIF plus AND / OR / NOT operators if you want to combine conditions.
Such as

Buy = Cond1 and Cond2 and NOT Cond3;

Really you should be using SEARCH before posting. This subject has been discussed over and over again
https://forum.amibroker.com/tags/iif

Specifically this: IIf function versus if statement is a MUST-READ.

Also something about boolean logic: https://en.wikipedia.org/wiki/Boolean_algebra

Last but not least: use CODE TAGS for posting code.

3 Likes