本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This work is licensed under an Attribution-ShareAlike 4.0 International License (CC BY-SA 4.0)
// https://creativecommons.org/licenses/by-sa/4.0/
// © Uptrick
//@version=6
// ██╗ ██╗██████╗ ████████╗██████╗ ██╗ ██████╗██╗ ██╗
// ██║ ██║██╔══██╗╚══██╔══╝██╔══██╗██║██╔════╝██║ ██╔╝
// ██║ ██║██████╔╝ ██║ ██████╔╝██║██║ █████╔╝
// ██║ ██║██╔═══╝ ██║ ██╔══██╗██║██║ ██╔═██╗
// ╚██████╔╝██║ ██║ ██║ ██║██║╚██████╗██║ ██╗
// ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═════╝╚═╝ ╚═╝
indicator(
"Uptrick: Adaptive Trend Matrix",
shorttitle="Adaptive Trend Matrix",
overlay=true,
max_labels_count=500
)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 01 · APPEARANCE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
gStyle = "01 · Appearance"
bullColor = input.color(
#00FFE5,
"Bullish Color",
group=gStyle,
tooltip="Bullish trail, candles, gradient and Buy signals."
)
bearColor = input.color(
#FF00B5,
"Bearish Color",
group=gStyle,
tooltip="Bearish trail, candles, gradient and Sell signals."
)
signalTextBull = input.color(
#000000,
"Buy Text",
group=gStyle
)
signalTextBear = input.color(
#FFFFFF,
"Sell Text",
group=gStyle
)
tpColor = input.color(
#FFFFFF,
"TP X Color",
group=gStyle,
tooltip="Color used for take-profit X markers."
)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 02 · TREND ENGINE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
gTrend = "02 · Trend Engine"
basisLength = input.int(
16,
"Trend Length",
minval=2,
group=gTrend,
tooltip="Lower values react faster. Higher values produce smoother and longer trend regimes."
)
smoothLength = input.int(
3,
"Smoothing",
minval=1,
group=gTrend,
tooltip="Additional smoothing applied to the trend basis and ATR."
)
atrLength = input.int(
10,
"ATR Length",
minval=2,
group=gTrend,
tooltip="Controls how quickly volatility reacts."
)
atrMultiplier = input.float(
1.8,
"Trail Distance",
minval=0.5,
step=0.1,
group=gTrend,
tooltip="Lower values create quicker trend switches. Higher values produce smoother trends."
)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 03 · SIGNALS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
gSignals = "03 · Signals"
showSignals = input.bool(
true,
"Show Buy / Sell",
group=gSignals,
tooltip="Show or hide Adaptive Trend Matrix Buy and Sell signals."
)
requiredConfirmations = input.int(
6,
"Required Confirmations",
minval=4,
maxval=10,
group=gSignals,
tooltip=
"Number of trend confirmations required before a signal can trigger.\n" +
"6 = balanced.\n" +
"7–8 = stricter."
)
adxMinimum = input.float(
15,
"Minimum ADX",
minval=0,
step=1,
group=gSignals,
tooltip="Minimum ADX required for DMI to count as a valid confirmation."
)
signalTrailATR = input.float(
0.5,
"Signal Trail Offset",
minval=0,
step=0.05,
group=gSignals,
tooltip=
"Buy = trail - ATR offset.\n" +
"Sell = trail + ATR offset."
)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 04 · TAKE PROFITS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
gTP = "04 · Take Profits"
showTP = input.bool(
true,
"Show TP Xs",
group=gTP
)
tp1ATR = input.float(
1.0,
"TP1 Distance",
minval=0.1,
step=0.1,
group=gTP,
tooltip="TP1 distance from entry measured in ATR."
)
tp2ATR = input.float(
2.0,
"TP2 Distance",
minval=0.1,
step=0.1,
group=gTP,
tooltip="TP2 distance from entry measured in ATR."
)
tp3ATR = input.float(
3.25,
"TP3 Distance",
minval=0.1,
step=0.1,
group=gTP,
tooltip="TP3 distance from entry measured in ATR."
)
tpXOffsetATR = input.float(
2.0,
"TP X Offset",
minval=0,
step=0.1,
group=gTP,
tooltip=
"Long TP X = high + ATR offset.\n" +
"Short TP X = low - ATR offset."
)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 05 · DISPLAY
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
gDisplay = "05 · Display"
showGradient = input.bool(
true,
"Vertical Gradient",
group=gDisplay
)
showCandles = input.bool(
true,
"Trend Candles",
group=gDisplay
)
gradientTransparency = input.int(
72,
"Gradient At Trail",
minval=0,
maxval=100,
group=gDisplay,
tooltip="Gradient opacity at the trail. It fades toward price."
)
trailTransparency = input.int(
30,
"Trail Transparency",
minval=0,
maxval=100,
group=gDisplay
)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// BASIS + ATR
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
basisRaw =
ta.ema(
hlc3,
basisLength
)
basis =
ta.ema(
basisRaw,
smoothLength
)
atrRaw =
ta.atr(
atrLength
)
atr =
ta.ema(
atrRaw,
smoothLength
)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// RATCHETING TRAILS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
longCandidate =
basis -
atr *
atrMultiplier
shortCandidate =
basis +
atr *
atrMultiplier
var float bullTrail = na
var float bearTrail = na
bullTrail :=
na(bullTrail[1]) ?
longCandidate :
math.max(
longCandidate,
bullTrail[1]
)
bearTrail :=
na(bearTrail[1]) ?
shortCandidate :
math.min(
shortCandidate,
bearTrail[1]
)
if not na(bullTrail[1]) and
close < bullTrail[1]
bullTrail :=
longCandidate
if not na(bearTrail[1]) and
close > bearTrail[1]
bearTrail :=
shortCandidate
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 01 · EMA STRUCTURE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
emaFast =
ta.ema(
close,
12
)
emaSlow =
ta.ema(
close,
34
)
emaBull =
emaFast >
emaSlow
emaBear =
emaFast <
emaSlow
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 02 · RSI
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
rsi =
ta.rsi(
close,
14
)
rsiBull =
rsi >
52
rsiBear =
rsi <
48
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 03 · MACD
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[macdLine, macdSignal, macdHist] =
ta.macd(
close,
12,
26,
9
)
macdBull =
macdLine >
macdSignal and
macdHist >
0
macdBear =
macdLine <
macdSignal and
macdHist <
0
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 04 · STOCHASTIC
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
stochK =
ta.stoch(
close,
high,
low,
14
)
stochD =
ta.sma(
stochK,
3
)
stochBull =
stochK >
stochD and
stochK >
45
stochBear =
stochK <
stochD and
stochK <
55
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 05 · CCI
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
cci =
ta.cci(
hlc3,
20
)
cciBull =
cci >
0
cciBear =
cci <
0
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 06 · DMI / ADX
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[plusDI, minusDI, adx] =
ta.dmi(
14,
14
)
dmiBull =
plusDI >
minusDI and
adx >=
adxMinimum
dmiBear =
minusDI >
plusDI and
adx >=
adxMinimum
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 07 · ROC
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
roc =
ta.roc(
close,
10
)
rocBull =
roc >
0
rocBear =
roc <
0
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 08 · MFI
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
mfi =
ta.mfi(
hlc3,
14
)
mfiBull =
mfi >
52
mfiBear =
mfi <
48
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 09 · OBV
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
obv =
ta.cum(
close > close[1] ?
volume :
close < close[1] ?
-volume :
0
)
obvEMA =
ta.ema(
obv,
14
)
obvBull =
obv >
obvEMA
obvBear =
obv <
obvEMA
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 10 · VWAP
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
vwapValue =
ta.vwap(
hlc3
)
vwapBull =
close >
vwapValue
vwapBear =
close <
vwapValue
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ADAPTIVE TREND MATRIX SCORE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
bullScore =
(emaBull ? 1 : 0) +
(rsiBull ? 1 : 0) +
(macdBull ? 1 : 0) +
(stochBull ? 1 : 0) +
(cciBull ? 1 : 0) +
(dmiBull ? 1 : 0) +
(rocBull ? 1 : 0) +
(mfiBull ? 1 : 0) +
(obvBull ? 1 : 0) +
(vwapBull ? 1 : 0)
bearScore =
(emaBear ? 1 : 0) +
(rsiBear ? 1 : 0) +
(macdBear ? 1 : 0) +
(stochBear ? 1 : 0) +
(cciBear ? 1 : 0) +
(dmiBear ? 1 : 0) +
(rocBear ? 1 : 0) +
(mfiBear ? 1 : 0) +
(obvBear ? 1 : 0) +
(vwapBear ? 1 : 0)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// TREND STATE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var int trend = 0
if trend == 0
trend :=
close >= basis ?
1 :
-1
bullBreak =
close >
bearTrail and
close >
basis
bearBreak =
close <
bullTrail and
close <
basis
rawBuy =
barstate.isconfirmed and
trend == -1 and
bullBreak and
bullScore >= requiredConfirmations
rawSell =
barstate.isconfirmed and
trend == 1 and
bearBreak and
bearScore >= requiredConfirmations
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// STRICT NO PYRAMIDING
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var int signalDirection = 0
buySignal =
rawBuy and
signalDirection != 1
sellSignal =
rawSell and
signalDirection != -1
if buySignal
trend := 1
signalDirection := 1
else if sellSignal
trend := -1
signalDirection := -1
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ACTIVE MATRIX TRAIL
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
activeTrail =
trend == 1 ?
bullTrail :
bearTrail
displayTrail =
trend == 1 ?
math.min(
activeTrail,
close - syminfo.mintick
) :
math.max(
activeTrail,
close + syminfo.mintick
)
trendColor =
trend == 1 ?
bullColor :
bearColor
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// TRADE STATE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var int tradeDirection = 0
var int signalBar = na
var float entryPrice = na
var float entryATR = na
var float tp1 = na
var float tp2 = na
var float tp3 = na
var bool tp1Hit = false
var bool tp2Hit = false
var bool tp3Hit = false
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// NEW LONG
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
if buySignal
tradeDirection := 1
signalBar := bar_index
entryPrice := close
entryATR := atr
tp1 :=
entryPrice +
entryATR *
tp1ATR
tp2 :=
entryPrice +
entryATR *
tp2ATR
tp3 :=
entryPrice +
entryATR *
tp3ATR
tp1Hit := false
tp2Hit := false
tp3Hit := false
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// NEW SHORT
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
if sellSignal
tradeDirection := -1
signalBar := bar_index
entryPrice := close
entryATR := atr
tp1 :=
entryPrice -
entryATR *
tp1ATR
tp2 :=
entryPrice -
entryATR *
tp2ATR
tp3 :=
entryPrice -
entryATR *
tp3ATR
tp1Hit := false
tp2Hit := false
tp3Hit := false
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// TAKE-PROFIT DETECTION
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
canCheckTP =
barstate.isconfirmed and
not na(signalBar) and
bar_index >
signalBar
longTP1 =
canCheckTP and
tradeDirection == 1 and
not tp1Hit and
high >= tp1
longTP2 =
canCheckTP and
tradeDirection == 1 and
not tp2Hit and
high >= tp2
longTP3 =
canCheckTP and
tradeDirection == 1 and
not tp3Hit and
high >= tp3
shortTP1 =
canCheckTP and
tradeDirection == -1 and
not tp1Hit and
low <= tp1
shortTP2 =
canCheckTP and
tradeDirection == -1 and
not tp2Hit and
low <= tp2
shortTP3 =
canCheckTP and
tradeDirection == -1 and
not tp3Hit and
low <= tp3
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// TP X POSITIONS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
longTPX =
high +
atr *
tpXOffsetATR
shortTPX =
low -
atr *
tpXOffsetATR
tp1X =
longTP1 ?
longTPX :
shortTP1 ?
shortTPX :
na
tp2X =
longTP2 ?
longTPX :
shortTP2 ?
shortTPX :
na
tp3X =
longTP3 ?
longTPX :
shortTP3 ?
shortTPX :
na
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// TP Xs
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
plotchar(
showTP ?
tp1X :
na,
"Adaptive Trend Matrix TP1",
char="X",
location=location.absolute,
color=tpColor,
size=size.tiny
)
plotchar(
showTP ?
tp2X :
na,
"Adaptive Trend Matrix TP2",
char="X",
location=location.absolute,
color=tpColor,
size=size.tiny
)
plotchar(
showTP ?
tp3X :
na,
"Adaptive Trend Matrix TP3",
char="X",
location=location.absolute,
color=tpColor,
size=size.tiny
)
if barstate.isconfirmed
if longTP1 or shortTP1
tp1Hit := true
if longTP2 or shortTP2
tp2Hit := true
if longTP3 or shortTP3
tp3Hit := true
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ADAPTIVE TREND MATRIX TRAIL
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
pTrend =
plot(
displayTrail,
"Adaptive Trend Matrix Trail",
color=color.new(
trendColor,
trailTransparency
),
linewidth=1,
style=plot.style_linebr
)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// INVISIBLE PRICE ANCHOR
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
pPrice =
plot(
close,
"Adaptive Trend Matrix Price Anchor",
color=color.new(
trendColor,
100
),
display=display.none
)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ADAPTIVE TREND MATRIX GRADIENT
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
gradientTop =
math.max(
close,
displayTrail
)
gradientBottom =
math.min(
close,
displayTrail
)
priceAboveTrail =
close >=
displayTrail
trailGradientColor =
color.new(
trendColor,
gradientTransparency
)
priceGradientColor =
color.new(
trendColor,
100
)
gradientTopColor =
priceAboveTrail ?
priceGradientColor :
trailGradientColor
gradientBottomColor =
priceAboveTrail ?
trailGradientColor :
priceGradientColor
fill(
pTrend,
pPrice,
gradientTop,
gradientBottom,
showGradient ?
gradientTopColor :
na,
showGradient ?
gradientBottomColor :
na,
title="Adaptive Trend Matrix Gradient"
)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ADAPTIVE TREND MATRIX CANDLES
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
plotcandle(
showCandles ?
open :
na,
showCandles ?
high :
na,
showCandles ?
low :
na,
showCandles ?
close :
na,
"Adaptive Trend Matrix Candles",
color=trendColor,
wickcolor=trendColor,
bordercolor=trendColor
)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SIGNAL ANCHORS
//
// BUY = TRAIL - 0.5 ATR
// SELL = TRAIL + 0.5 ATR
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
buyAnchor =
displayTrail -
atr *
signalTrailATR
sellAnchor =
displayTrail +
atr *
signalTrailATR
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// BUY
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
if showSignals and
buySignal
label.new(
bar_index,
buyAnchor,
"𝓑𝓾𝔂",
yloc=yloc.price,
style=label.style_label_up,
color=bullColor,
textcolor=signalTextBull,
size=size.normal,
tooltip=
"Adaptive Trend Matrix Buy\n\n" +
str.tostring(
bullScore
) +
"/10 confirmations"
)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SELL
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
if showSignals and
sellSignal
label.new(
bar_index,
sellAnchor,
"𝓢𝓮𝓵𝓵",
yloc=yloc.price,
style=label.style_label_down,
color=bearColor,
textcolor=signalTextBear,
size=size.normal,
tooltip=
"Adaptive Trend Matrix Sell\n\n" +
str.tostring(
bearScore
) +
"/10 confirmations"
)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// DATA WINDOW
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
plot(
bullScore,
"Adaptive Trend Matrix Bull Confirmations",
display=display.data_window
)
plot(
bearScore,
"Adaptive Trend Matrix Bear Confirmations",
display=display.data_window
)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ALERTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
alertcondition(
buySignal,
"Adaptive Trend Matrix Buy",
"Uptrick Adaptive Trend Matrix Buy on {{ticker}}"
)
alertcondition(
sellSignal,
"Adaptive Trend Matrix Sell",
"Uptrick Adaptive Trend Matrix Sell on {{ticker}}"
)
alertcondition(
longTP1 or shortTP1,
"Adaptive Trend Matrix TP1",
"Uptrick Adaptive Trend Matrix TP1 reached on {{ticker}}"
)
alertcondition(
longTP2 or shortTP2,
"Adaptive Trend Matrix TP2",
"Uptrick Adaptive Trend Matrix TP2 reached on {{ticker}}"
)
alertcondition(
longTP3 or shortTP3,
"Adaptive Trend Matrix TP3",
"Uptrick Adaptive Trend Matrix TP3 reached on {{ticker}}"
)