I made an strategy using Pinescript. Code is well started without error message. but plot of trailingstop line and barcolor function are not visible. I cannot understand why…
code is here:
//@version=5
strategy(title="UT Bot Strategy + STC", overlay = true)
// Inputs
a = input.float(1, title = "Key Vaule. 'This changes the sensitivity'")
c = input(10, title = "ATR Period")
h = input(false, title = "Signals from Heikin Ashi Candles")
xATR = ta.atr(c)
nLoss = a * xATR
src = h ? request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close, barmerge.gaps_off, barmerge.lookahead_off) : close
var float xATRTrailingStop = na
if src > nz(xATRTrailingStop[1],0) and src[1] > nz(xATRTrailingStop[1],0)
xATRTrailingStop := math.max(xATRTrailingStop[1],src-nLoss)
else if src < nz(xATRTrailingStop[1],0) and src[1] < nz(xATRTrailingStop[1],0)
xATRTrailingStop := math.min(xATRTrailingStop[1],src+nLoss)
else if src > xATRTrailingStop[1]
src-nLoss
else
src+nLoss
var color trailingstop_color = na
if close > xATRTrailingStop
trailingstop_color:=color.red
else
trailingstop_color:=color.green
plot(xATRTrailingStop,color=trailingstop_color,linewidth=2)
ema = ta.ema(src,1)
above = ta.crossover(ema, xATRTrailingStop)
below = ta.crossover(xATRTrailingStop, ema)
buy = src > xATRTrailingStop and above
sell = src < xATRTrailingStop and below
barbuy = src > xATRTrailingStop
barsell = src < xATRTrailingStop
plotshape(buy, title = "Buy", text = 'Buy', style = shape.labelup, location = location.belowbar, color= color.green, textcolor=color.white, size = size.tiny)
plotshape(sell, title = "Sell", text = 'Sell', style = shape.labeldown, location = location.abovebar, color= color.red, textcolor = color.white, size = size.tiny)
barcolor(barbuy ? color.green : na)
barcolor(barsell ? color.red : na)
EEEEEE = input(12, 'Length')
BBBB = input(26, 'FastLength')
BBBBB = input(50, 'SlowLength')
AAAA(BBB, BBBB, BBBBB) =>
fastMA = ta.ema(BBB, BBBB)
slowMA = ta.ema(BBB, BBBBB)
AAAA = fastMA - slowMA
AAAA
AAAAA(EEEEEE, BBBB, BBBBB) =>
AAA = input(0.5)
var CCCCC = 0.0
var DDD = 0.0
var DDDDDD = 0.0
var EEEEE = 0.0
BBBBBB = AAAA(close, BBBB, BBBBB)
CCC = ta.lowest(BBBBBB, EEEEEE)
CCCC = ta.highest(BBBBBB, EEEEEE) - CCC
CCCCC := CCCC > 0 ? (BBBBBB - CCC) / CCCC * 100 : nz(CCCCC[1])
DDD := na(DDD[1]) ? CCCCC : DDD[1] + AAA * (CCCCC - DDD[1])
DDDD = ta.lowest(DDD, EEEEEE)
DDDDD = ta.highest(DDD, EEEEEE) - DDDD
DDDDDD := DDDDD > 0 ? (DDD - DDDD) / DDDDD * 100 : nz(DDDDDD[1])
EEEEE := na(EEEEE[1]) ? DDDDDD : EEEEE[1] + AAA * (DDDDDD - EEEEE[1])
EEEEE
mAAAAA = AAAAA(EEEEEE, BBBB, BBBBB)
if buy and mAAAAA <=25
strategy.entry("Long",strategy.long,10)
else if mAAAAA >= 75
strategy.close("Long")
else if close <= strategy.opentrades.entry_price(strategy.opentrades-1)-nLoss
strategy.close("Long")
if sell and mAAAAA >= 75
strategy.entry("Short",strategy.short,10)
else if mAAAAA <= 25
strategy.close("Short")
else if close >= strategy.opentrades.entry_price(strategy.opentrades-1)+nLoss
strategy.close("Short")
This strategy consists of two parts: breakout of trailingstop(finding strong trend) and oscillator(for filtering).
Can you help me? 🙂
If you found correct code, then let me know.
New contributor
이하민 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.