0

I am new to TradingView Pine scripting. I am working on some study/strategy but currently seeking for help with a pine script which is on version 2 right now but I am trying convert it into Version 4 and is having so many compilation errors.

Below is the complete script I am trying to convert from V2 to V2 and error I am facing.

Script

//@version=4
//Trend Trading Study by MSM *Sanjay.r* Trend Trading Indicator
study("MystockMoney Trend Trading Tool 1.0", overlay=true)
res = input(title="Main MSM Time Frame", type=resolution, defval="120")
Factor=input(1, minval=1,maxval = 100)
Pd=input(1, minval=1,maxval = 100)
tp = input(500,title="Take Profit")
sl = input(200,title="Stop Loss")
//Plots VWAP and MVWAP for intraday trading. Useful to avoid whipsaws
//study("VWAP MVWAP with pivot points", overlay = true)
avlen = input(50) 
color1 = blue
color2 = black
mvwap = ema(vwap,avlen)
plot(vwap,linewidth = 2,style = circles, color = color2)
plot(mvwap,color= color1)
Up=hl2-(Factor*atr(Pd))
Dn=hl2+(Factor*atr(Pd))
MUp=security(tickerid,res,hl2-(Factor*atr(Pd)))
MDn=security(tickerid,res,hl2+(Factor*atr(Pd)))
Mclose=security(tickerid,res,close)
TrendUp=close[1]>TrendUp[1]? max(Up,TrendUp[1]) : Up
TrendDown=close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn
MTrendUp=Mclose[1]>MTrendUp[1]? max(MUp,MTrendUp[1]) : MUp
MTrendDown=Mclose[1]<MTrendDown[1]? min(MDn,MTrendDown[1]) : MDn
Trend = close > TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1],1)
Tsl = Trend==1? TrendUp: TrendDown
MTrend = Mclose > MTrendDown[1] ? 1: Mclose< MTrendUp[1]? -1: nz(MTrend[1],1)
MTsl = MTrend==1? MTrendUp: MTrendDown
linecolor = Trend == 1 ? green : red
plot(Tsl, color = linecolor , style = line , linewidth = 2,title = "MSM")
Mlinecolor = MTrend == 1 ? blue : orange
plot(MTsl, color = Mlinecolor , style = line , linewidth = 2,title = "Main MSM")
plotshape(cross(close,Tsl) and close>Tsl , "Up Arrow", shape.triangleup,location.belowbar,green,0,0)
plotshape(cross(Tsl,close) and close<Tsl , "Down Arrow", shape.triangledown , location.abovebar, red,0,0)
up = Trend == 1 and Trend[1] == -1 and MTrend == 1 
down = Trend == -1 and Trend[1] == 1 and MTrend == -1 
plotarrow(up ? Trend : na, title="Up Entry Arrow", colorup=lime, maxheight=60, minheight=50, transp=0)
plotarrow(down ? Trend : na, title="Down Entry Arrow", colordown=red, maxheight=60, minheight=50, transp=0)
golong = Trend == 1 and Trend[1] == -1 and MTrend == 1 
goshort = Trend == -1 and Trend[1] == 1 and MTrend == -1 
length=input(21, "length", minval=1)
avrg=sma(volume,length)
vold1 = volume > avrg*1.5 and close<open
vold2 = volume >= avrg*0.5 and volume<=avrg*1.5 and close<open
vold3 = volume < avrg *0.5 and close<open
volu1 = volume > avrg*1.5 and close>open
volu2 = volume >= avrg*0.5 and volume<=avrg*1.5 and close>open
volu3 = volume< avrg*0.5 and close>open
cold1=#800000
cold2=#FF0000
cold3=orange
colu1=#006400
colu2=lime
colu3=#7FFFD4
color = vold1 ? cold1 : vold2 ? cold2 : vold3 ? cold3 : volu1 ? colu1 : volu2 ? colu2 : volu3 ? colu3 : na
barcolor(color)
//Code merged for another indicator
sd = input(true, title="Show Daily Pivots?")
//Pivot Range Calculations - Mark Fisher
pivot = (high + low + close ) / 3.0 
bc = (high + low ) / 2.0 
tc = (pivot - bc) + pivot
r1 = (pivot * 2) - low
s1 = (pivot * 2) - high
r2 = pivot + (high - low)
s2 = pivot - (high - low)
r3 = r1 + (high - low)
s3 = s1 - (high - low)
r4 = r3 + (r2 - r1)
s4 = s3 - (s1 - s2)
//Daily Pivot Range 
dtime_pivot = security(tickerid, 'D', pivot[1]) 
dtime_bc = security(tickerid, 'D', bc[1]) 
dtime_tc = security(tickerid, 'D', tc[1]) 
dtime_r1 = security(tickerid, 'D', r1[1])
dtime_r2 = security(tickerid, 'D', r2[1])
dtime_r3 = security(tickerid, 'D', r3[1])
dtime_r4 = security(tickerid, 'D', r4[1])
dtime_s1 = security(tickerid, 'D', s1[1])
dtime_s2 = security(tickerid, 'D', s2[1])
dtime_s3 = security(tickerid, 'D', s3[1])
dtime_s4 = security(tickerid, 'D', s4[1])
offs_daily = 0 
plot(sd and dtime_pivot ? dtime_pivot : na, title="Daily Pivot",style=circles, color=blue,linewidth=3) 
plot(sd and dtime_bc ? dtime_bc : na, title="Daily BC",style=circles, color=blue,linewidth=3)
plot(sd and dtime_tc ? dtime_tc : na, title="Daily TC",style=circles, color=blue,linewidth=3)
plot(sd and dtime_r1 ? dtime_r1 : na, title="Daily r1",style=circles, color=green,linewidth=3)
plot(sd and dtime_s1 ? dtime_s1 : na, title="Daily s1",style=circles, color=red,linewidth=3)

