Please create trading strategy from this formula. Condition for exit:
1. Stop loss or take profit
2. On next candle
Code:
strategy("RSI small trade strategy", overlay=true, precision=5, currency="AUD")
//--------------- input parameters
src = input(defval=close, type=source, title="Source")
lenrsi = input(3, minval=1, type=integer, title="RSI Length")
lenupdown = input(2, minval=1, type=integer, title="UpDown Length")
lenroc = input(100, minval=1, type=integer, title="ROC Length")
//--------------- define function
updown(s) =>
isEqual = s == s[1]
isGrowing = s > s[1]
ud = isEqual ? 0 : isGrowing ? (nz(ud[1]) <= 0 ? 1 : nz(ud[1])+1) : (nz(ud[1]) >= 0 ? -1 : nz(ud[1])-1)
ud
//--------------- calculate RSIs
rsi = rsi(src, lenrsi)
updownrsi = rsi(updown(src), lenupdown)
percentrank = percentrank(roc(src, 1), lenroc)
crsi = avg(rsi, updownrsi, percentrank)
//--------------- calculate signal
sig1 = (close >= open) and (crsi < (crsi[1] - 3)) ? 1 : na
sig2 = (close <= open) and (crsi > (crsi[1] + 3)) ? 1 : na
midline = input (68)
price = close
Take_Profit = input(50)
Stop_Loss = input(50)
longCondition = sig2
if (longCondition)
strategy.entry("LongEntry", strategy.long)
strategy.exit("LongExit", "LongEntry", profit = Take_Profit, loss = Stop_Loss)
shortCondition = sig1
if (shortCondition)
strategy.entry("ShortEntry", strategy.short)
strategy.exit("ShortExit", "ShortEntry", profit = Take_Profit, loss = Stop_Loss)