Merge Two SuperTrend In pinescript TradingView
Merge Two SuperTrend In pinescript TradingView
Sample Code :-
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © subhajitbhattacharya
//@version=5
indicator("Two Supertrend", overlay=true, timeframe="", timeframe_gaps=true)
atrPeriod = input(10, "ATR Length", inline = "1")
factor = input.float(3.0, "Factor", step = 0.01, inline = "1")
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
bodyMiddle = plot((open + close) / 2, display=display.none)
upTrend = plot(direction < 0 ? supertrend : na, "Up Trend", color = color.green, style=plot.style_linebr)
downTrend = plot(direction < 0? na : supertrend, "Down Trend", color = color.red, style=plot.style_linebr)
fill(bodyMiddle, upTrend, color.new(color.green, 90), fillgaps=false)
fill(bodyMiddle, downTrend, color.new(color.red, 90), fillgaps=false)
atrPeriod1 = input(5, "ATR Length", inline = "2")
factor1 = input.float(1.0, "Factor", step = 0.01, inline = "2")
[supertrend1, direction1] = ta.supertrend(factor1, atrPeriod1)
bodyMiddle1 = plot((open + close) / 2, display=display.none)
upTrend1 = plot(direction1 < 0 ? supertrend1 : na, "Up Trend", color = color.green, style=plot.style_linebr)
downTrend1 = plot(direction1 < 0? na : supertrend1, "Down Trend", color = color.red, style=plot.style_linebr)
fill(bodyMiddle1, upTrend1, color.new(color.green, 90), fillgaps=false)
fill(bodyMiddle1, downTrend1, color.new(color.red, 90), fillgaps=false)
buy = direction < 0 and direction1 < 0
sell = direction > 0 and direction1 > 0
plotshape(buy and not buy[1], style = shape.triangleup, location = location.belowbar, color = color.green, size = size.normal)
plotshape(sell and not sell[1], style = shape.triangledown, location = location.abovebar, color = color.red, size = size.normal)
Video Tutorial :-
Comments
Post a Comment