In commodities like oil and gas the market loves to squeeze users who enter a short or long because RSI passes a certain threshold, because as an indicator it leads to many jumping the gun, while MACD is too much of a lag.
Is there a way to code to not just measure RSI going above a level, but put an optimised condition of how long above that level it stays before entering a short or long. (Not the frequency it hits the level)
JSParticipant
Veteran
Hi,
You can indeed introduce an extra condition to determine and optimize the number of bars above a certain level…
DefParam CumulateOrders=False
Once OBCount=0
Once OSCount=0
If RSI[20](Close)>70 then
OBCount=OBCount+1
EndIf
If OBCount>xOB then
SellShort 1 contract at Market
OBCount=0
EndIf
If RSI[20](Close)<30 then
OSCount=OSCount+1
EndIf
If OSCount>xOS then
Buy 1 contract at Market
OSCount=0
EndIf
This example will make sure that RSI has always been in OverBought in the last 10 bars:
N = 10
myCond = (summation[N](rsi[14](close) > 70) = N)
add
myCond to your conditions to enter a trade.
THanks both! Will give it a go