// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.
0
at [Link]
// © Spiel82
// This Pine Script™ code is subject to the terms of the Attribution-NonCommercial-
ShareAlike 4.0 International (CC BY-NC-SA 4.0)
[Link]
// © UAlgo
//@version=6
indicator('Breakout + Intraday + HTF MA', overlay = true, max_bars_back = 500,
max_lines_count = 500)
//@version=6
//indicator('Trend/Signals/TP+SL/Corr/Scalp [OWN]', shorttitle =
'Trend/Signals/TP+SL/Corr/Scalp [OWN]', overlay = true)
src = input(hl2, title = 'Source', group = 'Trend Continuation Signals with TP &
SL')
Multiplier = [Link](2, title = 'Sensitivity (0.5 - 5)', step = 0.1, minval =
0.5, maxval = 5, group = 'Trend Continuation Signals with TP & SL')
atrPeriods = [Link](14, title = 'ATR Length', group = 'Trend Continuation
Signals with TP & SL')
atrCalcMethod = [Link]('Method 1', title = 'ATR Calculation Methods', options
= ['Method 1', 'Method 2'], group = 'Trend Continuation Signals with TP & SL')
cloud_val = [Link](10, title = 'Cloud Moving Average Length', minval = 5, maxval
= 500, group = 'Trend Continuation Signals with TP & SL')
stopLossVal = [Link](2.0, title = 'Stop Loss Percent (0 for Disabling)',
minval = 0, group = 'Trend Continuation Signals with TP & SL')
showBuySellSignals = [Link](true, title = 'Show Buy/Sell Signals', group =
'Trend Continuation Signals with TP & SL')
showMovingAverageCloud = [Link](true, title = 'Show Cloud MA', group = 'Trend
Continuation Signals with TP & SL')
percent(nom, div) =>
100 * nom / div
src1 = [Link](open, 5)[1]
src2 = [Link](close, 12)
momm1 = [Link](src1)
momm2 = [Link](src2)
f1(m, n) =>
m >= n ? m : 0.0
f2(m, n) =>
m >= n ? 0.0 : -m
m1 = f1(momm1, momm2)
m2 = f2(momm1, momm2)
sm1 = [Link](m1, 1)
sm2 = [Link](m2, 1)
cmoCalc = percent(sm1 - sm2, sm1 + sm2)
hh = [Link](2)
h1 = bool([Link](hh, 2)) ? na : hh
hpivot = fixnan(h1)
ll = [Link](2)
l1 = bool([Link](ll, 2)) ? na : ll
lpivot = fixnan(l1)
rsiCalc = [Link](close, 9)
lowPivot = bool(lpivot)
highPivot = bool(hpivot)
sup = rsiCalc < 25 and cmoCalc > 50 and lowPivot
res = rsiCalc > 75 and cmoCalc < -50 and highPivot
atr2 = [Link]([Link], atrPeriods)
atr3 = atrCalcMethod == 'Method 1' ? [Link](atrPeriods) : atr2
up = src - Multiplier * atr3
up1 = nz(up[1], up)
up := close[1] > up1 ? [Link](up, up1) : up
dn = src + Multiplier * atr3
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? [Link](dn, dn1) : dn
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
buySignal = trend == 1 and trend[1] == -1
sellSignal = trend == -1 and trend[1] == 1
pos = 0.0
pos := buySignal ? 1 : sellSignal ? -1 : pos[1]
longCond = buySignal and pos[1] != 1
shortCond = sellSignal and pos[1] != -1
if buySignal
alert('buySignal', alert.freq_once_per_bar_close)
if sellSignal
alert('sellSignal', alert.freq_once_per_bar_close)
entryOfLongPosition = [Link](longCond, close, 0)
entryOfShortPosition = [Link](shortCond, close, 0)
sl = stopLossVal > 0 ? stopLossVal / 100 : 99999
stopLossForLong = entryOfLongPosition * (1 - sl)
stopLossForShort = entryOfShortPosition * (1 + sl)
takeProfitForLong1R = entryOfLongPosition * (1 + sl / 2)
takeProfitForShort1R = entryOfShortPosition * (1 - sl / 2)
takeProfitForLong2R = entryOfLongPosition * (1 + sl / 1.33)
takeProfitForShort2R = entryOfShortPosition * (1 - sl / 1.33)
takeProfitForLong3R = entryOfLongPosition * (1 + sl / 0.95)
takeProfitForShort3R = entryOfShortPosition * (1 - sl / 0.95)
long_sl = low < stopLossForLong and pos[1] == 1
short_sl = high > stopLossForShort and pos[1] == -1
takeProfitForLongFinal = high > takeProfitForLong3R and pos[1] == 1
takeProfitForShortFinal = low < takeProfitForShort3R and pos[1] == -1
if long_sl or short_sl or takeProfitForLongFinal or takeProfitForShortFinal
pos := 0
pos
lindex = [Link](longCond, bar_index, 0)
sindex = [Link](shortCond, bar_index, 0)
entryColor = pos == 1 ? [Link] : [Link]
if [Link] and pos != 0
lineEntry = [Link](bar_index, pos > 0 ? entryOfLongPosition :
entryOfShortPosition, pos > 0 ? lindex : sindex, pos > 0 ? entryOfLongPosition :
entryOfShortPosition, color = entryColor)
[Link](lineEntry[1])
stopLine = [Link](bar_index, pos > 0 ? stopLossForLong : stopLossForShort,
pos > 0 ? lindex : sindex, pos > 0 ? stopLossForLong : stopLossForShort, color =
[Link])
tpLine1 = [Link](bar_index, pos > 0 ? takeProfitForLong1R :
takeProfitForShort1R, pos > 0 ? lindex : sindex, pos > 0 ? takeProfitForLong1R :
takeProfitForShort1R, color = [Link])
tpLine2 = [Link](bar_index, pos > 0 ? takeProfitForLong2R :
takeProfitForShort2R, pos > 0 ? lindex : sindex, pos > 0 ? takeProfitForLong2R :
takeProfitForShort2R, color = [Link])
tpLine3 = [Link](bar_index, pos > 0 ? takeProfitForLong3R :
takeProfitForShort3R, pos > 0 ? lindex : sindex, pos > 0 ? takeProfitForLong3R :
takeProfitForShort3R, color = [Link])
[Link](stopLine[1])
[Link](tpLine1[1])
[Link](tpLine2[1])
[Link](tpLine3[1])
labelEntry = [Link](bar_index, pos > 0 ? entryOfLongPosition :
entryOfShortPosition, color = entryColor, textcolor = #000000, style =
label.style_label_left, text = 'Entry Price: ' + [Link](pos > 0 ?
entryOfLongPosition : entryOfShortPosition))
[Link](labelEntry[1])
labelStop = [Link](bar_index, pos > 0 ? stopLossForLong : stopLossForShort,
color = [Link], textcolor = #000000, style = label.style_label_left, text =
'(2%) Stop Loss Price: ' + [Link]([Link]((pos > 0 ? stopLossForLong :
stopLossForShort) * 100000) / 100000))
labelTp1 = [Link](bar_index, pos > 0 ? takeProfitForLong1R :
takeProfitForShort1R, color = [Link], textcolor = #000000, style =
label.style_label_left, text = '(1-1%) Take Profit: ' +
[Link]([Link]((pos > 0 ? takeProfitForLong1R : takeProfitForShort1R) *
100000) / 100000))
labelTp2 = [Link](bar_index, pos > 0 ? takeProfitForLong2R :
takeProfitForShort2R, color = [Link], textcolor = #000000, style =
label.style_label_left, text = '(2-1,5%) Take Profit: ' +
[Link]([Link]((pos > 0 ? takeProfitForLong2R : takeProfitForShort2R) *
100000) / 100000))
labelTp3 = [Link](bar_index, pos > 0 ? takeProfitForLong3R :
takeProfitForShort3R, color = [Link], textcolor = #000000, style =
label.style_label_left, text = '(3-2,1%) Take Profit: ' +
[Link]([Link]((pos > 0 ? takeProfitForLong3R : takeProfitForShort3R) *
100000) / 100000))
[Link](labelStop[1])
[Link](labelTp1[1])
[Link](labelTp2[1])
[Link](labelTp3[1])
changeCond = trend != trend[1]
smaSrcHigh = [Link](high, cloud_val)
smaSrcLow = [Link](low, cloud_val)
[macdLine, signalLine, histLine] = [Link](close, 12, 26, 9)
plot_high = plot(showMovingAverageCloud ? smaSrcHigh : na, color = na, editable =
false)
plot_low = plot(showMovingAverageCloud ? smaSrcLow : na, color = na, editable =
false)
plotshape(longCond ? up : na, title = 'UpTrend Begins', location =
[Link], style = [Link], size = [Link], color =
[Link]([Link], transp = 50))
plotshape(longCond and showBuySellSignals ? up : na, title = 'Buy', text = 'Buy
SIGNAL', location = [Link], style = [Link], size = [Link],
color = [Link]([Link], transp = 50), textcolor = [Link])
plotshape(shortCond ? dn : na, title = 'DownTrend Begins', location =
[Link], style = [Link], size = [Link], color =
[Link]([Link], transp = 50))
plotshape(shortCond and showBuySellSignals ? dn : na, title = 'Sell', text = 'Sell
SIGNAL', location = [Link], style = [Link], size = [Link],
color = [Link]([Link], transp = 50), textcolor = [Link])
fill(plot_high, plot_low, color = macdLine > 0 and macdLine[0] > macdLine[1] ?
[Link]([Link], transp = 85) : na, title = 'Positive Cloud Uptrend')
fill(plot_high, plot_low, color = macdLine > 0 and macdLine[0] < macdLine[1] ?
[Link]([Link], transp = 85) : na, title = 'Positive Cloud Downtrend')
fill(plot_high, plot_low, color = macdLine < 0 and macdLine[0] < macdLine[1] ?
[Link]([Link], transp = 85) : na, title = 'Negative Cloud Uptrend')
fill(plot_high, plot_low, color = macdLine < 0 and macdLine[0] > macdLine[1] ?
[Link]([Link], transp = 85) : na, title = 'Negative Cloud Downtrend')
mPlot = plot(ohlc4, title = '', style = plot.style_circles, linewidth = [Link](1,
0))
alertcondition(changeCond, title = 'Trend Direction Change ', message = 'Trend
direction has changed ! ')
alertLongTextID = '↑↑ BUY ↑↑ ' + ' < ' + [Link]([Link]) + ' > ' +
'Entry Price: ' + [Link](entryOfLongPosition) + ', Take Profit 1: ' +
[Link](takeProfitForLong1R) + ', Take Profit 2: ' +
[Link](takeProfitForLong2R) + ', Take Profit 3: ' +
[Link](takeProfitForLong3R) + ', Stop Loss Price: ' +
[Link](stopLossForLong)
alertShortTextID = '↓↓ SELL ↓↓ ' + ' < ' + [Link]([Link]) + ' > ' +
', Entry Price: ' + [Link](entryOfShortPosition) + ', Take Profit 1: ' +
[Link](takeProfitForShort1R) + ', Take Profit 2: ' +
[Link](takeProfitForShort2R) + ', Take Profit 3: ' +
[Link](takeProfitForShort3R) + ', Stop Loss Price: ' +
[Link](stopLossForShort)
longJsonID = alertLongTextID
shortJsonID = alertShortTextID
if longCond
alert(longJsonID, alert.freq_once_per_bar_close)
if shortCond
alert(shortJsonID, alert.freq_once_per_bar_close)
//LAZY SCALP BOX CODE//
setup_group = '████████ LAZY SCALP BOX CODE ████████'
avgVolLength = [Link](title = 'Avg Vol length', group = setup_group, defval =
30, minval = 3, maxval = 100, step = 1)
natrLength = [Link](title = 'NATR length', group = setup_group, defval = 14)
avgType = [Link]('EMA', 'Avg type', group = setup_group, options = ['SMA',
'EMA', 'RMA', 'WMA'])
position = [Link]('Right bottom', 'Board position', group = setup_group,
options = ['Right top', 'Right bottom', 'Center bottom', 'Left bottom', 'Left
top'])
cellWidth = [Link](8, 'Cell width', 1, 20, 1)
backColor = [Link](#434651, 'Cell Background color')
textColor = [Link]([Link], 'Cell Text color')
backColorAlert = [Link](#FBC02D, 'Cell Background color alert')
textColorAlert = [Link]([Link], 'Cell Text color alert')
showTitles = [Link](true, 'Show titles')
showDayVol = [Link](true, 'Show Day Volume')
showAvgVol = [Link](true, 'Show Avg Volume')
showNatr = [Link](true, 'Show NATR')
showCorr = [Link](true, 'Show Correlation')
showCorr2 = [Link](true, 'Show 2nd Correlation')
corrTicker = [Link]('BINANCE:BTCUSDT.P', 'Correlation symbol')
corrPeriod = [Link](title = 'Correlation period', defval = 20, step = 1)
corrTicker2 = [Link]('BINANCE:BTCUSDT.P', 'Correlation 2nd symbol')
corrPeriod2 = [Link](title = 'Correlation 2nd period', defval = 20, step = 1)
thresholdDayVol = [Link](title = 'Day VOL threshold ($)', defval = 100000000,
step = 1000000)
thresholdAvgVol = [Link](title = 'Avg VOL threshold ($)', defval = 3000000, step
= 100000)
thresholdNatr = [Link](title = 'NATR threshold', defval = 1, step = 0.1)
// Titles
dv = ''
av = ''
n = ''
c = ''
c2 = ''
if showTitles
dv := 'DV '
av := 'AV '
n := 'N '
c := 'BTC '
c2 := 'ETH '
c2
// FORMATTER
formater(data) =>
if [Link](data) > 11
[Link](data, 0, 3) + ' B'
else if [Link](data) > 10
[Link](data, 0, 2) + ' B'
else if [Link](data) > 9
[Link](data, 0, 1) + ' B'
else if [Link](data) > 8
[Link](data, 0, 3) + ' M'
else if [Link](data) > 7
[Link](data, 0, 2) + ' M'
else if [Link](data) > 6
[Link](data, 0, 1) + ' M'
else if [Link](data) > 5
[Link](data, 0, 3) + ' K'
else if [Link](data) > 4
[Link](data, 0, 2) + ' K'
else if [Link](data) > 3
[Link](data, 0, 1) + ' K'
// NART
natr = [Link]([Link](true), natrLength) / close * 100
if avgType == 'RMA'
natr := [Link]([Link](true), natrLength) / close * 100
natr
if avgType == 'SMA'
natr := [Link]([Link](true), natrLength) / close * 100
natr
if avgType == 'WMA'
natr := [Link]([Link](true), natrLength) / close * 100
natr
natrFormated = [Link]([Link](natr, 2))
// DAY VOLUME from different timeframe
d1 = [Link]([Link], '60', volume * close)
d2 = [Link]([Link], '60', volume[1] * close[1])
d3 = [Link]([Link], '60', volume[2] * close[2])
d4 = [Link]([Link], '60', volume[3] * close[3])
d5 = [Link]([Link], '60', volume[4] * close[4])
d6 = [Link]([Link], '60', volume[5] * close[5])
d7 = [Link]([Link], '60', volume[6] * close[6])
d8 = [Link]([Link], '60', volume[7] * close[7])
d9 = [Link]([Link], '60', volume[8] * close[8])
d10 = [Link]([Link], '60', volume[9] * close[9])
d11 = [Link]([Link], '60', volume[10] * close[10])
d12 = [Link]([Link], '60', volume[11] * close[11])
d13 = [Link]([Link], '60', volume[12] * close[12])
d14 = [Link]([Link], '60', volume[13] * close[13])
d15 = [Link]([Link], '60', volume[14] * close[14])
d16 = [Link]([Link], '60', volume[15] * close[15])
d17 = [Link]([Link], '60', volume[16] * close[16])
d18 = [Link]([Link], '60', volume[17] * close[17])
d19 = [Link]([Link], '60', volume[18] * close[18])
d20 = [Link]([Link], '60', volume[19] * close[19])
d21 = [Link]([Link], '60', volume[20] * close[20])
d22 = [Link]([Link], '60', volume[21] * close[21])
d23 = [Link]([Link], '60', volume[22] * close[22])
d24 = [Link]([Link], '60', volume[23] * close[23])
dayVolNumber = [Link](d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8 + d9 + d10 + d11 +
d12 + d13 + d14 + d15 + d16 + d17 + d18 + d19 + d20 + d21 + d22 + d23 + d24)
dayVol = [Link](dayVolNumber)
dayVol := formater(dayVol)
// AVG VOLUME
avgVolArr = array.new_float(1, volume * close)
for i = 1 to avgVolLength - 1 by 1
[Link](avgVolArr, volume[i] * close[i])
avgVolNumber = [Link]([Link](avgVolArr))
avgVol = [Link](avgVolNumber)
avgVol := formater(avgVol)
// CORRELATION
corrTickerData = [Link](corrTicker, '1', close)
corr = [Link]([Link](corrTickerData, close, corrPeriod), 2)
corrTickerData2 = [Link](corrTicker2, '1', close)
corr2 = [Link]([Link](corrTickerData2, close, corrPeriod2), 2)
// Styles
backColorDayVol = backColor
textColorDayVol = textColor
backColorAvgVol = backColor
textColorAvgVol = textColor
backColorNatr = backColor
textColorNatr = textColor
if dayVolNumber >= thresholdDayVol
backColorDayVol := backColorAlert
textColorDayVol := textColorAlert
textColorDayVol
if avgVolNumber >= thresholdAvgVol
backColorAvgVol := backColorAlert
textColorAvgVol := textColorAlert
textColorAvgVol
if natr >= thresholdNatr
backColorNatr := backColorAlert
textColorNatr := textColorAlert
textColorNatr
var tablePosition = position.top_right
if position == 'Right top'
tablePosition := position.top_right
tablePosition
if position == 'Right bottom'
tablePosition := position.bottom_right
tablePosition
if position == 'Center bottom'
tablePosition := position.bottom_center
tablePosition
if position == 'Left bottom'
tablePosition := position.bottom_left
tablePosition
if position == 'Left top'
tablePosition := position.top_left
tablePosition
// Render table
var infoTable = [Link](tablePosition, 1, 5, border_width = 1)
if [Link]
if showDayVol
[Link](infoTable, 0, 0, text = dv + [Link](dayVol), width =
cellWidth, bgcolor = backColorDayVol, text_color = textColorDayVol)
if showAvgVol
[Link](infoTable, 0, 1, text = av + [Link](avgVol), width =
cellWidth, bgcolor = backColorAvgVol, text_color = textColorAvgVol)
if showNatr
[Link](infoTable, 0, 2, text = n + natrFormated + ' %', width =
cellWidth, bgcolor = backColorNatr, text_color = textColorNatr)
if showCorr
[Link](infoTable, 0, 3, text = c + ' ' + [Link](corr), width =
cellWidth, bgcolor = backColor, text_color = textColor)
if showCorr2
[Link](infoTable, 0, 4, text = c2 + ' ' + [Link](corr2), width =
cellWidth, bgcolor = backColor, text_color = textColor)
//General inputs
setup_group1 = '████████ ITG Scalper_Early ████████'
len = input(14, group = setup_group1, title = 'TEMA period')
FfastLength = [Link](12, group = setup_group1, title = 'Filter fast length')
FslowLength = [Link](26, group = setup_group1, title = 'Filter slow length')
FsignalLength = [Link](9, group = setup_group1, title = 'Filter signal length')
// Validate input
if FfastLength < 1
FfastLength := 1
FfastLength
if FslowLength < 1
FslowLength := 1
FslowLength
if FsignalLength < 1
FsignalLength := 1
FsignalLength
//Get real close price
realC = close
//Triple EMA definition
ema1 = [Link](realC, len)
ema2 = [Link](ema1, len)
ema3 = [Link](ema2, len)
//Triple EMA trend calculation
avg = 3 * (ema1 - ema2) + ema3
//Filter formula
Fsource = close
FfastMA = [Link](Fsource, FfastLength)
FslowMA = [Link](Fsource, FslowLength)
Fmacd = FfastMA - FslowMA
Fsignal = [Link](Fmacd, FsignalLength)
//Entry & exit conditions
longSignal = [Link](Fmacd, Fsignal) and avg > avg[1]
shortSignal = [Link](Fmacd, Fsignal) and avg < avg[1]
// Plotting TEMA
plot(avg, title = 'TEMA', color = [Link], linewidth = 2)
// Plotting Buy and Sell signals
plotshape(series = longSignal, style = [Link], location =
[Link], color = [Link], size = [Link], title = 'Buy Signal')
plotshape(series = shortSignal, style = [Link], location =
[Link], color = [Link], size = [Link], title = 'Sell Signal')
// Alerts
alertcondition(longSignal, title = 'Buy Signal', message = 'Buy Signal')
alertcondition(shortSignal, title = 'Sell Signal', message = 'Sell Signal')
//indicator('Sup_Res/TRNDLN_Break/HTF_EMA (OWN)', overlay = true, max_bars_back =
500, max_lines_count = 500)
pivotCalc1 = [Link](10, 'lookback', minval = 5, group = 'Support/Resistance
Strength [UAlgo]')
maxPivotStored = [Link](10, 'Max Pivot Number Store', minval = 5, maxval = 100,
group = 'Support/Resistance Strength [UAlgo]')
channelStyle = [Link]('ATR', 'Type of channel', options = ['ATR', 'Percent'],
group = 'Support/Resistance Strength [UAlgo]')
minStrength = [Link](3, 'Minimum S/R Strength', minval = 2, group =
'Support/Resistance Strength [UAlgo]')
showLast = [Link](2, 'Show Last X S/R Lines', minval = 1, maxval = 10, group =
'Support/Resistance Strength [UAlgo]')
showSrPivots = [Link](true, 'Show S/R Pivot Points', group =
'Support/Resistance Strength [UAlgo]')
upColor = [Link]([Link]([Link], 20), 'Support/Resistance Color', group
= 'Support/Resistance Strength [UAlgo]', inline = 'c')
dnColor = [Link]([Link]([Link], 20), ' ', group = 'Support/Resistance
Strength [UAlgo]', inline = 'c')
ph = [Link](high, pivotCalc1, pivotCalc1)
pl = [Link](low, pivotCalc1, pivotCalc1)
type supportChannel
float top
float bot
int barStart
int barEnd
type resistanceChannel
float top
float bot
int barStart
int barEnd
var array<float> phVals = [Link]<float>()
var array<float> plVals = [Link]<float>()
var array<int> phIndex = [Link]<int>()
var array<int> plIndex = [Link]<int>()
var array<resistanceChannel> resistances = [Link]<resistanceChannel>()
var array<supportChannel> supports = [Link]<supportChannel>()
var array<line> supportLines = [Link]<line>()
var array<line> resistanceLines = [Link]<line>()
var array<label> supportLabels = [Link]<label>()
var array<label> resistanceLabels = [Link]<label>()
var float supportVal = na
var float resistanceVal = na
atr = [Link](200)
var array<float> array_atr = [Link]<float>()
for i = 1 to 200 by 1
if array_atr.size() > 199
array_atr.clear()
[Link](array_atr, atr[i])
float atrr = [Link](array_atr)
zonePercent = 1
tolerance = channelStyle == 'ATR' ? atr : 0
getModeWithMinCount(arr, channels, minCount, arrIndex) =>
float mostFrequentValue = na
int maxCount = 1
int mostFrequentIndex = -1
if [Link](arr) >= minCount
for i = [Link](arr) - 1 to 0 by 1
currentVal = [Link](arr, i)
currentIndex = [Link](arrIndex, i)
currentIndex := currentIndex / (time - time[1])
channelCount = 0
for j = [Link](channels) - 1 to 0 by 1
channel = [Link](channels, j)
if currentVal > [Link] and currentVal < [Link] and
[Link] / (time - time[1]) >= currentIndex
channelCount := channelCount + 1
channelCount
if channelCount >= minCount and channelCount > maxCount
maxCount := channelCount
mostFrequentValue := currentVal
mostFrequentIndex := i
mostFrequentIndex
[mostFrequentValue, maxCount, mostFrequentIndex]
createSupportZone(pivotPrice, barStart) =>
percentTolerance = channelStyle == 'Percent' ? pivotPrice * zonePercent / 100 :
tolerance
support = [Link](pivotPrice + percentTolerance, pivotPrice -
percentTolerance, barStart, time)
[Link](supports, support)
support
createResistanceZone(pivotPrice, barStart) =>
percentTolerance = channelStyle == 'Percent' ? pivotPrice * zonePercent / 100 :
tolerance
resistance = [Link](pivotPrice + percentTolerance, pivotPrice -
percentTolerance, barStart, time)
[Link](resistances, resistance)
resistance
if bool(ph)
[Link](high[pivotCalc1])
[Link](time[pivotCalc1])
createResistanceZone(high[pivotCalc1], time[pivotCalc1])
if bool(pl)
[Link](low[pivotCalc1])
[Link](time[pivotCalc1])
createSupportZone(low[pivotCalc1], time[pivotCalc1])
[supportMode, supportCount, supportIndex] = getModeWithMinCount(plVals, supports,
minStrength, plIndex)
[resistanceMode, resistanceCount, resistanceIndex] = getModeWithMinCount(phVals,
resistances, minStrength, phIndex)
supportVal := supportCount >= minStrength ? supportMode : supportVal
resistanceVal := resistanceCount >= minStrength ? resistanceMode : resistanceVal
calcPercentageDiff(current, level) =>
(current - level) / level * 100
manageLinesAndLabels(arr, maxSize) =>
while [Link](arr) > maxSize
firstItem = [Link](arr)
if not na(firstItem)
[Link]()
if [Link](supports) > 0 and supportVal != supportVal[1] and supportIndex >= 0
pivotTime = [Link](plIndex, supportIndex)
newLine = [Link](x1 = pivotTime, y1 = supportVal, x2 = time, y2 = supportVal,
xloc = xloc.bar_time, color = upColor)
[Link](supportLines, newLine)
percentDiff = calcPercentageDiff(close, supportVal)
labelText = [Link]('{0} ({1}%)', supportVal, [Link](percentDiff,
'#.##'))
newLabel = [Link](x = time, y = supportVal, text = labelText, xloc =
xloc.bar_time, style = label.style_label_left, color = [Link]([Link], 90),
textcolor = upColor)
[Link](supportLabels, newLabel)
manageLinesAndLabels(supportLines, showLast)
manageLinesAndLabels(supportLabels, showLast)
if [Link](resistances) > 0 and resistanceVal != resistanceVal[1] and
resistanceIndex >= 0
pivotTime = [Link](phIndex, resistanceIndex)
newLine = [Link](x1 = pivotTime, y1 = resistanceVal, x2 = time, y2 =
resistanceVal, xloc = xloc.bar_time, color = dnColor)
[Link](resistanceLines, newLine)
percentDiff = calcPercentageDiff(close, resistanceVal)
labelText = [Link]('{0} ({1}%)', resistanceVal, [Link](percentDiff,
'#.##'))
newLabel = [Link](x = time, y = resistanceVal, text = labelText, xloc =
xloc.bar_time, style = label.style_label_left, color = [Link]([Link], 90),
textcolor = dnColor)
[Link](resistanceLabels, newLabel)
manageLinesAndLabels(resistanceLines, showLast)
manageLinesAndLabels(resistanceLabels, showLast)
updateLinesAndLabels() =>
if [Link]() > 0
for i = 0 to [Link](supportLines) - 1 by 1
currentLine = [Link](supportLines, i)
currentLabel = [Link](supportLabels, i)
lineY = line.get_y1(currentLine)
if close > lineY
line.set_color(currentLine, upColor)
label.set_color(currentLabel, [Link]([Link], 90))
label.set_textcolor(currentLabel, upColor)
else
line.set_color(currentLine, dnColor)
label.set_color(currentLabel, [Link]([Link], 90))
label.set_textcolor(currentLabel, dnColor)
line.set_x2(currentLine, time)
label.set_x(currentLabel, time)
percentDiff = calcPercentageDiff(close, lineY)
labelText = [Link]('{0} ({1}%)', [Link](lineY, '#.0000'),
[Link](percentDiff, '#.##'))
label.set_text(currentLabel, labelText)
if [Link]() > 0
for i = 0 to [Link](resistanceLines) - 1 by 1
currentLine = [Link](resistanceLines, i)
currentLabel = [Link](resistanceLabels, i)
lineY = line.get_y1(currentLine)
if close > lineY
line.set_color(currentLine, upColor)
label.set_color(currentLabel, [Link]([Link], 90))
label.set_textcolor(currentLabel, upColor)
else
line.set_color(currentLine, dnColor)
label.set_color(currentLabel, [Link]([Link], 90))
label.set_textcolor(currentLabel, dnColor)
line.set_x2(currentLine, time)
label.set_x(currentLabel, time)
percentDiff = calcPercentageDiff(close, lineY)
labelText = [Link]('{0} ({1}%)', [Link](lineY, '#.0000'),
[Link](percentDiff, '#.##'))
label.set_text(currentLabel, labelText)
updateLinesAndLabels()
if [Link]() > maxPivotStored and [Link]() > maxPivotStored
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
plotshape(showSrPivots and not na(ph) ? high[pivotCalc1] : na, title = 'Resistance
Pivot', location = [Link], color = dnColor, style = [Link], size =
[Link], offset = -pivotCalc1)
plotshape(showSrPivots and not na(pl) ? low[pivotCalc1] : na, title = 'Support
Pivot', location = [Link], color = upColor, style = [Link], size =
[Link], offset = -pivotCalc1)
//ORDER BLOCKS//
//DELETED DUE TO TOO MANY NOTIFICATIONS//
//@version=5
//indicator("Trendline Breakouts With Targets [ Chartprime UPDATED
SIGNALS]",shorttitle = "TBT [ Chartprime UPDATED SIGNALS ]",overlay =
true,max_bars_back = 500,max_lines_count = 500)//
bool ChartTime = time > chart.left_visible_bar_time and time <
chart.right_visible_bar_time
string CORE = "➞ Core Settings 🔸"
var bool TradeisON = false
var bool LongTrade = false
var bool ShortTrade = false
var float TP = 0.0
var float SL = 0.0
int BarTIME = time - time[1]
var line tpLine = na
var line slLine = na
var label LAB = na
var label LABsl = na
var int UpdatedX = 0
var float UpdatedY = 0.0
var float UpdatedSLP = 0.0
var int UpdatedXLow = 0
var float UpdatedYLow = 0.0
var float UpdatedSLPLow = 0.0
int Period1 = [Link](10, title=' Period ➞',
group = CORE,
inline = "001")
bool Trendtype = [Link](title = " Type ➞",
defval='Wicks',
options=['Wicks', 'Body'],
group = CORE,
inline = "001")
== 'Wicks'
string Extensions = [Link](title=' Extend ➞',
defval=' 25',
options=[' 25', ' 50', ' 75'],
group = CORE,
inline = "001")
color LineCol1 = [Link]([Link](109, 111, 111, 19),"",group = CORE,inline =
"001")
bool ShowTargets = [Link](true,"Show Targets",group = CORE,inline = "002")
ExtenSwitcher(ex) =>
switch ex
' 25' => 1 ,
' 50' => 2 ,
=> 3
WidthSwitcher(ex) =>
switch ex
'1' => 1 ,
'2' => 2 ,
=> 3
StyleSwitcher(style) =>
switch style
'Dashed' => line.style_dashed ,
'Dotted' => line.style_dotted ,
=> line.style_solid
method volAdj(int len)=>
[Link]([Link](len) * 0.3, close * (0.3/100)) [20] /2
Zband = volAdj(30)
method Trendlines(float src, int timeIndex,bool dir) =>
var int Start = 1 , var int End = 0 , var int TIME = 1
var float YEnd = 0, var float YStart = 0 , var float Slope = 0
var line Line1 = [Link](na,na,na,na)
var line Line2 = [Link](na,na,na,na)
var line Line3 = [Link](na,na,na,na)
SCR = fixnan(src)
if [Link](SCR) != 0
TIME := time[timeIndex]
YStart := SCR[1]
Start := TIME[1]
Slope := (SCR - YStart) / (TIME - Start)
Slope
EXTime = ExtenSwitcher(Extensions) * BarTIME * 25
End := TIME + EXTime
YEnd := SCR + EXTime * Slope
if [Link](SCR) != 0 and not TradeisON[1]
LineCond = Slope * time < 0 ? dir ? na : [Link](11, 139, 7, 53) : dir ?
[Link](212, 46, 0, 54) : na
if not na(LineCond) //and ChartTime
Line1 := [Link](Start,
YStart,
End,
YEnd,
xloc.bar_time,
[Link],
color=[Link]([Link],100)
)
Line2:=[Link](Start,
YStart - (Zband * 2),
End,
YEnd - (Zband * 2),
xloc.bar_time,
[Link],
color=[Link]([Link],100)
)
Line3:=[Link](Start,
YStart - (Zband * 1),
End,
YEnd - (Zband * 1),
xloc.bar_time,
[Link],
color=[Link]([Link],100)
)
[Link](Line3,Line2,color= LineCol1)
[Link](Line3,Line1,color= LineCond)
// [Link](Line,Line2,color= [Link](28, 15, 2, 76))
[Start, YStart, Slope]
PH = [Link](Trendtype ? high : close > open ? close : open, Period1,
Period1 / 2)
PL = [Link](Trendtype ? low : close > open ? open : close, Period1, Period1 /
2)
method GetlinePrice(int TIME, float Price, float SLOP, int LookB) =>
var float Current = 0.0
EsTime = time - TIME
Current := Price + (EsTime - LookB * BarTIME) * SLOP
Current
method CheckCross(float Price, int StartTime, float StartPrice, float SLP) =>
var float Current = 0.0
var float Previous = 0.0
if StartPrice[Period1] != StartPrice
Current := GetlinePrice(StartTime, StartPrice, SLP, 0)
Previous := GetlinePrice(StartTime, StartPrice, SLP, 1)
Crossover = Price[1] < Previous and Price > Current ? 1 : Price[1] >
Previous - (Zband*0.1) and Price < Current - (Zband*0.1) ? -1 : 0
Crossover
[Xx, XZ, SLPXZ] = Trendlines(PH, Period1 / 2,false)
[XxL, XZL, SLPXZL] = Trendlines(PL, Period1 / 2, true)
if [Link](fixnan(PH)) != 0
UpdatedX := Xx
UpdatedY := XZ
UpdatedSLP := SLPXZ
UpdatedSLP
if [Link](fixnan(PL)) != 0
UpdatedXLow := XxL
UpdatedYLow := XZL
UpdatedSLPLow := SLPXZL
UpdatedSLPLow
Long = not (UpdatedSLP * time > 0)
and CheckCross(close, UpdatedX, UpdatedY, UpdatedSLP)== 1
and not TradeisON
Short = not (UpdatedSLPLow * time < 0)
and CheckCross(close, UpdatedXLow, UpdatedYLow, UpdatedSLPLow)==-1
and not TradeisON
TradeFire = Long or Short
if Long and not TradeisON
LongTrade:= true
ShortTrade:= false
if Short and not TradeisON
LongTrade:= false
ShortTrade:= true
if true
if TradeFire and not TradeisON
TP := switch
Long => high + (Zband *20)
Short => low - (Zband *20)
SL := switch
Long => low - (Zband *20)
Short => high + (Zband *20)
TradeisON:= true
if ShowTargets
[Link](bar_index,
Long ? high : low,
bar_index,
TP,
width=2,
color = #ffffff,
style= line.style_dashed)
tpLine:= [Link](bar_index,
TP,
bar_index+2,
TP,
style= line.style_dashed,
color = #ffffff
)
LAB:=[Link](bar_index,
TP,
"Target: "+ [Link]([Link]((TP),4)) +
", SL : " + [Link]([Link]((SL),4)),
color = [Link](154, 103, 20),
style= label.style_label_left,
size=[Link],
textcolor = [Link]
)
[Link](bar_index,
Long ? high : low,
bar_index,
SL,
width=2,
color = #ff0000,
style= line.style_dashed)
slLine:= [Link](bar_index,
SL,
bar_index+2,
SL,
style= line.style_dashed,
color = #ff0000
)
LABsl:=[Link](bar_index,
SL,
"StopLoss : " + [Link]([Link]((SL),4)),
color = #145e9a,
style= label.style_label_left,
size=[Link],
textcolor = [Link]
)
if TradeisON
line.set_x2(tpLine,bar_index)
label.set_x(LAB,bar_index+1)
line.set_x2(slLine,bar_index)
label.set_x(LABsl,bar_index+1)
if LongTrade and TradeisON
if high >= TP
label.set_color(LAB,[Link](6, 128, 10, 37))
label.set_color(LABsl,[Link](246, 7, 7,70))
TradeisON:=false
alert("Long Trade hit Target!")
if close <= SL
label.set_color(LAB,[Link]([Link](246, 7, 7),70))
label.set_color(LABsl,[Link]([Link](6, 128, 10), 37))
TradeisON:=false
alert("Long Trade hit Stoploss!")
else if ShortTrade and TradeisON
if low <= TP
label.set_color(LAB,[Link](6, 128, 10, 37))
label.set_color(LABsl,[Link](6, 128, 10, 37))
TradeisON:=false
alert("Short Trade hit Target!")
if close >= SL
label.set_color(LAB,[Link]([Link](246, 7, 7),70))
label.set_color(LABsl,[Link]([Link](6, 128, 10), 37))
TradeisON:=false
alert("Short Trade hit Stoploss!")
plotshape(Long and not TradeisON[1],
size = [Link],
color = [Link](46, 192, 6, 11),
location = [Link],
style = [Link] ,
text = "",
textcolor = [Link])
plotshape(Short and not TradeisON[1],
size = [Link],
color = [Link](241, 2, 2, 11),
location = [Link],
style = [Link] ,
text = "",
textcolor = [Link])
alertLongText = "↑↑ BUY ↑↑ " + " < " + [Link]([Link]) + " > " +
", Take Profit : " + [Link](TP) + " > " +
", SL : " + [Link](SL)
alertShortText = "↓↓ SELL ↓↓ " + " < " + [Link]([Link]) + " > " +
", Take Profit : " + [Link](TP) + " > " +
", SL : " + [Link](SL)
longJson = alertLongText
shortJson = alertShortText
if Long and not TradeisON[1]
alert(longJson, alert.freq_once_per_bar_close)
if Short and not TradeisON[1]
alert(shortJson, alert.freq_once_per_bar_close)
// -- END -- .
// © Julien_Eche
//@version=5
//indicator("Adaptive Trend Finder (log)", shorttitle='Adaptive Trend Finder',
overlay=true, max_bars_back=1200)//
confidence(pearsonR) =>
switch
pearsonR < 0.2 => "Extremely Weak"
pearsonR < 0.3 => "Very Weak"
pearsonR < 0.4 => "Weak"
pearsonR < 0.5 => "Mostly Weak"
pearsonR < 0.6 => "Somewhat Weak"
pearsonR < 0.7 => "Moderately Weak"
pearsonR < 0.8 => "Moderate"
pearsonR < 0.9 => "Moderately Strong"
pearsonR < 0.92 => "Mostly Strong"
pearsonR < 0.94 => "Strong"
pearsonR < 0.96 => "Very Strong"
pearsonR < 0.98 => "Exceptionally Strong"
=> "Ultra Strong"
getTablePosition(string pos) =>
switch pos
"Bottom Right" => position.bottom_right
"Bottom Center" => position.bottom_center
"Bottom Left" => position.bottom_left
"Top Right" => position.top_right
"Top Left" => position.top_left
"Top Center" => position.top_center
"Middle Right" => position.middle_right
=> position.middle_left // "Middle Left" - default
// Calculate deviations for given length
calcDev(float source, int length) =>
float logSource = [Link](source)
var int period_1 = length - 1
if [Link]
float sumX = 0.0
float sumXX = 0.0
float sumYX = 0.0
float sumY = 0.0
for int i=1 to length
float lSrc = logSource[i-1]
sumX += i
sumXX += i * i
sumYX += i * lSrc
sumY += lSrc
float slope = nz((length * sumYX - sumX * sumY) / (length * sumXX -
sumX * sumX))
float average = sumY / length
float intercept = average - (slope * sumX / length) + slope
float sumDev = 0.0
float sumDxx = 0.0
float sumDyy = 0.0
float sumDyx = 0.0
float regres = intercept + slope * period_1 * 0.5
float sumSlp = intercept
for int i=0 to period_1
float lSrc = logSource[i]
float dxt = lSrc - average
float dyt = sumSlp - regres
lSrc -= sumSlp
sumSlp += slope
sumDxx += dxt * dxt
sumDyy += dyt * dyt
sumDyx += dxt * dyt
sumDev += lSrc * lSrc
float unStdDev = [Link](sumDev / period_1) // unbiased
float divisor = sumDxx * sumDyy
float pearsonR = nz(sumDyx / [Link](divisor))
[unStdDev, pearsonR, slope, intercept]
else
[na, na, na, na]
string t1 = "In Long-Term Channel mode, if the channel is not visible, scroll back
on the chart for additional historical data. To view both Short-Term and Long-Term
channels simultaneously, load this indicator twice on your chart."
string t2 = "Displays the length of the period automatically selected by the
indicator that shows the strongest trend. This period is determined by identifying
the highest correlation between price movements and trend direction."
string t3 = "Pearson's R is a statistical measure that evaluates the linear
relationship between price movements and trend projection. A value closer to 1
indicates a strong positive correlation, increasing confidence in the trend
direction based on historical data."
string t4 = "Displays the annualized return (CAGR) of the trend over the auto-
selected period. This feature is available only for daily (D) and weekly (W)
timeframes, providing insight into the expected yearly growth rate if the trend
continues."
sourceInput = [Link](close, title="Source")
string group0 = "TREND CHANNEL SETTINGS"
bool periodMode = [Link] ( false, "Use Long-Term Channel",
group=group0, tooltip=t1)
float devMultiplier = [Link] ( 2.0, "Deviation Multiplier:",
group=group0, step=0.1)
color colorInput = [Link] ( [Link], "", group=group0,
inline=group0)
string lineStyle1 = [Link]( "Solid", "",
group=group0, inline=group0, options=["Solid", "Dotted", "Dashed"])
string extendStyle = [Link]("Extend Right", "",
group=group0, inline=group0, options=["Extend Right", "Extend Both", "Extend None",
"Extend Left"])
int fillTransparency = [Link] ( 93, "Fill Transp:",
group=group0, inline="mid", minval=0, maxval=100, step=1)
int channelTransparency = [Link] ( 40, "Line Transp:",
group=group0, inline="mid", minval=0, maxval=100, step=1)
string group1 = "MIDLINE SETTINGS"
color colorInputMidline = [Link] ( [Link], "", group=group1,
inline=group1)
int transpInput = [Link] ( 100, "Transp:", group=group1,
inline=group1, minval=0, maxval=100, step=10)
int lineWidth = [Link] ( 1, "Line Width:", group=group1,
inline=group1)
string midLineStyle = [Link]( "Dashed", "", group=group1,
inline=group1, options=["Dotted", "Solid", "Dashed"])
string group2 = "TABLE SETTINGS"
bool showAutoSelectedPeriod = input(true, "Show Auto-Selected Period",
group=group2, tooltip=t2)
bool showTrendStrength = input(true, "Show Trend Strength", group=group2,
inline="secondLine")
bool showPearsonInput = [Link](false, "Show Pearson's R",
group=group2, inline="secondLine", tooltip=t3)
bool showTrendAnnualizedReturn = input(true, "Show Trend Annualized Return",
group=group2, tooltip=t4)
string tablePositionInput = [Link]("Bottom Right", "Table Position",
options=["Bottom Right", "Bottom Left", "Middle Right", "Middle Left", "Top Right",
"Top Left", "Top Center", "Bottom Center"], group=group2, inline="fourthLine")
string textSizeInput = [Link]( "Normal", "Text Size",
options=["Normal", "Large", "Small"], group=group2, inline="fourthLine")
// Helper function to get the multiplier based on timeframe
get_tf_multiplier() =>
var float multiplier = 1.0
if [Link] == "crypto"
if [Link]
multiplier := 365 // ~365 trading days per year
else if [Link]
multiplier := 52 // 52 weeks per year
multiplier
else // Default for stocks and other asset types
if [Link]
multiplier := 252 // ~252 trading days per year
else if [Link]
multiplier := 52 // 52 weeks per year
multiplier
// Helper function to check if the timeframe is daily or weekly
is_valid_timeframe() =>
[Link] or [Link]
var string EXTEND_STYLE = switch extendStyle
"Extend Right" => [Link]
"Extend Both" => [Link]
"Extend None" => [Link]
=> [Link]
// Length Inputs
var array<int> Periods = periodMode ?
[Link](na,300,350,400,450,500,550,600,650,700,750,800,850,900,950,1000,1050,110
0,1150,1200) :
[Link](na,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200)
// Calculate deviations, correlation, slope, and intercepts for different lengths
[stdDev01, pearsonR01, slope01, intercept01] = calcDev(sourceInput,
[Link]( 1))
[stdDev02, pearsonR02, slope02, intercept02] = calcDev(sourceInput,
[Link]( 2))
[stdDev03, pearsonR03, slope03, intercept03] = calcDev(sourceInput,
[Link]( 3))
[stdDev04, pearsonR04, slope04, intercept04] = calcDev(sourceInput,
[Link]( 4))
[stdDev05, pearsonR05, slope05, intercept05] = calcDev(sourceInput,
[Link]( 5))
[stdDev06, pearsonR06, slope06, intercept06] = calcDev(sourceInput,
[Link]( 6))
[stdDev07, pearsonR07, slope07, intercept07] = calcDev(sourceInput,
[Link]( 7))
[stdDev08, pearsonR08, slope08, intercept08] = calcDev(sourceInput,
[Link]( 8))
[stdDev09, pearsonR09, slope09, intercept09] = calcDev(sourceInput,
[Link]( 9))
[stdDev10, pearsonR10, slope10, intercept10] = calcDev(sourceInput,
[Link](10))
[stdDev11, pearsonR11, slope11, intercept11] = calcDev(sourceInput,
[Link](11))
[stdDev12, pearsonR12, slope12, intercept12] = calcDev(sourceInput,
[Link](12))
[stdDev13, pearsonR13, slope13, intercept13] = calcDev(sourceInput,
[Link](13))
[stdDev14, pearsonR14, slope14, intercept14] = calcDev(sourceInput,
[Link](14))
[stdDev15, pearsonR15, slope15, intercept15] = calcDev(sourceInput,
[Link](15))
[stdDev16, pearsonR16, slope16, intercept16] = calcDev(sourceInput,
[Link](16))
[stdDev17, pearsonR17, slope17, intercept17] = calcDev(sourceInput,
[Link](17))
[stdDev18, pearsonR18, slope18, intercept18] = calcDev(sourceInput,
[Link](18))
[stdDev19, pearsonR19, slope19, intercept19] = calcDev(sourceInput,
[Link](19))
if [Link]
// Find the highest Pearson's R
float highestPearsonR = [Link](pearsonR01, pearsonR02, pearsonR03,
pearsonR04, pearsonR05, pearsonR06, pearsonR07, pearsonR08, pearsonR09, pearsonR10,
pearsonR11, pearsonR12, pearsonR13, pearsonR14, pearsonR15, pearsonR16, pearsonR17,
pearsonR18, pearsonR19)
// Determine selected length, slope, intercept, and deviations
int detectedPeriod = na
float detectedSlope = na
float detectedIntrcpt = na
float detectedStdDev = na
switch highestPearsonR
pearsonR01 =>
detectedPeriod := [Link](1)
detectedSlope := slope01
detectedIntrcpt := intercept01
detectedStdDev := stdDev01
pearsonR02 =>
detectedPeriod := [Link](2)
detectedSlope := slope02
detectedIntrcpt := intercept02
detectedStdDev := stdDev02
pearsonR03 =>
detectedPeriod := [Link](3)
detectedSlope := slope03
detectedIntrcpt := intercept03
detectedStdDev := stdDev03
pearsonR04 =>
detectedPeriod := [Link](4)
detectedSlope := slope04
detectedIntrcpt := intercept04
detectedStdDev := stdDev04
pearsonR05 =>
detectedPeriod := [Link](5)
detectedSlope := slope05
detectedIntrcpt := intercept05
detectedStdDev := stdDev05
pearsonR06 =>
detectedPeriod := [Link](6)
detectedSlope := slope06
detectedIntrcpt := intercept06
detectedStdDev := stdDev06
pearsonR07 =>
detectedPeriod := [Link](7)
detectedSlope := slope07
detectedIntrcpt := intercept07
detectedStdDev := stdDev07
pearsonR08 =>
detectedPeriod := [Link](8)
detectedSlope := slope08
detectedIntrcpt := intercept08
detectedStdDev := stdDev08
pearsonR09 =>
detectedPeriod := [Link](9)
detectedSlope := slope09
detectedIntrcpt := intercept09
detectedStdDev := stdDev09
pearsonR10 =>
detectedPeriod := [Link](10)
detectedSlope := slope10
detectedIntrcpt := intercept10
detectedStdDev := stdDev10
pearsonR11 =>
detectedPeriod := [Link](11)
detectedSlope := slope11
detectedIntrcpt := intercept11
detectedStdDev := stdDev11
pearsonR12 =>
detectedPeriod := [Link](12)
detectedSlope := slope12
detectedIntrcpt := intercept12
detectedStdDev := stdDev12
pearsonR13 =>
detectedPeriod := [Link](13)
detectedSlope := slope13
detectedIntrcpt := intercept13
detectedStdDev := stdDev13
pearsonR14 =>
detectedPeriod := [Link](14)
detectedSlope := slope14
detectedIntrcpt := intercept14
detectedStdDev := stdDev14
pearsonR15 =>
detectedPeriod := [Link](15)
detectedSlope := slope15
detectedIntrcpt := intercept15
detectedStdDev := stdDev15
pearsonR16 =>
detectedPeriod := [Link](16)
detectedSlope := slope16
detectedIntrcpt := intercept16
detectedStdDev := stdDev16
pearsonR17 =>
detectedPeriod := [Link](17)
detectedSlope := slope17
detectedIntrcpt := intercept17
detectedStdDev := stdDev17
pearsonR18 =>
detectedPeriod := [Link](18)
detectedSlope := slope18
detectedIntrcpt := intercept18
detectedStdDev := stdDev18
=> // pearsonR19
detectedPeriod := [Link](19)
detectedSlope := slope19
detectedIntrcpt := intercept19
detectedStdDev := stdDev19
var line upperLine = na, var linefill upperFill = na
var line baseLine = na
var line lowerLine = na, var linefill lowerFill = na
// Calculate start and end price based on detected slope and intercept
float startPrice = [Link](detectedIntrcpt + detectedSlope * (detectedPeriod -
1))
float endPrice = [Link](detectedIntrcpt)
int startAtBar = bar_index - detectedPeriod + 1
var color ChannelColor = [Link](colorInput, channelTransparency)
if na(baseLine)
baseLine := [Link](startAtBar, startPrice, bar_index, endPrice,
width=lineWidth, extend=EXTEND_STYLE,
color=[Link](colorInputMidline, transpInput),
style=midLineStyle == "Dotted" ? line.style_dotted :
midLineStyle == "Dashed" ? line.style_dashed :
line.style_solid)
else
line.set_xy1(baseLine, startAtBar, startPrice)
line.set_xy2(baseLine, bar_index, endPrice)
float upperStartPrice = startPrice * [Link](devMultiplier * detectedStdDev)
float upperEndPrice = endPrice * [Link](devMultiplier * detectedStdDev)
if na(upperLine)
upperLine := [Link](startAtBar, upperStartPrice, bar_index,
upperEndPrice,
width=1, extend=EXTEND_STYLE,
color=ChannelColor,
style=lineStyle1 == "Dotted" ? line.style_dotted :
lineStyle1 == "Dashed" ? line.style_dashed :
line.style_solid)
else
line.set_xy1 (upperLine, startAtBar, upperStartPrice)
line.set_xy2 (upperLine, bar_index, upperEndPrice)
line.set_color(upperLine, colorInput)
float lowerStartPrice = startPrice / [Link](devMultiplier * detectedStdDev)
float lowerEndPrice = endPrice / [Link](devMultiplier * detectedStdDev)
if na(lowerLine)
lowerLine := [Link](startAtBar, lowerStartPrice, bar_index,
lowerEndPrice,
width=1, extend=EXTEND_STYLE,
color=ChannelColor,
style=lineStyle1 == "Dotted" ? line.style_dotted :
lineStyle1 == "Dashed" ? line.style_dashed :
line.style_solid)
else
line.set_xy1 (lowerLine, startAtBar, lowerStartPrice)
line.set_xy2 (lowerLine, bar_index, lowerEndPrice)
line.set_color(lowerLine, colorInput)
if na(upperFill)
upperFill := [Link](upperLine, baseLine, color=[Link](colorInput,
fillTransparency))
if na(lowerFill)
lowerFill := [Link](baseLine, lowerLine, color=[Link](colorInput,
fillTransparency))
var table t = na
if periodMode
t := [Link](position.bottom_center, 2, 3)
else
t := [Link](getTablePosition(tablePositionInput), 2, 3)
string text1 = periodMode ? "Auto-Selected Period (Long Term): " +
[Link](detectedPeriod) : "Auto-Selected Period: " +
[Link](detectedPeriod)
var colorInputLight = [Link](colorInput, 0)
// Display or hide the "Auto-Selected Period" cell
if showAutoSelectedPeriod
[Link](t, 0, 0, text1, text_color=colorInputLight,
text_size=textSizeInput == "Large" ? [Link] : textSizeInput == "Small" ?
[Link] : [Link])
// Display or hide the "Trend Strength" or "Pearson's R" cell
if showTrendStrength
if showPearsonInput
[Link](t, 0, 1, "Pearson's R: " + [Link](detectedSlope >
0.0 ? -highestPearsonR : highestPearsonR, "#.###"), text_color=colorInput,
text_size=textSizeInput == "Large" ? [Link] : textSizeInput == "Small" ?
[Link] : [Link])
else
[Link](t, 0, 1, "Trend Strength: " + confidence(highestPearsonR),
text_color=colorInput, text_size=textSizeInput == "Large" ? [Link] :
textSizeInput == "Small" ? [Link] : [Link])
// Calculate CAGR
float cagr = na
if not na(detectedPeriod) and bar_index >= detectedPeriod and
is_valid_timeframe()
float num_of_periods = detectedPeriod
float multiplier = get_tf_multiplier()
float startClosePrice = close[detectedPeriod - 1]
cagr := [Link](close / startClosePrice, multiplier / num_of_periods) - 1
// Display or hide the "Trend Annualized Return" cell
if showTrendAnnualizedReturn and is_valid_timeframe()
[Link](t, 0, 2, "Trend Annualized Return: " + (not na(cagr) ?
[Link](cagr * 100, "#.#") + "%" : "N/A"), text_color=colorInput,
text_size=textSizeInput == "Large" ? [Link] : textSizeInput == "Small" ?
[Link] : [Link])
// HIGHER TIMEFRAME EMA //
//@version=6
//indicator(title = 'Higher Timeframe EMA (HTF EMA)', shorttitle = 'EMA+', overlay
= true)
// Get user input
res1 = [Link](title = 'EMA Timeframe', defval = 'D', group = 'Higher
Timeframe EMA (HTF EMA)')
len1 = [Link](title = 'EMA Length', defval = 25, group = 'Higher Timeframe EMA
(HTF EMA)')
col = [Link](title = 'Color EMA', defval = true, group = 'Higher Timeframe EMA
(HTF EMA)')
smooth = [Link](title = 'Smooth', defval = true, group = 'Higher Timeframe EMA
(HTF EMA)')
// Calculate EMA
ema = [Link](close, len1)
emaStep = [Link]([Link], res1, ema[[Link] ? 1 :
0])[[Link] ? 0 : 1]
emaSmooth = [Link]([Link], res1, ema[[Link] ? 1 :
0], gaps = barmerge.gaps_on)[[Link] ? 0 : 1]
// Draw EMA
plot(smooth ? emaSmooth : emaStep, color = col ? close > emaStep ? [Link] :
[Link] : [Link], linewidth = 2, title = 'HTF EMA')
//@version=6
//indicator('Trend Continuation Signals [AlgoAlpha]', shorttitle = 'AlgoAlpha - ♾️
Continuation Signals', overlay = true, timeframe = '', timeframe_gaps = false)
mult = input(2.0, 'Volatility Bands Multiplier', group = 'Trend Continuation
Signals')
reductionFactor = input(6.0, 'Volatility Bands reductionFactor', tooltip =
'Increase this to make the bands thinner', group = 'Trend Continuation Signals')
malen = [Link](93, 'Trend Period', group = 'Trend Continuation Signals')
malen1 = [Link](50, 'Fast Length', group = 'Trend Continuation Signals')
green = input(#00ffbb, group = 'Trend Continuation Signals')
red = input(#ff1100, group = 'Trend Continuation Signals')
v1 = [Link](hl2, malen)
v2 = [Link](close, malen1)
dev = mult * [Link](hl2, malen)
upper = v1 + dev
lower = v1 - dev
dev1 = mult / reductionFactor * [Link](upper, malen)
upperu = upper + dev1
loweru = upper - dev1
dev2 = mult / reductionFactor * [Link](lower, malen)
upperl = lower + dev2
lowerl = lower - dev2
uptrend = v1 > v1[1]
downtrend = v1 < v1[1]
neutral = uptrend and v2 < v1 or downtrend and v2 > v1
plot(v1, color = neutral ? [Link] : downtrend ? red : uptrend ? green : na,
linewidth = 3, title = 'Trend')
plot(v2, display = [Link])
u = plot(upper, color = [Link])
l = plot(lower, color = [Link])
u1 = plot(upperu, color = [Link](red, 50))
u2 = plot(loweru, color = [Link](red, 90))
l11 = plot(upperl, color = [Link](green, 90))
l2 = plot(lowerl, color = [Link](green, 50))
plotchar(uptrend and [Link](close, v2), 'Bullish Continuation', '▲',
[Link], green, size = [Link])
plotchar(downtrend and [Link](close, v2), 'Bearish Continuation', '▼',
[Link], red, size = [Link])
//bgcolor(uptrend and hl2 < v1 ? [Link](green, 90) : downtrend and hl2 > v1 ?
[Link](red, 90) : na)
//fill(u1, u, [Link](red, 50))
//fill(u2, u, [Link](red, 90))
//fill(l11, l, [Link](green, 90))
//fill(l2, l, [Link](green, 50))
//Alerts
//alertcondition(uptrend and [Link](close, v2), 'Bullish Continuation',
'Bullish Continuation Signal')
//alertcondition(downtrend and [Link](close, v2), 'Bearish Continuation',
'Bearish Continuation Signal')
//alertcondition([Link](v1, v1[1]), 'Bullish Trend', 'Bullish Trend Signal')
//alertcondition([Link](v1, v1[1]), 'Bearish Trend', 'Bearish Trend Signal')