명시
Hi, I need to convert this indicator written in pine script to mq4. Alerts should be added when the price touches the trendline
and the ability to change the ATR period and set how many past trendlines can be displayed.
It can be done?
Thank you.Corrado
//@version=5
indicator("Trendlines with Breaks", "Trendlines with Breaks", overlay = true)
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
length = input.int(14, 'Swing Detection Lookback')
mult = input.float(1., 'Slope', minval = 0, step = .1)
calcMethod = input.string('Atr', 'Slope Calculation Method', options = ['Atr','Stdev','Linreg'])
backpaint = input(true, tooltip = 'Backpainting offset displayed elements in the past. Disable backpainting to see real time information returned by the indicator.')
//Style
upCss = input.color(color.teal, 'Up Trendline Color', group = 'Style')
dnCss = input.color(color.red, 'Down Trendline Color', group = 'Style')
showExt = input(true, 'Show Extended Lines')
//-----------------------------------------------------------------------------}
//Calculations
//-----------------------------------------------------------------------------{
var upper = 0.
var lower = 0.
var slope_ph = 0.
var slope_pl = 0.
var offset = backpaint ? length : 0
n = bar_index
src = close
ph = ta.pivothigh(length, length)
pl = ta.pivotlow(length, length)
//Slope Calculation Method
slope = switch calcMethod
'Atr' => ta.atr(length) / length * mult
'Stdev' => ta.stdev(src,length) / length * mult
'Linreg' => math.abs(ta.sma(src * n, length) - ta.sma(src, length) * ta.sma(n, length)) / ta.variance(n, length) / 2 * mult
//Get slopes and calculate trendlines
slope_ph := ph ? slope : slope_ph
slope_pl := pl ? slope : slope_pl
upper := ph ? ph : upper - slope_ph
lower := pl ? pl : lower + slope_pl
var upos = 0
var dnos = 0
upos := ph ? 0 : close > upper - slope_ph * length ? 1 : upos
dnos := pl ? 0 : close < lower + slope_pl * length ? 1 : dnos
//-----------------------------------------------------------------------------}
//Extended Lines
//-----------------------------------------------------------------------------{
var uptl = line.new(na,na,na,na, color = upCss, style = line.style_dashed, extend = extend.right)
var dntl = line.new(na,na,na,na, color = dnCss, style = line.style_dashed, extend = extend.right)
if ph and showExt
uptl.set_xy1(n-offset, backpaint ? ph : upper - slope_ph * length)
uptl.set_xy2(n-offset+1, backpaint ? ph - slope : upper - slope_ph * (length+1))
if pl and showExt
dntl.set_xy1(n-offset, backpaint ? pl : lower + slope_pl * length)
dntl.set_xy2(n-offset+1, backpaint ? pl + slope : lower + slope_pl * (length+1))
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
plot(backpaint ? upper : upper - slope_ph * length, 'Upper', color = ph ? na : upCss, offset = -offset)
plot(backpaint ? lower : lower + slope_pl * length, 'Lower', color = pl ? na : dnCss, offset = -offset)
//Breakouts
plotshape(upos > upos[1] ? low : na, "Upper Break"
, shape.labelup
, location.absolute
, upCss
, text = "B"
, textcolor = color.white
, size = size.tiny)
plotshape(dnos > dnos[1] ? high : na, "Lower Break"
, shape.labeldown
, location.absolute
, dnCss
, text = "B"
, textcolor = color.white
, size = size.tiny)
//-----------------------------------------------------------------------------}
//Alerts
//-----------------------------------------------------------------------------{
alertcondition(upos > upos[1], 'Upward Breakout', 'Price broke the down-trendline upward')
alertcondition(dnos > dnos[1], 'Downward Breakout', 'Price broke the up-trendline downward')
//-----------------------------------------------------------------------------}
응답함
1
등급
프로젝트
460
26%
중재
140
20%
/
59%
기한 초과
100
22%
작업중
2
등급
프로젝트
598
35%
중재
64
20%
/
58%
기한 초과
147
25%
무료
게재됨: 1 기고글, 22 코드
3
등급
프로젝트
814
62%
중재
33
27%
/
45%
기한 초과
23
3%
무료
게재됨: 1 코드
4
등급
프로젝트
220
75%
중재
0
기한 초과
0
무료
5
등급
프로젝트
3
33%
중재
1
0%
/
100%
기한 초과
0
무료
6
등급
프로젝트
17
47%
중재
2
50%
/
50%
기한 초과
0
무료
7
등급
프로젝트
3
0%
중재
3
33%
/
67%
기한 초과
1
33%
무료
8
등급
프로젝트
499
67%
중재
5
40%
/
0%
기한 초과
4
1%
무료
게재됨: 8 코드
9
등급
프로젝트
945
47%
중재
309
58%
/
27%
기한 초과
125
13%
무료
10
등급
프로젝트
178
39%
중재
4
25%
/
50%
기한 초과
14
8%
무료
프로젝트 정보
예산
30 - 50 USD