You are on page 1of 2

//@version=4

strategy("RSI2", overlay=true)

//inizializzazione parametri

//RSI
src = close
len = input(2, minval=1, title="RSILength")
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down)

//medie mobili

mmlen = input(200, title="Slow MA len")


mmflen = input(50, title="Fast MA len")
machoice = input(defval="EMA", options=["SMA", "EMA"])

//soglie RSI
RSIthreshUP = input (90, title="Threshold RSI up")
RSIthreshDWN = input (10, title="Threshold RSI down")

//input ticker
tick=input(0.5,title="Ticker size",type=input.float)
filter=input(true,title="Trend Filter",type=input.bool)

mmslow = if machoice == "SMA"


sma(close, mmlen)
else
ema(close, mmlen)

mmfast = if machoice == "SMA"


sma(close, mmflen)
else
ema(close, mmflen)

plot(mmslow, color=color.white)
plot(mmfast, color=color.yellow)

//condizioni ingresso ed uscita mercato. Uscita non utilizzate

ConditionEntryL = if filter == true


mmfast > mmslow and close > mmslow and rsi < RSIthreshDWN
else
mmfast > mmslow and rsi < RSIthreshDWN

ConditionEntryS = if filter == true


mmfast < mmslow and close < mmslow and rsi > RSIthreshUP
else
mmfast < mmslow and rsi > RSIthreshUP
//ConditionExitL = (barssince(close>open)>2)
//ConditionExitS = (barssince(open>close)>2)

//impostazione trailing stop


ts = input(1, title="TrailingStop%", type=input.float)
ts_calc = close * (1/tick) * ts * 0.01

//ingressi ed uscite Mercato


if ConditionEntryL
strategy.entry("RSILong", strategy.long)

strategy.exit("ExitLong", "RSILong", trail_points=0, trail_offset=ts_calc)


//if (ConditionExitL)
// strategy.close ("RSILong")

if ConditionEntryS
strategy.entry("RSIShort", strategy.short)

strategy.exit("ExitShort", "RSIShort", trail_points=0, trail_offset=ts_calc)


//if (ConditionExitS)
// strategy.close ("RSIShort")

You might also like