//@version=4
study("Strategy with SL/PT", overlay = true)
pos = 0
long_entry = nz(pos[1]) == 0 and crossover(sma(close, 10), sma(close, 30))
sl_level = 0.0
sl_level := long_entry[1] ? open * 0.99 : nz(sl_level[1])
pt_level = 0.0
pt_level := long_entry[1] ? open * 1.02 : nz(pt_level[1])
sl_exit = nz(pos[1]) == 1 and crossunder(low, sl_level)
pt_exit = nz(pos[1]) == 1 and crossover(high, pt_level)
pos := long_entry ? 1 :
nz(pos[1] == 1) and (sl_exit or pt_exit) ? 0 :
nz(pos[1])
plot(sl_level, color = color.red)
plot(pt_level, color = color.green)
plotshape(long_entry, text = "Long")
plotshape(sl_exit, text = "SL")
plotshape(pt_exit, text = "PT")
//if (long_entry)
// strategy.entry("Long", true)
// strategy.exit("Long", loss = close / 100 / syminfo.mintick, profit = 2 * close / 100 / syminfo.mintick)
alertcondition(long_entry, "Long", "Long")
alertcondition(sl_exit, "PT", "PT")
alertcondition(pt_exit, "SL", "SL")
Hi, I need help to create alert for my tp and sl on my strategy. This code doesn’t work for some reason. Can you help me?