3

First mistake is I took some Version 3 code and pasted it into V4 and have got most of the conversion right but I know have error and I just can't figure out when I try to plot the series, getting the following error for each one:

line 189: Cannot call 'plot' with arguments (series[float], color=const color, style=const string, linewidth=literal integer, title=literal string);

 //@version=4
study(title = "Study1", overlay = true)

> Blockquote


//strategy("Daily ATR Stop", overlay=true, precision=5)

smaFastLkb = input(14, minval=1, title='Fast SMA Period')
smaSlowLkb = input(28, minval=1, title='Slow SMA Period')
atrLkb = input(7, minval=1, title='ATR Stop Period')
atrRes = input("D", type= input.resolution, title='ATR Resolution')
atrMult = input(1, step=0.25, title='ATR Stop Multiplier') 


// Get the indicators
// -------------------
atr = security(syminfo.tickerid , atrRes, atr(atrLkb))
smaFast = sma(close, smaFastLkb)
smaSlow = sma(close, smaSlowLkb)


longCondition = crossover(smaFast, smaSlow)
//if (longCondition)
//    strategy.entry("Long", strategy.long)

shortCondition = crossunder(smaFast, smaSlow)
//if (shortCondition)
//    strategy.entry("Short", strategy.short)

// Calc ATR Stops

float longStop = na
longStop :=  shortCondition ? na : longCondition ? close - (atr * atrMult) : longStop[1]
shortStop = float(na)
shortStop := longCondition ? na : shortCondition ? close + (atr * atrMult) : shortStop[1]
    
// Place the exits
//strategy.exit("Long ATR Stop", "Long", stop=longStop)
//strategy.exit("Short ATR Stop", "Short", stop=shortStop)
    
// Plot the stoplosses
plot(smaFast,   color=color.orange, style = line.style_dashed,  linewidth=2, title='Fast SMA') 
plot(smaFast,   color=color.purple, style = line.style_dashed,  linewidth=2, title='Slow SMA')
plot(longStop,  color=color.red,    style = line.style_dashed,  title='Long ATR Stop')
plot(shortStop, color= color.maroon,style =  line.style_dashed, title='Short ATR Stop')
G.Lebret
  • 2,826
  • 2
  • 16
  • 27
tradeire
  • 31
  • 1
  • 1
  • 2

1 Answers1

3

You were using the style= arguments for line.new():

plot(smaFast,   color=color.orange, style = plot.style_circles,  linewidth=2, title='Fast SMA') 
plot(smaFast,   color=color.purple, style = plot.style_circles,  linewidth=2, title='Slow SMA')
plot(longStop,  color=color.red,    style = plot.style_circles,  title='Long ATR Stop')
plot(shortStop, color= color.maroon,style = plot.style_circles,  title='Short ATR Stop')

When you get a compiler error on a function call, research the function in the refman to ensure you are using it correctly. This is the entry for plot(). There's no dashed style for plot(). You can sorta simulate one using this, which makes the color invisible every second bar:

plot(smaFast,   color=bar_index % 2 == 0 ? color.orange : na, style = plot.style_line,  linewidth=2, title='Fast SMA') 
Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
PineCoders-LucF
  • 8,288
  • 2
  • 12
  • 21