Hi Monkey,
The solution is best illustrated by means of an example. The code below is a simple strategy based on an RSI crossing certain set levels (60 and 40):
-------------------------------------------------------------
RSI:"Momentum.RSI(14)";
UpperLevel:60;
LowerLevel:40;
SELL:=CROSS(RSI,UpperLevel);
BUY:=CROSS(LowerLevel,RSI);
DRAWTEXT(BUY==1,RSI,'BUY',1),Label2,VCenter,Bottom;
DRAWTEXT(SELL==1,RSI,'SELL',2),Label1,VCenter,Top;
-------------------------------------------------------------
The above code will put 'BUY' and 'SELL' labels on the RSI in a manner you describe in your post - i.e. multiple consecutive buys and sells. Changing the code to the below solves this problem:
-------------------------------------------------------------
RSI:"Momentum.RSI(14)";
UpperLevel:60;
LowerLevel:40;
SELL:=CROSS(RSI,UpperLevel);
BUY:=CROSS(LowerLevel,RSI);
BarsSinceLastBuy:=REF(HHVBARS(BUY,100000),1);
BarsSinceLastSell:=REF(HHVBARS(SELL,100000),1);
CanSell:=IF(BarsSinceLastBuy>BarsSinceLastSell,0,1);
CanBuy:=IF(BarsSinceLastSell>BarsSinceLastBuy,0,1);
SELL2 := SELL * CanSell;
BUY2 := BUY * CanBuy;
DRAWTEXT(BUY2==1,RSI,'BUY',1),Label2,VCenter,Bottom;
DRAWTEXT(SELL2==1,RSI,'SELL',2),Label1,VCenter,Top;
-------------------------------------------------------------
The critical lines are:
BarsSinceLastBuy:=REF(HHVBARS(BUY,100000),1);
BarsSinceLastSell:=REF(HHVBARS(SELL,100000),1);
CanSell:=IF(BarsSinceLastBuy>BarsSinceLastSell,0,1);
CanBuy:=IF(BarsSinceLastSell>BarsSinceLastBuy,0,1);
SELL2 := SELL * CanSell;
BUY2 := BUY * CanBuy;
If you set up a strategy and create your initial buy and sell criteria and call them 'BUY' and 'SELL', you should be able to utilise the lines above - note that the adapted, non-repeating buy and sell signals are then called 'BUY2' and 'SELL2'.
If you have any problems with the above, please call Swordfish support.
Estuary