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;
Cover = Close < MA( Close , 10 );
PositionSize = -10;
type or paste code here
@harryzehnwirth this should help you figure it out.
http://www.amibroker.com/kb/2014/09/20/broad-market-timing-in-system-formulas/
12m
thanks Larry
I'm not quite there yet (I am new, but trying hard :
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;
Copy
//
// 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;
@harryzehnwirth it doesn't look like you added your marketdown condition to your Short rules. To do that, you'll need to put these lines before your Short assignment:
//
// 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;
You'll then need to add something like this to the Short assignment:
AND marketdown
Also make sure your database includes a symbol named ^GSPC
. The S&P 500 index might also be named SPX, $SPX, or some other variation. You could also use SPY, the S&P 500 ETF.
Works well. Thank you.