Errors after compiling above script

Processing script...
line 5: Undeclared identifier 'resolution';
line 18: Undeclared identifier 'blue';
line 19: Undeclared identifier 'black';
line 21: Undeclared identifier 'circles';
line 21: Undeclared identifier 'color2';
line 22: Undeclared identifier 'color1';
line 26: Undeclared identifier 'res';
line 27: Undeclared identifier 'res';
line 29: Undeclared identifier 'res';
line 31: Undeclared identifier 'TrendUp';
line 32: Undeclared identifier 'TrendDown';
line 34: Undeclared identifier 'Mclose';
line 34: Undeclared identifier 'MTrendUp';
line 34: Undeclared identifier 'MUp';
line 35: Undeclared identifier 'Mclose';
line 35: Undeclared identifier 'MTrendDown';
line 35: Undeclared identifier 'MDn';
line 37: Undeclared identifier 'TrendDown';
line 37: Undeclared identifier 'TrendUp';
line 37: Undeclared identifier 'Trend';
line 38: Undeclared identifier 'Trend';
line 38: Undeclared identifier 'TrendUp';
line 38: Undeclared identifier 'TrendDown';
line 40: Undeclared identifier 'Mclose';
line 40: Undeclared identifier 'MTrendDown';
line 40: Undeclared identifier 'MTrendUp';
line 40: Undeclared identifier 'MTrend';
line 41: Undeclared identifier 'MTrend';
line 41: Undeclared identifier 'MTrendUp';
line 41: Undeclared identifier 'MTrendDown';
line 43: Undeclared identifier 'Trend';
line 43: Undeclared identifier 'green';
line 43: Undeclared identifier 'red';
line 44: Undeclared identifier 'Tsl';
line 44: Undeclared identifier 'linecolor';
line 44: Undeclared identifier 'line';
line 46: Undeclared identifier 'MTrend';
line 46: Undeclared identifier 'blue';
line 46: Undeclared identifier 'orange';
line 47: Undeclared identifier 'MTsl';
line 47: Undeclared identifier 'Mlinecolor';
line 47: Undeclared identifier 'line';
line 49: Undeclared identifier 'Tsl';
line 49: Undeclared identifier 'green';
line 50: Undeclared identifier 'Tsl';
line 50: Undeclared identifier 'red';
line 52: Undeclared identifier 'Trend';
line 52: Undeclared identifier 'MTrend';
line 53: Undeclared identifier 'Trend';
line 53: Undeclared identifier 'MTrend';
line 54: Undeclared identifier 'up';
line 54: Undeclared identifier 'Trend';
line 54: Undeclared identifier 'lime';
line 55: Undeclared identifier 'down';
line 55: Undeclared identifier 'Trend';
line 55: Undeclared identifier 'red';
line 58: Undeclared identifier 'Trend';
line 58: Undeclared identifier 'MTrend';
line 59: Undeclared identifier 'Trend';
line 59: Undeclared identifier 'MTrend';
line 76: Undeclared identifier 'orange';
line 80: Undeclared identifier 'lime';
line 84: Undeclared identifier 'cold3';
line 84: Undeclared identifier 'colu2';
line 86: Undeclared identifier 'color';
line 105: Cannot call 'security' with arguments (const integer, literal string, series[float]); available overloads: security(string, string, series[float], const bool, const bool, string) => series[float]; security(string, string, series[integer], const bool, const bool, string) => series[integer]; security(string, string, series[bool], const bool, const bool, string) => series[bool]; security(string, string, series[color], const bool, const bool, string) => series[color]; security(string, string, <arg_expr_type>, const bool, const bool, string) => <arg_expr_type>;
line 106: Cannot call 'security' with arguments (const integer, literal string, series[float]); available overloads: security(string, string, series[float], const bool, const bool, string) => series[float]; security(string, string, series[integer], const bool, const bool, string) => series[integer]; security(string, string, series[bool], const bool, const bool, string) => series[bool]; security(string, string, series[color], const bool, const bool, string) => series[color]; security(string, string, <arg_expr_type>, const bool, const bool, string) => <arg_expr_type>;
line 107: Cannot call 'security' with arguments (const integer, literal string, series[float]); available overloads: security(string, string, series[float], const bool, const bool, string) => series[float]; security(string, string, series[integer], const bool, const bool, string) => series[integer]; security(string, string, series[bool], const bool, const bool, string) => series[bool]; security(string, string, series[color], const bool, const bool, string) => series[color]; security(string, string, <arg_expr_type>, const bool, const bool, string) => <arg_expr_type>;
line 108: Cannot call 'security' with arguments (const integer, literal string, series[float]); available overloads: security(string, string, series[float], const bool, const bool, string) => series[float]; security(string, string, series[integer], const bool, const bool, string) => series[integer]; security(string, string, series[bool], const bool, const bool, string) => series[bool]; security(string, string, series[color], const bool, const bool, string) => series[color]; security(string, string, <arg_expr_type>, const bool, const bool, string) => <arg_expr_type>;
line 109: Cannot call 'security' with arguments (const integer, literal string, series[float]); available overloads: security(string, string, series[float], const bool, const bool, string) => series[float]; security(string, string, series[integer], const bool, const bool, string) => series[integer]; security(string, string, series[bool], const bool, const bool, string) => series[bool]; security(string, string, series[color], const bool, const bool, string) => series[color]; security(string, string, <arg_expr_type>, const bool, const bool, string) => <arg_expr_type>;
line 110: Cannot call 'security' with arguments (const integer, literal string, series[float]); available overloads: security(string, string, series[float], const bool, const bool, string) => series[float]; security(string, string, series[integer], const bool, const bool, string) => series[integer]; security(string, string, series[bool], const bool, const bool, string) => series[bool]; security(string, string, series[color], const bool, const bool, string) => series[color]; security(string, string, <arg_expr_type>, const bool, const bool, string) => <arg_expr_type>;
line 111: Cannot call 'security' with arguments (const integer, literal string, series[float]); available overloads: security(string, string, series[float], const bool, const bool, string) => series[float]; security(string, string, series[integer], const bool, const bool, string) => series[integer]; security(string, string, series[bool], const bool, const bool, string) => series[bool]; security(string, string, series[color], const bool, const bool, string) => series[color]; security(string, string, <arg_expr_type>, const bool, const bool, string) => <arg_expr_type>;
line 112: Cannot call 'security' with arguments (const integer, literal string, series[float]); available overloads: security(string, string, series[float], const bool, const bool, string) => series[float]; security(string, string, series[integer], const bool, const bool, string) => series[integer]; security(string, string, series[bool], const bool, const bool, string) => series[bool]; security(string, string, series[color], const bool, const bool, string) => series[color]; security(string, string, <arg_expr_type>, const bool, const bool, string) => <arg_expr_type>;
line 113: Cannot call 'security' with arguments (const integer, literal string, series[float]); available overloads: security(string, string, series[float], const bool, const bool, string) => series[float]; security(string, string, series[integer], const bool, const bool, string) => series[integer]; security(string, string, series[bool], const bool, const bool, string) => series[bool]; security(string, string, series[color], const bool, const bool, string) => series[color]; security(string, string, <arg_expr_type>, const bool, const bool, string) => <arg_expr_type>;
line 114: Cannot call 'security' with arguments (const integer, literal string, series[float]); available overloads: security(string, string, series[float], const bool, const bool, string) => series[float]; security(string, string, series[integer], const bool, const bool, string) => series[integer]; security(string, string, series[bool], const bool, const bool, string) => series[bool]; security(string, string, series[color], const bool, const bool, string) => series[color]; security(string, string, <arg_expr_type>, const bool, const bool, string) => <arg_expr_type>;
line 115: Cannot call 'security' with arguments (const integer, literal string, series[float]); available overloads: security(string, string, series[float], const bool, const bool, string) => series[float]; security(string, string, series[integer], const bool, const bool, string) => series[integer]; security(string, string, series[bool], const bool, const bool, string) => series[bool]; security(string, string, series[color], const bool, const bool, string) => series[color]; security(string, string, <arg_expr_type>, const bool, const bool, string) => <arg_expr_type>;
line 119: Undeclared identifier 'dtime_pivot';
line 119: Undeclared identifier 'circles';
line 119: Undeclared identifier 'blue';
line 120: Undeclared identifier 'dtime_bc';
line 120: Undeclared identifier 'circles';
line 120: Undeclared identifier 'blue';
line 121: Undeclared identifier 'dtime_tc';
line 121: Undeclared identifier 'circles';
line 121: Undeclared identifier 'blue';
line 122: Undeclared identifier 'dtime_r1';
line 122: Undeclared identifier 'circles';
line 122: Undeclared identifier 'green';
line 123: Undeclared identifier 'dtime_s1';
line 123: Undeclared identifier 'circles';
line 123: Undeclared identifier 'red'
Script 'MystockMoney Trend Trading Tool 1.0' has been saved
Bjorn Mistiaen
6,9553 gold badges24 silver badges47 bronze badges
asked Dec 27, 2020 at 9:11

