Re: Converting tradingview script to mt4 indicator

2
Hello coders! Request to convert Tradingview script to MT4. Thank you!

// @version=2

// Title: "LuxOption".
// Revision: 2 (most likely final unless I find some serious issues)
// Author: LuxOption
//
// Description / Usage:
//
// - Three stacked SMA based Bollinger Bands designed just to give you a quick visual on the pressure/heat of movement.
// - Set inner band as you would expect, then set your preferred multiplier increment for the additional outer 2 bands.
// - Option to use EMA as alternative basis, rather than SMA.
// - Breakout indication shapes, which have their own multiplier seperate from the BB's; but still tied to same length/period.
// - Both high and low breakouts each have seperate selectable source options.
//
// r2 changes:
//
// - cleaned and tightened up code a bit.
// - revised title tags for customisation, to make things a little clearer.
// - dropped [JR] tag, didn't realise someone else was using that.. less potential confusion between authors. Sorry other [JR]!

study(shorttitle="LuxOption", title="Multi BB Heat Vis - SMA/EMA/Breakout - r2", overlay=true)

// Inputs
bb_useEma = input(false, title="Use EMA Basis?")
bb_length = input(20, minval=1, title="Bollinger Length")
bb_source = input(open, title="Bollinger Source")
bb_mult = input(2.0, title="Base Multiplier", minval=0.1, maxval=25)
bb_multInc = input(0.5, title="Multiplier Increment", minval=0.1, maxval=25)
bo_mult = input(3.5, title="Breakout Multiplier", minval=0.5, maxval=25)
bo_hSource = input(high, title="High Break Source")
bo_lSource = input(low, title="Low Break Source")

bb_basis = bb_useEma ? ema(bb_source, bb_length) : sma(bb_source, bb_length)

// Deviation
bb_stdDev = stdev(bb_source, bb_length)
bb_devBase = bb_mult * bb_stdDev
bb_devInc1 = (bb_mult + bb_multInc) * bb_stdDev
bb_devInc2 = (bb_mult + (bb_multInc * 2)) * bb_stdDev
bo_dev = bo_mult * bb_stdDev

// plot basis
plot(bb_basis, title="Basis Line", color=silver, transp=50)

// plot and fill upper bands
bbu_A = plot((bb_basis + bb_devBase), title="Upper Band - A", color=red, transp=90)
bbu_B = plot((bb_basis + bb_devInc1), title="Upper Band - B", color=red, transp=85)
bbu_C = plot((bb_basis + bb_devInc2), title="Upper Band - C", color=red, transp=80)
fill(bbu_A, bbu_B, title="Upper Fill [ A - B ]", color=red, transp=90)
fill(bbu_B, bbu_C, title="Upper Fill [ B - C ]", color=red, transp=80)

// plot and fill lower bands
bbl_A = plot((bb_basis - bb_devBase), title="Lower Band - A", color=green, transp=90)
bbl_B = plot((bb_basis - bb_devInc1), title="Lower Band - B", color=green, transp=85)
bbl_C = plot((bb_basis - bb_devInc2), title="Lower Band - C", color=green, transp=80)
fill(bbl_A, bbl_B, title="Lower Fill [ A - B ]", color=green, transp=90)
fill(bbl_B, bbl_C, title="Lower Fill [ B - C ]", color=green, transp=80)

// center channel fill
fill(bbu_A, bbl_A, title="Center Channel Fill", color=silver, transp=100)

// plot breakouts
plotshape(bo_hSource >= (bb_basis + bo_dev), title="High Break", style=shape.triangledown, location=location.abovebar, size=size.tiny, color=red, transp=0)
plotshape(bo_lSource <= (bb_basis - bo_dev), title="Low Break", style=shape.triangleup, location=location.belowbar, size=size.tiny, color=green, transp=0)
Attachments
Who knows others is wise
Who knows himself is enlightened

Re: Converting tradingview script to mt4 indicator

3
Hello coders! Request to convert Tradingview script to MT4. Thank you!
Automatically finds a triangle on the chart.
https://ru.tradingview.com/script/R1uOE ... otriangle/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ROBO_Trading

//@version=4
study(title = "robotrading autotriangle", shorttitle = "autotriangle", overlay = true)

bars = input(1000)
level = input(false)

newlineh(bars)=>
h = highest(high, bars)
t = 0
for i = 0 to bars
t := i
if high == h
break
var line line1 = na
line.delete(line1)
if level
line1 := line.new(bar_index - t, h, bar_index, h, color = color.blue, width = 3, extend = extend.right)
a = t

newlinel(bars)=>
l = lowest(low, bars)
t = 0
for i = 0 to bars
t := i
if low == l
break
var line line1 = na
line.delete(line1)
if level
line1 := line.new(bar_index - t, l, bar_index, l, color = color.red, width = 3, extend = extend.right)
a = t

