-
-
-
https://www.tradingview.com/x/QtHSyTiy/ atr trend bar renklendirme...
trend hesaplatma var.....kullanılan ortalamaları...mtf olarak da hesapladığı için....
iki tane atr trend hesaplıyor.....
isteyen.....stoplarıda görülebilir yapar......
PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//
//@version=6
//
// L&L Trend System
//
// L&L Trend System is an ATR based day trading system specifically designed for intra-day traders and scalpers.
//
// The System works on any chart time frame & can be applied to any market. The study involves two components: 1.) Trend Line which is basically a fast gauge
// represented by the 13 EMA. 2.) Stop Line is an ATR deviaton line with special calculation based on the previous bar ATRs and position of the price in relation
// to the current and previous values of 13 EMA.
//
// There are 5 different trend modes available. Each mode is visualizing different ATR settings which provides either aggressive or more conservative approach. The
// more "tigher" modes such as tight or normal can be used on less volatile markets such as S&P Futures (ES). Looses & FOMC modes are designed for active high volatility
// markets such as NQ or YM futures or BTC or perhaps some currency pairs. Then there is the "Net" mode. The net mode is basically the combination of all modes in one
// stop line system which creates "the net" effect. The system also includes additional higher time frame (HTF) trend system. This can be set to any time frame by manual
// HTF mode. HTF mode set to "auto" will automatically choose the best suitable higher time frame trend system based on my backtesting results.
//
// By default, the bars are colored (Trend Bars) based on the DMI and ADX indicators. Whenever the DMI is bearish and ADX is above 20 the candles paint themselfs red.
// And vice versa for the green candles and bullish DMI. Whenever the ADX falls below the 20, candles are netural which means there is no real trend in place.
//
// In terms of visualization, each trend system is fully customizable through the inputs settings. There is also an option to turn on/off the background clouds behind the
// stop lines. These clouds can make the charts more clean & visible.
//
// Created by © L&L Capital
//
indicator('Trend System', shorttitle = '.', overlay = true)
// Inputs
string TrendMode = input.string('Normal', 'Trend Mode', options = ['Tight', 'Normal', 'Loose', 'FOMC', 'Net'], group = 'Settings', tooltip = 'There are several trend modes available. The mods are lined up based on the aggressiveness of the ATR. Tight & Normal modes are the going to flip way much often whereas the Loose or FOMC will provide much higher wiggle room. The good rule of thumb to use is to just stick with first two modes when trading less volatile sessions or ranges, and use the other two on fast moving expanding environments. The Net mode provides the combination of all modes in one giant net. Some might prefer this mode since it suits well to the scale in scale out methods. ')
string HTFMode = input.string('Auto', 'HTF Mode', options = ['Auto', 'Manual'], group = 'Settings', tooltip = 'Changes the higher time frame mode. The HTF mode set to auto will automatically change the HTF Trend System time frame for you. The auto mode is choosing the most suitable time frames based on the pre-defined time frame pairs that are the most suitable ones. If you prefer your own time frame choose the manual mode.')
TimeFrameM = input.timeframe('60', 'HTF Aggregation', options = ['1', '2', '3', '5', '10', '15', '20', '30', '45', '60', '120', '180', '240', 'D', '2D', '3D', '4D', 'W', '2W', '3W', 'M', '2M', '3M'], group = 'Settings', tooltip = 'Set the manual time frame for the HTF Trend System.')
ShowTrendBars = input(defval = true, title = 'Show Trend Bars', group = 'Trend Bars', tooltip = 'Trend Bars are based on the DMI and ADX indicators. Whenever the DMI is bearish and ADX is above 20 the candles paint themselfs red. And vice versa for the green candles and bullish DMI. Whenever the ADX falls below the 20, candles are netural which means there is no real trend in place.')
TrendBarBullish = input(#27c22e, title = 'Bullish', group = 'Trend Bars')
TrendBarBearish = input(#ff0000, title = 'Bearish', group = 'Trend Bars')
TrendBarNeutral = input(#f4f4ee, title = 'Neutral', group = 'Trend Bars')
ShowTrend = input(defval = true, title = 'Show Trend Line', group = 'Trend Line', tooltip = 'Trend Line is the first part of the L&L Trend System. The trend line is nothing simplier than the 13 exponential moving average. The color of the Trend Line depends on the position of multiple exponential averages and whether they are stacked on top of each other or not.')
TrendBullish = input(#27c22e, title = 'Bullish', group = 'Trend Line')
TrendBearish = input(#ff0000, title = 'Bearish', group = 'Trend Line')
TrendNeutral = input(#f4f4ee, title = 'Neutral', group = 'Trend Line')
ShowStop = input(defval = true, title = 'Show Stop Line', group = 'Stop Line', tooltip = 'Stop Line is the main and most important part of the system. It is based on a special ATR calculation that takes into consideration the past ATRs and prices of the 13 EMA. Stop Line provides zones that no moving average can. To make it simple it is something like a moving average that uses the ATR not the average price of the previous bars.')
StopBullish = input(#27c22e, title = 'Bullish', group = 'Stop Line')
StopBearish = input(#ff0000, title = 'Bearish', group = 'Stop Line')
ShowTrend2 = input(defval = false, title = 'Show HTF Trend Line', group = 'Higher Time Frame Trend Line', tooltip = 'Higher Time Frame Trend Line.')
TrendBullish2 = input(#27c22e, title = 'Bullish', group = 'Higher Time Frame Trend Line')
TrendBearish2 = input(#ff0000, title = 'Bearish', group = 'Higher Time Frame Trend Line')
TrendNeutral2 = input(#f4f4ee, title = 'Neutral', group = 'Higher Time Frame Trend Line')
ShowStop2 = input(defval = false, title = 'Show HTF Stop Line', group = 'Higher Time Frame Stop Line', tooltip = 'Higher Time Frame Stop Line')
StopBullish2 = input(#27c22e, title = 'Bullish', group = 'Higher Time Frame Stop Line')
StopBearish2 = input(#ff0000, title = 'Bearish', group = 'Higher Time Frame Stop Line')
ShowCloud = input(defval = true, title = 'Show Cloud', group = 'Trend Cloud', tooltip = 'Cloud will paint the area behind the Trend Line and Stop Line with custom color.')
CloudBullish = input(color.rgb(39, 194, 46, 85), title = 'Bullish', group = 'Trend Cloud')
CloudBearish = input(color.rgb(255, 0, 0, 85), title = 'Bearish', group = 'Trend Cloud')
ShowHTFCloud = input(defval = false, title = 'Show HTF Cloud', group = 'Higher Time Frame Trend Cloud', tooltip = 'Higher Time Frame Cloud.')
CloudBullish2 = input(color.rgb(39, 194, 46, 85), title = 'Bullish', group = 'Higher Time Frame Trend Cloud')
CloudBearish2 = input(color.rgb(255, 0, 0, 85), title = 'Bearish', group = 'Higher Time Frame Trend Cloud')
// Trend Bars (DMI Colored Candles)
BullishDMI = high - high[1] > low[1] - low and high - high[1] > 0 ? high - high[1] : 0
BearishDMI = low[1] - low > high - high[1] and low[1] - low > 0 ? low[1] - low : 0
DMIUp = 100 * ta.rma(BullishDMI, 14) / ta.rma(ta.tr(true), 14)
DMIDown = 100 * ta.rma(BearishDMI, 14) / ta.rma(ta.tr(true), 14)
ADXx = DMIUp + DMIDown > 0 ? 100 * math.abs(DMIUp - DMIDown) / (DMIUp + DMIDown) : na
ADX = ta.rma(ADXx, 14)
ColorBars = ShowTrendBars and DMIUp > DMIDown and ADX > 20 ? TrendBarBullish : ShowTrendBars and DMIUp < DMIDown and ADX > 20 ? TrendBarBearish : ShowTrendBars ? TrendBarNeutral : na
barcolor(color = ColorBars, editable = false)
// Trend System (First Time Frame)
ema8 = ta.vwma(close, 8)
ema13 = ta.vwma(close, 13)
ema21 = ta.vwma(close, 21)
ema34 = ta.vwma(close, 34)
emaup = ema8 > ema13 and ema13 > ema21 and ema21 > ema34
emadn = ema8 < ema13 and ema13 < ema21 and ema21 < ema34
Trend = ta.ema(close, 13)
TrendColor = ShowTrend and emadn and close <= Trend ? TrendBearish : ShowTrend and emaup and close >= Trend ? TrendBullish : ShowTrend ? TrendNeutral : na
plot(Trend, title = 'Atr-Trend-1', color = TrendColor, linewidth = 2, editable = false)
ATRLength = if TrendMode == 'Tight'
60
else if TrendMode == 'Normal'
80
else if TrendMode == 'Loose'
100
else if TrendMode == 'FOMC'
120
else if TrendMode == 'Net'
140
ATR = ATRLength / 100 * ta.ema(ta.tr(true), 8)
Up = close > Trend + ATR
Down = close < Trend - ATR
var T = 0.0
T := Up ? 1 : Down ? -1 : T[1]
StopLineColor = ShowStop and T == 1 ? StopBullish : ShowStop ? StopBearish : na
//plotchar(T == 1 ? Trend - ATR : T == -1 ? Trend + ATR : T[1], title = 'StopLine', char = '-', location = location.absolute, size = size.tiny, color = StopLineColor, editable = false)
ATRA = (ATRLength - 20) / 100 * ta.ema(ta.tr(true), 8)
Up11 = close > Trend + ATRA
Down11 = close < Trend - ATRA
var T11 = 0.0
T11 := Up11 ? 1 : Down11 ? -1 : T11[1]
StopLineColor1 = ShowStop and T11 == 1 ? StopBullish : ShowStop ? StopBearish : na
//plotchar(T11 == 1 ? Trend - ATRA : T11 == -1 ? Trend + ATRA : T11[1], title = 'StopLine2', char = '-', location = location.absolute, size = size.tiny, color = StopLineColor1, editable = false)
ATRNET = TrendMode == 'Net' ? (ATRLength - 40) / 100 * ta.ema(ta.tr(true), 8) : na
UpNET = close > Trend + ATRNET
DownNET = close < Trend - ATRNET
var TNET = 0.0
TNET := UpNET ? 1 : DownNET ? -1 : TNET[1]
StopLineColorNET = ShowStop and TNET == 1 ? StopBullish : ShowStop ? StopBearish : na
//plotchar(TNET == 1 ? Trend - ATRNET : TNET == -1 ? Trend + ATRNET : TNET[1], title = 'StopLineNET', char = '-', location = location.absolute, size = size.tiny, color = StopLineColorNET, editable = false)
ATRNET1 = TrendMode == 'Net' ? (ATRLength - 60) / 100 * ta.ema(ta.tr(true), 8) : na
UpNET1 = close > Trend + ATRNET1
DownNET1 = close < Trend - ATRNET1
var TNET1 = 0.0
TNET1 := UpNET1 ? 1 : DownNET1 ? -1 : TNET1[1]
StopLineColorNET1 = ShowStop and TNET1 == 1 ? StopBullish : ShowStop ? StopBearish : na
//plotchar(TNET1 == 1 ? Trend - ATRNET1 : TNET1 == -1 ? Trend + ATRNET1 : TNET1[1], title = 'StopLineNET1', char = '-', location = location.absolute, size = size.tiny, color = StopLineColorNET1, editable = false)
ATRNET2 = TrendMode == 'Net' ? (ATRLength - 80) / 100 * ta.ema(ta.tr(true), 8) : na
UpNET2 = close > Trend + ATRNET2
DownNET2 = close < Trend - ATRNET2
var TNET2 = 0.0
TNET2 := UpNET2 ? 1 : DownNET2 ? -1 : TNET2[1]
StopLineColorNET2 = ShowStop and TNET2 == 1 ? StopBullish : ShowStop ? StopBearish : na
//plotchar(TNET2 == 1 ? Trend - ATRNET2 : TNET2 == -1 ? Trend + ATRNET2 : TNET2[1], title = 'StopLineNET2', char = '-', location = location.absolute, size = size.tiny, color = StopLineColorNET2, editable = false)
// Higher Time Frame Aggregations
TimeFrameA = timeframe.period == '1' ? '5' : timeframe.period == '2' ? '5' : timeframe.period == '3' ? '5' : timeframe.period == '4' ? '5' : timeframe.period == '5' ? '30' : timeframe.period == '10' ? '30' : timeframe.period == '15' ? '30' : timeframe.period == '30' ? '240' : timeframe.period == '60' ? '240' : timeframe.period == '120' ? '240' : timeframe.period == '180' ? 'D' : timeframe.period == '240' ? 'D' : timeframe.period == 'D' ? 'W' : timeframe.period == 'W' ? 'M' : timeframe.period == 'M' ? '3M' : timeframe.period
TimeFrame = if HTFMode == 'Auto'
TimeFrameA
else if HTFMode == 'Manual'
TimeFrameM
// Trend System (Second Time Frame)
ema82 = request.security(syminfo.tickerid, TimeFrame, ta.vwma(close, 8))
ema132 = request.security(syminfo.tickerid, TimeFrame, ta.vwma(close, 13))
ema212 = request.security(syminfo.tickerid, TimeFrame, ta.vwma(close, 21))
ema342 = request.security(syminfo.tickerid, TimeFrame, ta.vwma(close, 34))
emaup2 = ema82 > ema132 and ema132 > ema212 and ema212 > ema342
emadn2 = ema82 < ema132 and ema132 < ema212 and ema212 < ema342
Trend2 = request.security(syminfo.tickerid, TimeFrame, ta.ema(close, 13))
TrendColor2 = ShowTrend2 and emadn2 and request.security(syminfo.tickerid, TimeFrame, close) <= Trend2 ? TrendBearish2 : ShowTrend2 and emaup2 and request.security(syminfo.tickerid, TimeFrame, close) >= Trend2 ? TrendBullish2 : ShowTrend2 ? TrendNeutral2 : na
plot(Trend2, title = 'Atr-Trend-2', color = TrendColor2, linewidth = 2, editable = false)
ATRLength2 = if TrendMode == 'Tight'
60
else if TrendMode == 'Normal'
80
else if TrendMode == 'Loose'
100
else if TrendMode == 'FOMC'
120
else if TrendMode == 'Net'
140
ATR2 = ATRLength2 / 100 * request.security(syminfo.tickerid, TimeFrame, ta.ema(ta.tr(true), 8))
Up2 = request.security(syminfo.tickerid, TimeFrame, close) > Trend2 + ATR2
Down2 = request.security(syminfo.tickerid, TimeFrame, close) < Trend2 - ATR2
var T2 = 0.0
T2 := Up2 ? 1 : Down2 ? -1 : T2[1]
StopLineColor2 = ShowStop2 and T2 == 1 ? StopBullish2 : ShowStop2 ? StopBearish2 : na
//plotchar(T2 == 1 ? Trend2 - ATR2 : T2 == -1 ? Trend2 + ATR2 : T2[1], title = 'StopLine2', char = '-', location = location.absolute, size = size.tiny, color = StopLineColor2, editable = false)
ATR2A = (ATRLength2 - 20) / 100 * request.security(syminfo.tickerid, TimeFrame, ta.ema(ta.tr(true), 8))
Up2A = request.security(syminfo.tickerid, TimeFrame, close) > Trend2 + ATR2A
Down2A = request.security(syminfo.tickerid, TimeFrame, close) < Trend2 - ATR2A
var T2A = 0.0
T2A := Up2A ? 1 : Down2A[1] ? -1 : T2A[1]
StopLineColor2A = ShowStop2 and T2A == 1 ? StopBullish2 : ShowStop2 ? StopBearish2 : na
//plotchar(T2A == 1 ? Trend2 - ATR2A : T2A == -1 ? Trend2 + ATR2A : T2A[1], title = 'StopLine2', char = '-', location = location.absolute, size = size.tiny, color = StopLineColor2A, editable = false)
ATR2ANET = TrendMode == 'Net' ? (ATRLength2 - 40) / 100 * request.security(syminfo.tickerid, TimeFrame, ta.ema(ta.tr(true), 8)) : na
Up2ANET = request.security(syminfo.tickerid, TimeFrame, close) > Trend2 + ATR2ANET
Down2ANET = request.security(syminfo.tickerid, TimeFrame, close) < Trend2 - ATR2ANET
var T2ANET = 0.0
T2ANET := Up2ANET ? 1 : Down2ANET[1] ? -1 : T2ANET[1]
StopLineColor2ANET = ShowStop2 and T2ANET == 1 ? StopBullish2 : ShowStop2 ? StopBearish2 : na
//plotchar(T2ANET == 1 ? Trend2 - ATR2ANET : T2ANET == -1 ? Trend2 + ATR2ANET : T2ANET[1], title = 'StopLine2', char = '-', location = location.absolute, size = size.tiny, color = StopLineColor2ANET, editable = false)
ATR2ANET1 = TrendMode == 'Net' ? (ATRLength2 - 60) / 100 * request.security(syminfo.tickerid, TimeFrame, ta.ema(ta.tr(true), 8)) : na
Up2ANET1 = request.security(syminfo.tickerid, TimeFrame, close) > Trend2 + ATR2ANET1
Down2ANET1 = request.security(syminfo.tickerid, TimeFrame, close) < Trend2 - ATR2ANET1
var T2ANET1 = 0.0
T2ANET1 := Up2ANET1 ? 1 : Down2ANET1[1] ? -1 : T2ANET1[1]
StopLineColor2ANET1 = ShowStop2 and T2ANET1 == 1 ? StopBullish2 : ShowStop2 ? StopBearish2 : na
//plotchar(T2ANET1 == 1 ? Trend2 - ATR2ANET1 : T2ANET1 == -1 ? Trend2 + ATR2ANET1 : T2ANET1[1], title = 'StopLine2', char = '-', location = location.absolute, size = size.tiny, color = StopLineColor2ANET1, editable = false)
ATR2ANET2 = TrendMode == 'Net' ? (ATRLength2 - 80) / 100 * request.security(syminfo.tickerid, TimeFrame, ta.ema(ta.tr(true), 8)) : na
Up2ANET2 = request.security(syminfo.tickerid, TimeFrame, close) > Trend2 + ATR2ANET2
Down2ANET2 = request.security(syminfo.tickerid, TimeFrame, close) < Trend2 - ATR2ANET2
var T2ANET2 = 0.0
T2ANET2 := Up2ANET2 ? 1 : Down2ANET2[1] ? -1 : T2ANET2[1]
StopLineColor2ANET2 = ShowStop2 and T2ANET2 == 1 ? StopBullish2 : ShowStop2 ? StopBearish2 : na
//plotchar(T2ANET2 == 1 ? Trend2 - ATR2ANET2 : T2ANET2 == -1 ? Trend2 + ATR2ANET2 : T2ANET2[1], title = 'StopLine2', char = '-', location = location.absolute, size = size.tiny, color = StopLineColor2ANET2, editable = false)
// Trend Clouds
p1 = plot(Trend, title = 'Trend Line', color = TrendColor, linewidth = 2, display = display.none, editable = false)
p2 = plot(T == 1 ? Trend - ATR : T == -1 ? Trend + ATR : T[1], title = 'StopLine ', color = StopLineColor, linewidth = 2, display = display.none, editable = false)
Cloud = ShowCloud and T == 1 ? CloudBullish : ShowCloud ? CloudBearish : na
//fill(p1, p2, title = 'TrendCloud', color = Cloud, editable = false)
p3 = plot(Trend2, title = 'Trend Line 2', color = TrendColor2, linewidth = 2, display = display.none, editable = false)
p4 = plot(T2 == 1 ? Trend2 - ATR2 : T2 == -1 ? Trend2 + ATR2 : T2[1], title = 'StopLine 2', color = StopLineColor2, linewidth = 2, display = display.none, editable = false)
Cloud2 = ShowHTFCloud and T2 == 1 ? CloudBullish2 : ShowHTFCloud ? CloudBearish2 : na
//fill(p3, p4, title = 'TrendCloud2', color = Cloud2, editable = false)
/////////////////////////
-
https://www.tradingview.com/x/oTmrKsE8/ ortalama hesaplatma üçlü....kesişimleri dikkate alınıyor....
PHP Code:
//@version=6
source = input.source(close, 'Source')
alpha = input.float(0.1, 'Alpha', 0.001, 1, 0.001)
//style = input.string('BES', 'Style', ['BES', 'DBES', 'TBES'])
bes(source, alpha) =>
var float smoothed = na
smoothed := na(smoothed) ? source : alpha * source + (1 - alpha) * nz(smoothed[1])
smoothed
tbes() =>
e1 = bes(source, alpha)
e2 = bes(e1, alpha)
e3 = bes(e2, alpha)
tema = 3 * (e1 - e2) + e3
tema
dbes() =>
e1 = bes(source, alpha)
e2 = bes(e1, alpha)
dema = 2 * e1 - e2
dema
plot(bes(source, alpha), title="Trend Ortalama Yavaş", style = plot.style_line, color = close > bes(source, alpha) ? color.rgb(0, 230, 119, 00) : close < bes(source, alpha) ? color.rgb(255, 82, 82, 00) : na)
plot(tbes(), title="Trend Ortalama Hızlı", style = plot.style_line, color = close > tbes() ? color.rgb(0, 230, 119, 00) : close < tbes() ? color.rgb(255, 82, 82, 00) : na)
plot(dbes(), title="Trend Ortalama Normal", style = plot.style_line, color = close > dbes() ? color.rgb(0, 230, 119, 00) : close < dbes() ? color.rgb(255, 82, 82, 00) : na)
/////////////////////////
-
https://www.tradingview.com/x/2qmmxg1Z/
5 ve 4 değeri kullanılarak.....en yüksek ve düşük .....pivot üzerinden hesaplama yapıyor.....
değeri kendinize göre değiştirebilirsiniz....
PHP Code:
//
// ---------------------------------------------------------------------------------------------------------------------{
// @variable Length for LOWESS calculation
int length = input.int(1, minval = 1, title = 'Length', group = 'LOWESS (Locally Weighted Scatterplot Smoothing)')
// @variable Number of bars to the left for pivot calculation
int leftBars = input.int(5, 'Length', group = 'Pivots')
// @variable Number of bars to the right for pivot calculation
int rightBars = leftBars - 4
// @variable Line object for high pivot
var line line_h = na
// @variable Line object for low pivot
var line line_l = na
// @variable Color for upward movements
color col_up = color.yellow
// @variable Color for downward movements
color col_dn = color.red
// ---------------------------------------------------------------------------------------------------------------------}
//
// ---------------------------------------------------------------------------------------------------------------------{
// Calculate pivot high and low
ph = ta.pivothigh(leftBars, rightBars)
pl = ta.pivotlow(leftBars, rightBars)
//@function Calculates LOWESS (Locally Weighted Scatterplot Smoothing)
//@param src (float) Source series
//@param length (int) Lookback period
//@returns (float) LOWESS value
lowess(src, length) =>
sum_w = 0.0
sum_wx = 0.0
sum_wy = 0.0
for i = 0 to length - 1 by 1
w = math.pow(1 - math.pow(i / length, 3), 3)
sum_w := sum_w + w
sum_wx := sum_wx + w * i
sum_wy := sum_wy + w * src[i]
sum_wy
a = sum_wy / sum_w
b = sum_wx / sum_w
a + b / (length - 1) / 2000
//@function Calculates Modified Adaptive Gaussian Moving Average
//@param src (float) Source series
//@param length (int) Lookback period
//@returns [float, float] Gaussian MA and smoothed Gaussian MA
GaussianMA(src, length) =>
h_l = array.new<float>(length)
float gma = 0.0
float sumOfWeights = 0.0
float sigma = (ta.atr(length) + ta.stdev(close, length)) / 2 // Volatility adaption
float highest = 0.0
float lowest = 0.0
float smoothed = 0.0
for i = 0 to length - 1 by 1
h_l.push(close[i])
highest := h_l.max()
lowest := h_l.min()
weight = math.exp(-math.pow((i - (length - 1)) / (2 * sigma), 2) / 2)
value = math.max(highest[i], highest) + math.min(lowest[i], lowest)
gma := gma + value * weight
sumOfWeights := sumOfWeights + weight
sumOfWeights
gma := gma / sumOfWeights / 2
smoothed := lowess(gma, 10)
[gma, smoothed]
[gma, smoothed] = GaussianMA(close, length)
smoothedColor = smoothed > smoothed[2] ? col_up : smoothed <= smoothed[2] ? col_dn : na
plot(smoothed, 'Trend- Pivot', smoothedColor)
/////////////////////////////
-
macd gibi düşünün....12-26-9 ile 2-2-3 yinelemeli.....
https://www.tradingview.com/x/9gNLIv9P/
-
-
PHP Code:
/////////////////////////
//@version=6
// Input
fastlen = input(12, title = 'Fast Moving Average')
slowlen = input(26, title = 'Slow Moving Average')
signallen = input(9, title = 'Signal Line')
switch2 = input(true, title = 'Enable Moving Averages?')
// Calculation
fast = ta.ema(close, fastlen)
slow = ta.ema(close, slowlen)
MACD = fast - slow
signal = ta.ema(MACD, signallen)
histogr = MACD - signal
// MACD, MA colors
MACDcolor = fast > slow ? color.lime : color.red
fastcolor = ta.change(fast) > 0 ? color.lime : color.red
slowcolor = ta.change(slow) > 0 ? color.lime : color.red
MACDupdowncolor = ta.change(MACD) > 0 ? color.lime : color.red
// MACD histogram colors
histogrMACDcolor = MACD > histogr ? color.lime : color.red
histogrzerocolor = histogr > 0 ? color.lime : color.red
histogrupdowncolor = ta.change(histogr) > 0 ? color.lime : color.red
// MACD signal line colors
signalMACDcolor = MACD > signal ? color.lime : color.red
signalzerocolor = signal > 0 ? color.lime : color.red
signalupdowncolor = ta.change(signal) > 0 ? color.lime : color.red
S = plot(switch2 ? slow : na, color = MACDcolor, linewidth = 2, title="MACD- Trend-2 Yavaş")
///////
// Input
fastlen1 = input(2, title = 'Fast Moving Average')
slowlen1 = input(3, title = 'Slow Moving Average')
signallen1 = input(3, title = 'Signal Line')
switch21 = input(true, title = 'Enable Moving Averages?')
// Calculation
fast1 = ta.ema(close, fastlen1)
slow1 = ta.ema(close, slowlen1)
MACD1= fast1 - slow1
signal1 = ta.ema(MACD1, signallen1)
histogr1 = MACD1 - signal1
// MACD, MA colors
MACDcolor1 = fast1 > slow1 ? color.lime : color.red
fastcolor1 = ta.change(fast1) > 0 ? color.lime : color.red
slowcolor1 = ta.change(slow1) > 0 ? color.lime: color.red
MACDupdowncolor1 = ta.change(MACD1) > 0 ? color.lime : color.red
// MACD histogram colors
histogrMACDcolor1 = MACD1 > histogr1 ? color.lime : color.red
histogrzerocolor1 = histogr1 > 0 ? color.lime : color.red
histogrupdowncolor1 = ta.change(histogr1) > 0 ? color.lime : color.red
// MACD signal line colors
signalMACDcolor1 = MACD1 > signal1 ? color.lime : color.red
signalzerocolor1 = signal1 > 0 ? color.lime : color.red
signalupdowncolor1 = ta.change(signal1) > 0 ? color.lime : color.red
S1 = plot(switch21 ? slow1 : na, color = MACDcolor1, linewidth = 1,title="MACD-Trend-1 Hızlı")
-
https://www.tradingview.com/x/oatH0fPE/ kombineli....
PHP Code:
indicator('Trend System', shorttitle = '.', overlay = true)
/////////////////////////
//@version=6
// Input
fastlen = input(12, title = 'Fast Moving Average')
slowlen = input(26, title = 'Slow Moving Average')
signallen = input(9, title = 'Signal Line')
switch2 = input(true, title = 'Enable Moving Averages?')
// Calculation
fast = ta.ema(close, fastlen)
slow = ta.ema(close, slowlen)
MACD = fast - slow
signal = ta.ema(MACD, signallen)
histogr = MACD - signal
// MACD, MA colors
MACDcolor = fast > slow ? color.lime : color.red
fastcolor = ta.change(fast) > 0 ? color.lime : color.red
slowcolor = ta.change(slow) > 0 ? color.lime : color.red
MACDupdowncolor = ta.change(MACD) > 0 ? color.lime : color.red
// MACD histogram colors
histogrMACDcolor = MACD > histogr ? color.lime : color.red
histogrzerocolor = histogr > 0 ? color.lime : color.red
histogrupdowncolor = ta.change(histogr) > 0 ? color.lime : color.red
// MACD signal line colors
signalMACDcolor = MACD > signal ? color.lime : color.red
signalzerocolor = signal > 0 ? color.lime : color.red
signalupdowncolor = ta.change(signal) > 0 ? color.lime : color.red
S = plot(switch2 ? slow : na, color = MACDcolor, linewidth = 2, title="MACD- Trend-2 Yavaş")
///////
// Input
fastlen1 = input(2, title = 'Fast Moving Average')
slowlen1 = input(3, title = 'Slow Moving Average')
signallen1 = input(3, title = 'Signal Line')
switch21 = input(true, title = 'Enable Moving Averages?')
// Calculation
fast1 = ta.ema(close, fastlen1)
slow1 = ta.ema(close, slowlen1)
MACD1= fast1 - slow1
signal1 = ta.ema(MACD1, signallen1)
histogr1 = MACD1 - signal1
// MACD, MA colors
MACDcolor1 = fast1 > slow1 ? color.lime : color.red
fastcolor1 = ta.change(fast1) > 0 ? color.lime : color.red
slowcolor1 = ta.change(slow1) > 0 ? color.lime: color.red
MACDupdowncolor1 = ta.change(MACD1) > 0 ? color.lime : color.red
// MACD histogram colors
histogrMACDcolor1 = MACD1 > histogr1 ? color.lime : color.red
histogrzerocolor1 = histogr1 > 0 ? color.lime : color.red
histogrupdowncolor1 = ta.change(histogr1) > 0 ? color.lime : color.red
// MACD signal line colors
signalMACDcolor1 = MACD1 > signal1 ? color.lime : color.red
signalzerocolor1 = signal1 > 0 ? color.lime : color.red
signalupdowncolor1 = ta.change(signal1) > 0 ? color.lime : color.red
S1 = plot(switch21 ? slow1 : na, color = MACDcolor1, linewidth = 1,title="MACD-Trend-1 Hızlı")
///////////////////////
// 𝙐𝙎𝙀𝙍 𝙄𝙉𝙋𝙐𝙏𝙎
// ---------------------------------------------------------------------------------------------------------------------{
// @variable Length for LOWESS calculation
int length = input.int(1, minval = 1, title = 'Length', group = 'LOWESS (Locally Weighted Scatterplot Smoothing)')
// @variable Number of bars to the left for pivot calculation
int leftBars = input.int(5, 'Length', group = 'Pivots')
// @variable Number of bars to the right for pivot calculation
int rightBars = leftBars - 4
// @variable Line object for high pivot
var line line_h = na
// @variable Line object for low pivot
var line line_l = na
// @variable Color for upward movements
color col_up = color.yellow
// @variable Color for downward movements
color col_dn = color.red
// ---------------------------------------------------------------------------------------------------------------------}
// 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎
// ---------------------------------------------------------------------------------------------------------------------{
// Calculate pivot high and low
ph = ta.pivothigh(leftBars, rightBars)
pl = ta.pivotlow(leftBars, rightBars)
//@function Calculates LOWESS (Locally Weighted Scatterplot Smoothing)
//@param src (float) Source series
//@param length (int) Lookback period
//@returns (float) LOWESS value
lowess(src, length) =>
sum_w = 0.0
sum_wx = 0.0
sum_wy = 0.0
for i = 0 to length - 1 by 1
w = math.pow(1 - math.pow(i / length, 3), 3)
sum_w := sum_w + w
sum_wx := sum_wx + w * i
sum_wy := sum_wy + w * src[i]
sum_wy
a = sum_wy / sum_w
b = sum_wx / sum_w
a + b / (length - 1) / 2000
//@function Calculates Modified Adaptive Gaussian Moving Average
//@param src (float) Source series
//@param length (int) Lookback period
//@returns [float, float] Gaussian MA and smoothed Gaussian MA
GaussianMA(src, length) =>
h_l = array.new<float>(length)
float gma = 0.0
float sumOfWeights = 0.0
float sigma = (ta.atr(length) + ta.stdev(close, length)) / 2 // Volatility adaption
float highest = 0.0
float lowest = 0.0
float smoothed = 0.0
for i = 0 to length - 1 by 1
h_l.push(close[i])
highest := h_l.max()
lowest := h_l.min()
weight = math.exp(-math.pow((i - (length - 1)) / (2 * sigma), 2) / 2)
value = math.max(highest[i], highest) + math.min(lowest[i], lowest)
gma := gma + value * weight
sumOfWeights := sumOfWeights + weight
sumOfWeights
gma := gma / sumOfWeights / 2
smoothed := lowess(gma, 10)
[gma, smoothed]
[gma, smoothed] = GaussianMA(close, length)
smoothedColor = smoothed > smoothed[2] ? col_up : smoothed <= smoothed[2] ? col_dn : na
plot(smoothed, 'Trend- Pivot', smoothedColor)
/////////////////////////////
-
https://www.tradingview.com/x/JQ3iXDSm/ atr değerinde değişiklik yapılıp, yinelemeli denenebilir....
PHP Code:
//@version=6
indicator('ATR Based Zigzag w EMA', overlay = true)
// === Inputs ===
ATRLength = input(14, title = 'ATR Length')
ATRMult = input(5.0, title = 'ATR Multiplier')
lineSmoothLength = input(50, title = 'Line Smoothness (EMA Length)')
upTrendColor = input(color.rgb(0, 255, 132), title = 'Uptrend Line Color')
downTrendColor = input(color.rgb(255, 0, 0), title = 'Downtrend Line Color')
// === ATR Calculation ===
atr_val = ta.atr(ATRLength)
// === State Variables ===
var float LL = na
var float HH = na
var int trend = 1
// === Initialization ===
LL := na(LL[1]) ? low : LL[1]
HH := na(HH[1]) ? high : HH[1]
trend := na(trend[1]) ? 1 : trend[1]
// === Core Logic ===
if trend > 0 // Uptrend: looking for new swing low
if high >= HH
HH := high
HH
else
if low < HH - atr_val * ATRMult
trend := -1
LL := low
LL
else // Downtrend: looking for new swing high
if low <= LL
LL := low
LL
else
if high > LL + atr_val * ATRMult
trend := 1
HH := high
HH
// === Median Price (or pick a price base you prefer) ===
medianPrice = (high + low) / 2
// === Smoothed Line ===
smoothLine = ta.ema(medianPrice, lineSmoothLength)
// === Plotting the Clean Trend Line ===
plot(smoothLine, color = trend == 1 ? upTrendColor : downTrendColor, linewidth = 3, title = 'Trend Line')
// === (Optional) Bar Coloring Too ===
barcolor(trend == 1 ? upTrendColor : downTrendColor)