Yes it worked, thanks a lot Mrtools.
btw, what is color red for? the one with "color late" buffer?
Also, was wondering if for MT4 already exist ot its possible to make something like this indicator from tradingview that calculates angles of bollinger bands:
this is the explanation of the indicator:
"This script is used to calculate angle of Bollinger Bands and also setup alerts.
The angle is based on the rules:
- if the previous 2 is 1.1, previous 1 is 1, and the current is 1.1, then the angle should be 90 degrees.
- if the previous 2 is 0.9, previous 1 is 1, and the current is 0.9, then the angle should be 270 degrees
If upper angle is below 90 degrees and close is above the average, it is long signal.
If lower angle is above 270 degrees and close is below the average, it is short signal.
- It is good for catch trend trading.
- Not good for swing trading as the BB changes are very tiny but angles for upper may hit below 90 degrees or angle of lower may be above 270 degrees.
this is the code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jesselau76 https://jesselau.com
//@version=4
study(shorttitle="BBAngle", title="Angle of Bollinger Bands Alert", overlay=true, resolution="")
// input
length = input(5, minval=1)
src = input(close, title="Source")
mult = input(2.0, minval=0.001, maxval=50, title="StdDev")
basis = sma(src, length)
dev = mult * stdev(src, length)
upper = basis + dev
lower = basis - dev
offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
plot(basis, "Basis", color=#872323, offset = offset)
p1 = plot(upper, "Upper", color=color.teal, offset = offset)
p2 = plot(lower, "Lower", color=color.teal, offset = offset)
fill(p1, p2, title = "Background", color=#198787, transp=95)
anglealert = input(90.0, minval=0.0, maxval=360, title="Angle Alert")
//calculate angles
//Base on the rules: if 1 change to 2 than change to 1, the angle shoulbe 270 degree. if 2 change to 1 then change to 2, the angle should be 90 degree.
rad2degree = 180 / 3.141592653589793238462643 //pi
ang1 = 180 - rad2degree * atan((upper[0] - upper[1]) / abs(upper[1]-upper[2])) - rad2degree * atan((upper[2] - upper[1]) / abs(upper[1]-upper[2]))
ang2 = 180 - rad2degree * atan((lower[0] - lower[1]) / abs(lower[1]-lower[2])) - rad2degree * atan((lower[2] - lower[1]) / abs(lower[1]-lower[2]))
// Signals
turnGreen = close > basis and ang1 < anglealert
turnRed = close < basis and ang2 > 360 - anglealert
plotshape(turnGreen, style = shape.triangleup, location = location.belowbar, color = color.green, size=size.small)
plotshape(turnRed, style = shape.triangledown, location = location.abovebar, color = color.red, size=size.small)
// Alerts
alertcondition(turnGreen, title= "bbangle_green", message= "{{ticker}} LONG")
alertcondition(turnRed, title= "bbangle_red", message= "{{ticker}} SHORT")