2

I have this code in my account and it works fine but I can not publish it. I'm having a very hard time converting this script to the version 4 or 5.

study(title="Wolf Trade", overlay = true)
adverupgrade = input(defval=true,  title="instagram.com/wolftrade_official")
showsignal   = input(defval=true,  title="Signal")
showStop     = input(defval=false,  title="Stop Loss")
a = input(2, title = "Sensitive 1 Or 2")
RSILENGTH = input(14, title = "14")
RSICENTERLINE = input(52, title = "52")
MACDFASTLENGTH = input(7, title = "7")
MACDSLOWLENGTH = input(12, title = "12")
MACDSIGNALSMOOTHING = input(12, title = "12")
SmoothK = input(3, title = "3")     
SmoothD = input(3, title = "3")
LengthRSI = input(14, title = "14")
LengthStoch = input(14, title = "14")
c = input(10, title="10")
xATR = atr(c)
nLoss = a * xATR
xATRTrailingStop = iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close - nLoss),
                    iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss), 
                        iff(close > nz(xATRTrailingStop[1], 0), close - nLoss, close + nLoss)))
pos =  iff(close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0), 1,
      iff(close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0))) 
color = pos == -200 ? red: pos == 1 ? yellow : yellow 
ema= ema(close,1)
above = crossover(ema,xATRTrailingStop )
below = crossover(xATRTrailingStop,ema)
buy = close > xATRTrailingStop and above 
sell = close < xATRTrailingStop and below
barbuy = close > xATRTrailingStop 
barsell = close < xATRTrailingStop 
plotshape(showsignal and buy, title = "Buy", text = 'Buy', style = shape.triangleup, location = location.belowbar, color= #00bcd4,textcolor = #00bcd4, transp = 0, size = size.tiny)
plotshape(showsignal and sell, title = "Sell", text = 'Sell', style = shape.triangledown, location = location.abovebar, color= #e91c1c,textcolor = #e91c1c, transp = 0, size = size.tiny)
barcolor(showsignal and barbuy? #26a69a:na)
barcolor(showsignal and barsell? #ef5350:na)
alertcondition(showsignal and buy, title='Buy', message='Buy')
alertcondition(showsignal and sell, title='Sell', message='Sell')
Length=input(title="22", type=integer, defval=22)
ATRPeriod=input(title="22", type=integer, defval=22)
Mult=input(title="3", type=integer, defval=3)
RSISource = input(close, title = "close")
SOURCE = input(hlc3, title = "hlc3")
short_stop = lowest(Length)+Mult*atr(ATRPeriod)
long_stop  = highest(Length)-Mult*atr(ATRPeriod)
shortvs=na(shortvs[1]) ? short_stop : iff(close>shortvs[1], short_stop , min(short_stop,shortvs[1]))
longvs=na(longvs[1]) ? long_stop : iff(close<longvs[1], long_stop, max(long_stop,longvs[1]))
longswitch=iff (close>=shortvs[1] and close[1]<shortvs[1] , 1 ,  0)
shortswitch=iff (close<=longvs[1] and close[1]>longvs[1] ,  1 ,  0)
direction= iff(na(direction[1]), 0, 
            iff (direction[1]<=0 and longswitch, 1, 
            iff (direction[1]>=0 and shortswitch, -1, direction[1])))
pc=direction>0?longvs:shortvs
plot(showStop and pc ? pc : na, color=direction>0?#26a69a:#ef5350, title="Stop Lines", style=line, transp=70, linewidth=2)

I tried a lot but I could not do it.

Nick is tired
  • 6,860
  • 20
  • 39
  • 51

1 Answers1

3

It's not a v4 indicator, it's written in Pine v1, hence why it works without specifying the version at the beginning. Migration guides from earlier Pine versions to the newer ones can be found in the User Manual.

Working v5 code:


    //@version=5
    indicator(title='Wolf Trade', overlay=true)
    adverupgrade = input(defval=true, title='instagram.com/wolftrade_official')
    showsignal = input(defval=true, title='Signal')
    showStop = input(defval=false, title='Stop Loss')
    a = input(2, title='Sensitive 1 Or 2')
    RSILENGTH = input(14, title='14')
    RSICENTERLINE = input(52, title='52')
    MACDFASTLENGTH = input(7, title='7')
    MACDSLOWLENGTH = input(12, title='12')
    MACDSIGNALSMOOTHING = input(12, title='12')
    SmoothK = input(3, title='3')
    SmoothD = input(3, title='3')
    LengthRSI = input(14, title='14')
    LengthStoch = input(14, title='14')
    c = input(10, title='10')
    xATR = ta.atr(c)
    nLoss = a * xATR
    float xATRTrailingStop = na
    iff_1 = close > nz(xATRTrailingStop[1], 0) ? close - nLoss : close + nLoss
    iff_2 = close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0) ? math.min(nz(xATRTrailingStop[1]), close + nLoss) : iff_1
    xATRTrailingStop := close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0) ? math.max(nz(xATRTrailingStop[1]), close - nLoss) : iff_2
    float pos = na
    iff_3 = close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0) ? -1 : nz(pos[1], 0)
    pos := close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0) ? 1 : iff_3
    color = pos == -200 ? color.red : pos == 1 ? color.yellow : color.yellow
    ema = ta.ema(close, 1)
    above = ta.crossover(ema, xATRTrailingStop)
    below = ta.crossover(xATRTrailingStop, ema)
    buy = close > xATRTrailingStop and above
    sell = close < xATRTrailingStop and below
    barbuy = close > xATRTrailingStop
    barsell = close < xATRTrailingStop
    plotshape(showsignal and buy, title='Buy', text='Buy', style=shape.triangleup, location=location.belowbar, color=color.new(#00bcd4, 0), textcolor=color.new(#00bcd4, 0), size=size.tiny)
    plotshape(showsignal and sell, title='Sell', text='Sell', style=shape.triangledown, location=location.abovebar, color=color.new(#e91c1c, 0), textcolor=color.new(#e91c1c, 0), size=size.tiny)
    barcolor(showsignal and barbuy ? #26a69a : na)
    barcolor(showsignal and barsell ? #ef5350 : na)
    alertcondition(showsignal and buy, title='Buy', message='Buy')
    alertcondition(showsignal and sell, title='Sell', message='Sell')
    Length = input(title='22', defval=22)
    ATRPeriod = input(title='22', defval=22)
    Mult = input(title='3', defval=3)
    RSISource = input(close, title='close')
    SOURCE = input(hlc3, title='hlc3')
    short_stop = ta.lowest(Length) + Mult * ta.atr(ATRPeriod)
    long_stop = ta.highest(Length) - Mult * ta.atr(ATRPeriod)
    float shortvs = na
    float longvs = na
    shortvs := na(shortvs[1]) ? short_stop : close > shortvs[1] ? short_stop : math.min(short_stop, shortvs[1])
    longvs := na(longvs[1]) ? long_stop : close < longvs[1] ? long_stop : math.max(long_stop, longvs[1])
    longswitch = close >= shortvs[1] and close[1] < shortvs[1] ? 1 : 0
    shortswitch = close <= longvs[1] and close[1] > longvs[1] ? 1 : 0
    float direction = na
    iff_4 = direction[1] >= 0 and shortswitch ? -1 : direction[1]
    iff_5 = direction[1] <= 0 and longswitch ? 1 : iff_4
    direction := na(direction[1]) ? 0 : iff_5
    pc = direction > 0 ? longvs : shortvs
    plot(showStop and pc ? pc : na, color=direction > 0 ? color.new(#26a69a, 70) : color.new(#ef5350, 70), title='Stop Lines', style=plot.style_line, linewidth=2)

Yuvi
  • 419
  • 7
  • 12
beeholder
  • 1,444
  • 1
  • 3
  • 6