1 Answer 1

1

Converted to Pine v4

//@version=4
//Trend Trading Study by MSM *Sanjay.r* Trend Trading Indicator
study("MystockMoney Trend Trading Tool 1.0", overlay=true)
res = input(title="Main MSM Time Frame", type=input.resolution, defval="120")
Factor = input(1, minval = 1, maxval = 100)
Pd = input(1, minval = 1, maxval = 100)
tp = input(500, title="Take Profit")
sl = input(200, title="Stop Loss")
avlen = input(50) 
var float TrendUp = na
var float TrendDown = na
var float MTrendUp = na
var float MTrendDown = na
var float Trend = na
var float Tsl = na
var float MTrend = na
var float MTsl = na
var color linecolor = na
//Plots VWAP and MVWAP for intraday trading. Useful to avoid whipsaws
//study("VWAP MVWAP with pivot points", overlay = true)
color1 = color.blue
color2 = color.black
mvwap = ema(vwap,avlen)
plot(vwap, linewidth = 2, style = plot.style_circles, color = color2)
plot(mvwap, color= color1)
delta = (Factor*atr(Pd))
Up = hl2 - delta
Dn = hl2 + delta
MUp = security(syminfo.tickerid, res, Up)
MDn = security(syminfo.tickerid, res, Dn)
Mclose = security(syminfo.tickerid, res, close)
TrendUp := close[1]>TrendUp[1]? max(Up,TrendUp[1]) : Up
TrendDown := close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn
MTrendUp := Mclose[1]>MTrendUp[1]? max(MUp,MTrendUp[1]) : MUp
MTrendDown := Mclose[1]<MTrendDown[1]? min(MDn,MTrendDown[1]) : MDn
Trend := close > TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1],1)
Tsl := Trend==1? TrendUp: TrendDown
MTrend := Mclose > MTrendDown[1] ? 1: Mclose< MTrendUp[1]? -1: nz(MTrend[1],1)
MTsl := MTrend==1? MTrendUp: MTrendDown
linecolor := Trend == 1 ? color.green : color.red
plot(Tsl, color = linecolor , style = plot.style_line , linewidth = 2, title = "MSM")
Mlinecolor = MTrend == 1 ? color.blue : color.orange
plot(MTsl, color = Mlinecolor , style = plot.style_line , linewidth = 2,title = "Main MSM")
plotshape(cross(close,Tsl) and close>Tsl , "Up Arrow", shape.triangleup,location.belowbar, color.green, 0, 0)
plotshape(cross(Tsl,close) and close<Tsl , "Down Arrow", shape.triangledown , location.abovebar, color.red, 0, 0)
up = Trend == 1 and Trend[1] == -1 and MTrend == 1 
down = Trend == -1 and Trend[1] == 1 and MTrend == -1 
plotarrow(up ? Trend : na, title="Up Entry Arrow", colorup=color.lime, maxheight=60, minheight=50, transp=0)
plotarrow(down ? Trend : na, title="Down Entry Arrow", colordown=color.red, maxheight=60, minheight=50, transp=0)
golong = up
goshort = down
length = input(21, "length", minval=1)
avrg = sma(volume, length)
vold1 = volume > avrg*1.5 and close < open
vold2 = volume >= avrg*0.5 and volume <= avrg*1.5 and close < open
vold3 = volume < avrg*0.5 and close < open
volu1 = volume > avrg*1.5 and close > open
volu2 = volume >= avrg*0.5 and volume <= avrg*1.5 and close > open
volu3 = volume < avrg*0.5 and close > open
cold1 = #800000
cold2 = #FF0000
cold3 = color.orange
colu1 = #006400
colu2 = color.lime
colu3 = #7FFFD4
bcolor = vold1 ? cold1 : vold2 ? cold2 : vold3 ? cold3 : volu1 ? colu1 : volu2 ? colu2 : volu3 ? colu3 : na
barcolor(bcolor)
//Code merged for another indicator
sd = input(true, title="Show Daily Pivots?")
//Pivot Range Calculations - Mark Fisher
pivot = hlc3
bc = hl2
tc = (pivot - bc) + pivot
r1 = (pivot * 2) - low
s1 = (pivot * 2) - high
r2 = pivot + (high - low)
s2 = pivot - (high - low)
r3 = r1 + (high - low)
s3 = s1 - (high - low)
r4 = r3 + (r2 - r1)
s4 = s3 - (s1 - s2)
//Daily Pivot Range 
dtime_pivot = security(syminfo.tickerid, 'D', pivot[1]) 
dtime_bc = security(syminfo.tickerid, 'D', bc[1]) 
dtime_tc = security(syminfo.tickerid, 'D', tc[1]) 
dtime_r1 = security(syminfo.tickerid, 'D', r1[1])
dtime_r2 = security(syminfo.tickerid, 'D', r2[1])
dtime_r3 = security(syminfo.tickerid, 'D', r3[1])
dtime_r4 = security(syminfo.tickerid, 'D', r4[1])
dtime_s1 = security(syminfo.tickerid, 'D', s1[1])
dtime_s2 = security(syminfo.tickerid, 'D', s2[1])
dtime_s3 = security(syminfo.tickerid, 'D', s3[1])
dtime_s4 = security(syminfo.tickerid, 'D', s4[1])
offs_daily = 0 
plot(sd and dtime_pivot ? dtime_pivot : na, title="Daily Pivot", style=plot.style_circles, color=color.blue, linewidth=3) 
plot(sd and dtime_bc ? dtime_bc : na, title="Daily BC", style=plot.style_circles, color=color.blue, linewidth=3)
plot(sd and dtime_tc ? dtime_tc : na, title="Daily TC", style=plot.style_circles, color=color.blue, linewidth=3)
plot(sd and dtime_r1 ? dtime_r1 : na, title="Daily r1", style=plot.style_circles, color=color.green, linewidth=3)
plot(sd and dtime_s1 ? dtime_s1 : na, title="Daily s1", style=plot.style_circles, color=color.red, linewidth=3)
answered Dec 28, 2020 at 11:45
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.