Combining 2 formulas

Hi people. How do I combine 2 formulas in a scan/exploration so that it narrows down my search even more? Do I just put a symbol, or AND or PLUS in somewhere?

@vekian scan/exploration results are controlled by the Filter array.

How to create your own exploration

Since it is a logical array (true/false values), you can create it combining as many conditions as you want using the logical AND / OR / NOT operators.

Directly from the AFL Reference Manual:

Logical operators

Symbol Meaning
NOT Logical "Not" - gives "True" when operand is equal to false
AND Logical "And" - gives "True" result if BOTH operands are true at the same time
OR Logical "Or" - gives "True" result if ANY of operands is true

A search in the forum will find many examples of exploration code that set the Filter variable using multiple rules.

So probably, you can just combine the conditions of your two formulas to achieve your goal.

2 Likes

thanks Larry
I'm not quite there yet (I am new, but trying hard :slightly_smiling_face: :
I'd like to enter trades only when SP below its 200 day MA

this is my formula now, though the back test doesn't 'pick up' or adhere to the SP condition:

Buy = 0;

Sell = 0;

Short = RSI( 3 ) > 85
AND Close > Ref( Close , -1 )
AND Ref( Close , -1 ) > Ref( Close , -2 )
AND Volume > 500000
AND MA( Volume , 21 ) > 500000
AND Ref( MA( Volume , 21 ) , -21 ) > 500000
AND ADX( 7 ) > 50
AND ATR( 10 ) > Close/20
AND Close > 5;

//

// read S&P 500 values from ^GSPC ticker
//
sp500 = Foreign( "^GSPC", "C" );
//
// market-wide filter should be in "state" form
// (so it is True all the time when market is down)
//
marketdown = sp500 < MA( sp500, 200 );
marketup = NOT marketdown;

Cover = Close < MA( Close , 10 );

PositionSize = -10;

Ok. Thanks beppe. That seems simple enough.