Page 1 of 1

Convert Pine script 2 to 5

Posted: Sat Sep 16, 2023 2:30 am
by anehate563
Hello, I've been attempting to enhance this outdated script in version 2, but it's proven quite challenging because of the older version. My primary goal is to address the repainting issue, but I'm struggling to upgrade the script to version 5, and I'm uncertain about the steps required to achieve that. I encounter numerous errors when attempting to do so.

Here is the code: Any help would be appreciated

Code: Select all

//@version=2
study("Trend Signal 2", overlay=true)
RISK= input(title="RISK", type=integer, defval=14)
value10=3+RISK*2
value11=value10
x1=67+RISK
x2=33-RISK

range(length) =>
    sum = 0
    for i = 1 to length-1
        sum := sum + abs(high[i]-low[i])
    sum / length

MRO1(length, range) =>
	true_count = 0
	counter = 0
	for i = 1 to length-1
		x = if abs(open[i]-close[i+1]) >= range*2.0
			true_count := true_count + 1
			counter = i
			break
	mro = if true_count >= 1
		counter
	else
		-1	
	mro

MRO2(length, range) =>
	true_count = 0
	counter = 0
	for i = 1 to length-1
		x = if abs(close[i+3]-close[i]) >= range*4.6
			true_count := true_count + 1
			counter = i
			break
	mro = if true_count >= 1
		counter
	else
		-1	
	mro

wpr(length) =>
    upper = highest(length)
    lower = lowest(length)
    out = 100 * (close - upper) / (upper - lower)
    out
	
rng = range(10)
mro1=MRO1(10,rng)
mro2=MRO2(7,rng)

rez = if mro1>-1
	3
else
	value10
	
value11:=rez
rez1 = if mro2>-1
	4
else
	value10
value11:=rez1

value2 = 100-abs(wpr(value10))

Table_value2=value2

notset=false
ii1 = 1
for i1 = 1 to 300
    if ((Table_value2[i1] < x2 or Table_value2[i1] > x1) and notset==false)
        notset:=true
        ii1 := i1

z=Table_value2[ii1]
up = if value2 < x2
    if Table_value2[ii1] > x1
        ii1
	else
	    0
else
    0


plotshape(up, style=shape.labeldown, location=location.abovebar, size=size.normal, color=aqua, text="Sell")

dn = if value2 > x1
    if Table_value2[ii1] < x2
        ii1
	else
	    0
else
    0


plotshape(dn, style=shape.labelup, location=location.belowbar, size=size.normal, color=aqua, text="Buy")



Re: Convert Pine script 2 to 5

Posted: Wed Sep 20, 2023 2:49 am
by Steve Burman
Here's the V5 version

//@version=5
indicator("Trend Signal 2", overlay=true)
RISK= input.int(title="RISK", defval=14)
value10=3+RISK*2
value11=value10
x1=67+RISK
x2=33-RISK

Range(length) =>
var float sum = 0
for i = 1 to length-1
sum := sum + math.abs(high-low)
sum / length

MRO1(length, Range) =>
true_count = 0
counter = 0
for i = 1 to length-1
if math.abs(open-close[i+1]) >= Range*2.0
true_count := true_count + 1
counter := i
break
mro = if true_count >= 1
counter
else
-1
mro

MRO2(length, Range) =>
true_count = 0
counter = 0
for i = 1 to length-1
if math.abs(close[i+3]-close) >= Range*4.6
true_count := true_count + 1
counter := i
break
mro = if true_count >= 1
counter
else
-1
mro

wpr(length) =>
upper = ta.highest(length)
lower = ta.lowest(length)
out = 100 * (close - upper) / (upper - lower)
out

rng = Range(10)
mro1=MRO1(10,rng)
mro2=MRO2(7,rng)

rez = if mro1>-1
3
else
value10

value11:=rez
rez1 = if mro2>-1
4
else
value10
value11:=rez1

value2 = 100-math.abs(wpr(value10))

Table_value2=value2

notset=false
ii1 = 1
for i1 = 1 to 300
if ((Table_value2[i1] < x2 or Table_value2[i1] > x1) and notset==false)
notset:=true
ii1 := i1

z=Table_value2[ii1]
up = if value2 < x2
if Table_value2[ii1] > x1
ii1
else
0
else
0


plotshape(up, style=shape.labeldown, location=location.abovebar, size=size.normal, color=color.aqua, text="Sell")

dn = if value2 > x1
if Table_value2[ii1] < x2
ii1
else
0
else
0


plotshape(dn, style=shape.labelup, location=location.belowbar, size=size.normal, color=color.aqua, text="Buy")

Re: Convert Pine script 2 to 5

Posted: Wed Sep 20, 2023 2:50 am
by Steve Burman
Unfortunately pinescripters.net has lost all indentations