Merge Two SuperTrend In pinescript TradingView

Merge Two SuperTrend In pinescript TradingView


    Merging two SuperTrend indicators in Pine Script on TradingView allows traders to combine multiple trend-following signals and gain deeper insights into market trends. In this guide, we will walk you through the process of merging two SuperTrend indicators in Pine Script. You will learn how to adjust the parameters and plot the merged indicator on your TradingView chart. By merging two SuperTrend indicators, you can potentially enhance the accuracy of your trading signals and make more informed trading decisions. Discover how to harness the power of combining SuperTrend indicators to identify strong trends and improve your overall trading strategy.

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

Popular posts from this blog

How to develop Screener in Pine Script TradingView

Import Chartink data into Python

Import Nifty Option Chain With Python