I'm trying to convert a TradingView strategy into a study with alerts. I'm relatively new to this idea. I've created plots so that the long and short entries show up on the chart, and then I created alerts that corresponded to those entries. But my issue comes up here, because I can't find out where to create the corresponding exit alerts.
//@version=3
study("Generalized SSL Backtest w/ TSSL", shorttitle="Judgement", overlay=true)
lb = input(10, title="Lb", minval=1)
maType = input(type=string, defval="SMA", title="MA Type", options=["SMA","EMA","HMA","McG","WMA","Tenkan"])
fixedSL = input(title="SL Activation", defval=300)
trailSL = input(title="SL Trigger", defval=1)
fixedTP = input(title="TP Activation", defval=150)
trailTP = input(title="TP Trigger", defval=1)
ma(t,sig,len) =>
sss=na
if t =="SMA"
sss := sma(sig,len)
if t == "EMA"
sss := ema(sig,len)
if t == "HMA"
sss := hma(sig,len)
if t == "McG" // Mc Ginley
sss := mcg(sig,len)
if t == "Tenkan"
sss := tenkan(sig,len)
if t == "WMA"
sss := wma(sig,len)
sss
base(mah, mal) =>
bbb = na
inChannel = close<mah and close>mal
belowChannel = close<mah and close<mal
bbb := inChannel? bbb[1]: belowChannel? -1: 1
uuu = bbb==1? mal: mah
ddd = bbb==1? mah: mal
[uuu, ddd]
maH = ma(maType, high, lb)
maL = ma(maType, low, lb)
[up, dn] = base(maH,maL)
plot(up, title="High MA", color=lime, linewidth=3)
plot(dn, title="Low MA", color=orange, linewidth=3)
long = crossover(dn,up)
short = crossover(up,dn)
// === STRATEGY - LONG POSITION EXECUTION ===
//strategy.entry("Long", strategy.long, when= long and startTimeOk())
//strategy.exit("Exit", qty_percent = 100, loss=fixedSL, trail_offset=trailTP, trail_points=fixedTP)
//strategy.exit("Exit", when= short)
// === STRATEGY - SHORT POSITION EXECUTION ===
//strategy.entry("Short", strategy.short, when= short and startTimeOk())
//strategy.exit("Exit", qty_percent = 100, loss=fixedSL, trail_offset=trailTP, trail_points=fixedTP)
//strategy.exit("Exit", when= long)
plotchar(long, char = "Long", color = green)
plotchar(short, char = "Short", color = red)
alertcondition(long, "ENTRY LONG", "ENTRY LONG")
alertcondition(short, "ENTRY SHORT", "ENTRY SHORT")
Any help would be appreciated.