h1 = newlineh(bars)
l1 = newlinel(max(1, h1))
h2 = newlineh(max(1, l1))
l2 = newlinel(max(1, h2))

var line line1 = na
line.delete(line1)
hy1 = highest(high, max(1, h1 + 1))
hy2 = highest(high, max(1, h2 + 1))
line1 := line.new(bar_index - h1, hy1, bar_index - h2, hy2, color = color.orange, width = 3, extend = extend.right)

var line line2 = na
line.delete(line2)
ly1 = lowest(low, max(1, l1 + 1))
ly2 = lowest(low, max(1, l2 + 1))
line2 := line.new(bar_index - l1, ly1, bar_index - l2, ly2, color = color.orange, width = 3, extend = extend.right)
Attachments
Who knows others is wise
Who knows himself is enlightened

Re: Converting tradingview script to mt4 indicator

4
Hello coders! Request to convert Tradingview script to MT4. Thank you!
OBV with linear regression
https://ru.tradingview.com/script/y6l30AA0-OBV-LIN/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RafaelZioni

//@version=4
study(title="OBV-LIN", overlay=true)

src1 = close
window_len = 28

v_len = 14
price_spread = stdev(high-low, window_len)

v = cum(sign(change(src1)) * volume)
smooth = sma(v, v_len)
v_spread = stdev(v - smooth, window_len)
shadow = (v - smooth) / v_spread * price_spread

out = shadow > 0 ? high + shadow : low + shadow


len1 = input(50, title="OBV Length")


z(out, len1) =>
h = 0.0
d = 0.0
for i = 0 to len1 - 1
k = (len1 - i) * len1
h := h + k
d := d + out * k
d / h

cp = z(out, floor(sqrt(len1)))


lineColor = cp > cp[2] ? color.lime : color.red
plot(cp, title="cp", color=lineColor ,linewidth=2)
//
len = input(100, minval=1),off= 0,dev= input(2, "Deviation")
c1 = cp

lreg1 = linreg(c1, len1, off), lreg_x1 =linreg(c1, len1, off+1)
b1 = bar_index, s1 = lreg1 - lreg_x1,intr1 = lreg1 - b1*s1
dS1 = 0.0
for i1=0 to len1-1
dS1:= dS1 + pow(c1[i1]-(s1*(b1-i1)+intr1), 2)
de1 = sqrt(dS1/(len))
up1 = (-de1*dev) + lreg1
down1= (de1*dev) + lreg1

//

//
t1=0, x11 = bar_index-len,x21 = bar_index, y11 = s1*( bar_index-len)+intr1,y21 = lreg1,u1 = t1 <= 0 or bar_index < t1
if u1
line pr1 = line.new(x11, y11, x21, y21, xloc.bar_index, extend.none, color.gray,width=1)
line.delete(pr1[1])
line px1 = line.new(x11, de1*dev + y11, x21, de1*dev + y21, xloc.bar_index, extend.none,width=1)
line.delete(px1[1])
line pz1 = line.new(x11, -de1*dev + y11, x21, -de1*dev + y21, xloc.bar_index, extend.none,width=1)
line.delete(pz1[1])
//
c = close

lreg = linreg(c, len, off), lreg_x =linreg(c, len, off+1)
b = bar_index, s = lreg - lreg_x,intr = lreg - b*s
dS = 0.0
for i=0 to len-1
dS:= dS + pow(c-(s*(b-i)+intr), 2)
de = sqrt(dS/(len))
up = (-de*dev) + lreg
down= (de*dev) + lreg
//

//
t=0, x1 = bar_index-len,x2 = bar_index, y1 = s*( bar_index-len)+intr,y2 = lreg,u = t <= 0 or bar_index < t
if u
line pr = line.new(x1, y1, x2, y2, xloc.bar_index, extend.right, color.red,style=line.style_dashed,width=2)
line.delete(pr[1])
line px = line.new(x1, de*dev + y1, x2, de*dev + y2, xloc.bar_index, extend.right,style=line.style_dashed,width=2)
line.delete(px[1])
line pz = line.new(x1, -de*dev + y1, x2, -de*dev + y2, xloc.bar_index, extend.right,style=line.style_dashed,width=2)
line.delete(pz[1])


bu1 = crossover(cp,cp[2]) and cp<up
sz2=crossunder(cp,cp[2]) and cp>down

plotshape(bu1, style=shape.triangleup,location=location.belowbar, color=color.green, transp=0, size=size.tiny)
plotshape(sz2, style=shape.triangledown,location=location.abovebar, color=color.red, transp=0, size=size.tiny)
Attachments
These users thanked the author dmnik for the post:
RodrigoRT7
Who knows others is wise
Who knows himself is enlightened


Who is online

Users browsing this forum: No registered users and 19 guests