Imagine this simple system:
Rule: Stock's close is above MA(50)
If rule is fulfilled, send a limit order, 2% below yesterday close.
AFL Code:
/*******************************************************************
//Stock above MA
Rule1=Ref(Close,-1)>MA(Ref(Close,-1),50);
//Stock drops 2%
Rule2=Iif(Low<0.98*Ref(Close,-1),1,0);
Buy=Iif(Rule1==1 AND Rule2==1,1,0);
//Buyprice can be 2% below yesterday close, or even better.
BuyPrice=Iif(Open<0.98*Ref(Close,-1),Open,0.98*Ref(Close,-1));
SetOption("MaxOpenPositions", 5 ); // no more than 5 positions
PositionScore=ROC(C,40);
/*******************************************************************
As you can imagine, this simple system will trigger lots of buy signals every
day. Without PositionScoring, I guess Amibroker choose the stocks by
alphabetically order?
So, to solve this question, i thought in a simple ranking filter.
Lets say: PositionScore=ROC(C,40);
But, now there is my problem. If i apply PositionScore to the system above,
system will be forward-looking.
The rank is applied to every stocks dropping 3%, and the ones with better rank
are chosen.
In real life, if I already have 4 open positions, only the stock with highest
rank should be considered.
Anyone can help?
Probably my explanation wasn't clear, this isn't easy to explain. Ask me any
questions, if that was the case.
Many thanks!