[go: up one dir, main page]

0% found this document useful (0 votes)
112 views19 pages

Elite Algo

The document contains a TradingView Pine Script for an indicator called 'Elitealgo' which calculates various volatility measures using different methods such as Parkinson, Garman-Klass, and Yang-Zhang. It includes user inputs for customization, functions for calculating volatility, and options for displaying results on charts. Additionally, it provides a warning about potential scammers and includes contact information for the creators.

Uploaded by

leoaviator117
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views19 pages

Elite Algo

The document contains a TradingView Pine Script for an indicator called 'Elitealgo' which calculates various volatility measures using different methods such as Parkinson, Garman-Klass, and Yang-Zhang. It includes user inputs for customization, functions for calculating volatility, and options for displaying results on charts. Additionally, it provides a warning about potential scammers and includes contact information for the creators.

Uploaded by

leoaviator117
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 19

//@version=5

indicator("Elitealgo", shorttitle="EA v30", overlay=true, precision=0,


explicit_plot_zorder=true, max_labels_count=500)

// ─────────────────────────────────────────────────────────────
// This code is created by AlgoPoint. All other leaked algos are available at:
// Website: algopoint.mysellix.io
// Contact: algopointstore@gmail.com
// Discord: algopoint
// Instagram: algopoint / algopoint01
// ─────────────────────────────────────────────────────────────

// ⚠️ Scammer List:
// Discord Username: nedenolmuyor (ZZ_Algo)
// Discord Username: rayyav (MAD MAD) — Also Eyo Breakout Telegram Admin. Be
careful.

// ─────────────────────────────────────────────────────────────
// User Inputs & Display Settings
// ─────────────────────────────────────────────────────────────

title = "AlgoPoint"
subtitle = "All Leaked Algos | IG: algopoint"

symInfoCheck = false
symInfo = syminfo.ticker + " | " + timeframe.period +
(timeframe.isminutes ? "M" : "")
date = str.tostring(dayofmonth(time_close)) + "/" +
str.tostring(month(time_close)) + "/" + str.tostring(year(time_close))

textVPosition = "middle"
textHPosition = "center"
symVPosition = "top"
symHPosition = "left"

width = 0
height = 0

c_title = #b2b5be80
s_title = "large"
a_title = "center"

c_subtitle = #b2b5be80
s_subtitle = "normal"
a_subtitle = "center"

c_bg = color.new(color.blue, 100)

// ─────────────────────────────────────────────────────────────
// Volatility Calculator Function
// ─────────────────────────────────────────────────────────────

f_coc(x, period, sqrtAnnual) =>


mean = ta.sma(x, period)
s = array.new_float(0)
for i = 0 to period - 1
array.push(s, math.pow(x[i] - mean, 2))
sqrtAnnual * math.sqrt(array.sum(s) / (period - 1))
// ─────────────────────────────────────────────────────────────
// Parkinson Volatility
// ─────────────────────────────────────────────────────────────
f_park(period, sqrtAnnual) =>
var LOG2 = math.log(2)
powLogHighLow = math.pow(math.log(high / low), 2)
sqrtAnnual * math.sqrt(1.0 / period * math.sum(1.0 / (4.0 * LOG2) *
powLogHighLow, period))

// ─────────────────────────────────────────────────────────────
// Garman-Klass Volatility
// ─────────────────────────────────────────────────────────────
f_gk(period, sqrtAnnual) =>
var LOG2 = math.log(2)
var SQRT_1_PERIOD = math.sqrt(1 / period)
powLogHighLow = math.pow(math.log(high / low), 2)
powLogCloseOpen = math.pow(math.log(close / open), 2)
tmp = 0.5 * powLogHighLow - (2.0 * LOG2 - 1.0) * powLogCloseOpen
sqrtAnnual * math.sqrt(math.sum(tmp, period)) * SQRT_1_PERIOD

// ─────────────────────────────────────────────────────────────
// Rogers-Satchell Volatility
// ─────────────────────────────────────────────────────────────
f_rsv(period, sqrtAnnual) =>
tmp = math.log(high / close) * math.log(high / open) + math.log(low / close) *
math.log(low / open)
sqrtAnnual * math.sqrt(math.sum(tmp, period) / period)

// ─────────────────────────────────────────────────────────────
// Garman-Klass Yang-Zhang Extension Volatility
// ─────────────────────────────────────────────────────────────
f_gkyz(period, sqrtAnnual) =>
var LOG2 = math.log(2)
var SQRT_1_PERIOD = math.sqrt(1 / period)
powLogHighLow = math.pow(math.log(high / low), 2)
powLogCloseOpen = math.pow(math.log(close / open), 2)
lastClose = nz(close[1], close)
powLogOpenClose1 = math.pow(math.log(open / lastClose), 2)
tmp = powLogOpenClose1 + 0.5 * powLogHighLow - (2.0 * LOG2 - 1.0) *
powLogCloseOpen
sqrtAnnual * math.sqrt(math.sum(tmp, period)) * SQRT_1_PERIOD

// ─────────────────────────────────────────────────────────────
// Yang-Zhang Volatility
// ─────────────────────────────────────────────────────────────
f_yz(a, period, sqrtAnnual) =>
oaman = math.log(open) - math.log(nz(close[1], close))
u = math.log(high) - math.log(open)
d = math.log(low) - math.log(open)
caman = math.log(close) - math.log(open)
nMinusOne = period - 1
avgo = ta.sma(oaman, period)
avgc = ta.sma(caman, period)
so = array.new_float(0)
sc = array.new_float(0)
for i = 0 to period - 1
array.push(so, math.pow(oaman[i] - avgo, 2))
array.push(sc, math.pow(caman[i] - avgc, 2))
sumo = array.sum(so)
sumc = array.sum(sc)
Vo = sumo / nMinusOne
Vc = sumc / nMinusOne
Vrs = math.sum(u * (u - caman) + d * (d - caman), period) / period
k = (a - 1.0) / (a + (period + 1.0) / nMinusOne)
sqrtAnnual * math.sqrt(Vo + k * Vc + (1.0 - k) * Vrs)

// ─────────────────────────────────────────────────────────────
// Exponentially Weighted Volatility
// ─────────────────────────────────────────────────────────────
f_ewma(source, period, sqrtAnnual) =>
var lambda = (period - 1) / (period + 1)
squared = math.pow(source, 2)
float v = na
v := lambda * nz(v[1], squared) + (1.0 - lambda) * squared
sqrtAnnual * math.sqrt(v)

// ─────────────────────────────────────────────────────────────
// Mean Absolute Deviation (Adjusted)
// ─────────────────────────────────────────────────────────────
f_mad(source, period, sqrtAnnual) =>
var SQRT_HALF_PI = math.sqrt(math.asin(1))
mean = ta.sma(source, period)
S = array.new_float(0)
for i = 0 to period - 1
array.push(S, math.abs(source[i] - mean))
sumS = array.sum(S)
sqrtAnnual * (sumS / period) * SQRT_HALF_PI

// ─────────────────────────────────────────────────────────────
// Median Absolute Deviation
// ─────────────────────────────────────────────────────────────
f_mead(source, period, sqrtAnnual) =>
median = ta.percentile_nearest_rank(source, period, 50)
E = 0.0
for i = 0 to period - 1
E += math.abs(source[i] - median)
sqrtAnnual * math.sqrt(2) * (E / period)

// ─────────────────────────────────────────────────────────────
// Rescale Function
// ─────────────────────────────────────────────────────────────
f_rescale(_src, _size) =>
math.max(0, math.min(_size, int(_src / 100 * _size)))

// ─────────────────────────────────────────────────────────────
// Label Panel Function
// ─────────────────────────────────────────────────────────────
_label(T, color_PnL) =>
label PnL_Label = na
label.delete(PnL_Label[1])
PnL_Label := label.new(time, 0, text=T, color=color_PnL, textcolor=color.white,
size=size.normal, style=label.style_label_left, xloc=xloc.bar_time,
textalign=text.align_left)
label.set_x(PnL_Label, label.get_x(PnL_Label) + math.round(ta.change(time) *
3))

// ─────────────────────────────────────────────────────────────
// Round Function
// ─────────────────────────────────────────────────────────────
Round(src, digits) =>
p = math.pow(10, digits)
math.round(math.abs(src) * p) / p * math.sign(src)

// ─────────────────────────────────────────────────────────────
// Options for Inputs
// ─────────────────────────────────────────────────────────────

ON = 'On'
OFF = 'Off'

CTC = 'Close to Close'


PKS = 'Parkinson'
GK = 'Garman Klass'
RS = 'Rogers Satchell'
GKYZ = 'Garman Klass Yang Zhang Extension'
YZ = 'Yang Zhang'
EWMA = 'EWMA'
MAD = 'Mean Absolute Deviation'
MAAD = 'Median Absolute Deviation'

// ─────────────────────────────────────────────────────────────
// Chart Style Options
// ─────────────────────────────────────────────────────────────
L = 'Line'
SL = 'StepLine'
Ar = 'Area'
CL = 'Columns'

// ─────────────────────────────────────────────────────────────
// Settings
// ─────────────────────────────────────────────────────────────

Haman = input.string(EWMA, 'Volatility Method', options=[CTC, PKS, RS, GK, GKYZ,


YZ, EWMA, MAD, MAAD])
period = input.int(10, 'Period', minval=1, maxval=500)
Annual = input.int(365, 'Annual Days', minval=1, maxval=500)
a = input.float(1.34, 'Alpha', minval=0.1, maxval=5.0, step=0.01)
Plen = input.int(365, 'Percentile Length', minval=1, maxval=500)
Pco = input.bool(true, 'Color Output')
sma = input.bool(true, 'Show SMA')
malen = input.int(55, 'MA Length', minval=1, maxval=500)
bsg = input.bool(false, 'Background Signals')
stl = input.string(CL, 'Style', options=[L, SL, Ar, CL])
lT = input.int(3, 'Line Thickness', minval=1, maxval=5)
i_invert= input.bool(false, 'Invert Colors')
bg = input.bool(false, 'Dark Background')
sp = input.bool(false, 'Show Panel')

// Optional background styling


bgcolor(bg ? color.new(#000000, 90) : na, title='Dark Background')

// ─────────────────────────────────────────────────────────────
// Volatility Calculations
// ─────────────────────────────────────────────────────────────

sqrtAnnual = math.sqrt(Annual) * 100


logr = math.log(close / close[1])
Hv = Haman == CTC ? f_coc(logr, period, sqrtAnnual) :
Haman == PKS ? f_park(period, sqrtAnnual) :
Haman == RS ? f_rsv(period, sqrtAnnual) :
Haman == GK ? f_gk(period, sqrtAnnual) :
Haman == GKYZ ? f_gkyz(period, sqrtAnnual) :
Haman == EWMA ? f_ewma(logr, period, sqrtAnnual) :
Haman == YZ ? f_yz(a, period, sqrtAnnual) :
Haman == MAD ? f_mad(logr, period, sqrtAnnual) :
f_mead(logr, period, sqrtAnnual)

// ─────────────────────────────────────────────────────────────
// Plot Style & Watermark
// ─────────────────────────────────────────────────────────────

pstyle = stl == L ? plot.style_linebr : stl == SL ? plot.style_stepline : stl ==


Ar ? plot.style_area : stl == CL ? plot.style_columns : plot.style_line

textWatermark = table.new(textVPosition + "_" + textHPosition, 1, 3)

// ─────────────────────────────────────────────────────────────
// HV Statistics
// ─────────────────────────────────────────────────────────────

avgHV = ta.sma(Hv, malen)


HVP = ta.percentrank(Hv, Plen)
NearZero = HVP < 1.5 ? 1 : 0
HV50 = ta.percentile_nearest_rank(Hv, Plen, 50)

// ─────────────────────────────────────────────────────────────
// Text Functions
// ─────────────────────────────────────────────────────────────

texthv() =>
' HV: ' + str.tostring(Round(Hv, 2))

textphv() =>
'HV 50 Percentile: ' + str.tostring(Round(HV50, 2))

texthvp() =>
'HV Percentile: ' + str.tostring(Round(HVP, 2)) + '%'

// ─────────────────────────────────────────────────────────────
// Coloring Gradient
// ─────────────────────────────────────────────────────────────

c_ = array.new_color()
array.push(c_, #0effff)
array.push(c_, #00fdf6)
array.push(c_, #00fbee)
array.push(c_, #00f9e4)
array.push(c_, #00f6db)
array.push(c_, #00f4d1)
array.push(c_, #13f1c6)
array.push(c_, #24efbc)
array.push(c_, #31ecb1)
array.push(c_, #3ce9a6)
array.push(c_, #47e69b)
array.push(c_, #51e390)
array.push(c_, #5adf85)
array.push(c_, #62dc7a)
array.push(c_, #6ad96e)
array.push(c_, #72d563)
array.push(c_, #7ad157)
array.push(c_, #81cd4b)
array.push(c_, #88ca3f)
array.push(c_, #8fc532)
array.push(c_, #96c123)
array.push(c_, #9cbd0e)
array.push(c_, #a3b800)
array.push(c_, #a9b300)
array.push(c_, #b0ae00)
array.push(c_, #b6a900)
array.push(c_, #bca300)
array.push(c_, #c29e00)
array.push(c_, #c89800)
array.push(c_, #ce9100)
array.push(c_, #d48b00)
array.push(c_, #da8400)
array.push(c_, #df7c00)
array.push(c_, #e57400)
array.push(c_, #ea6c00)
array.push(c_, #ef6200)
array.push(c_, #f35800)
array.push(c_, #f74c00)
array.push(c_, #fb3e00)
array.push(c_, #ff2d00)

if i_invert
array.reverse(c_)

sizeOf = array.size(c_) - 1
colorHV = Pco ? array.get(c_, f_rescale(HVP, sizeOf)) : color.aqua

// ─────────────────────────────────────────────────────────────
// Plots
// ─────────────────────────────────────────────────────────────

plot(Hv, 'HV', color=colorHV, linewidth=lT, style=pstyle)


plot(sma ? avgHV : na, 'sma', color=color.new(#FFFFFF, 25), linewidth=2)
bgcolor(Hv > avgHV ? color.lime : na)

if sp
_label(symInfo + texthv() + '\n' + textphv() + '\n' + texthvp() + '\n\n',
#000000c0)

col2 = HVP >= 1 ? color.yellow : HVP >= 0.5 ? color.orange : #8D0000


bgcolor(bsg and NearZero ? col2 : na)

// ─────────────────────────────────────────────────────────────
// Custom MAS Levels
// ─────────────────────────────────────────────────────────────

maa = avgHV / 100 * 140


mab = avgHV / 100 * 180
mac = avgHV / 100 * 240
mad = avgHV / 100 * 60
mae = avgHV / 100 * 20

// ─────────────────────────────────────────────────────────────
// Auto Sensitivity Volatility Band Settings
// ─────────────────────────────────────────────────────────────

float volatility = 0.0

if Hv < maa and Hv > avgHV


volatility := 6
else if Hv < mab and Hv > maa
volatility := 7
else if Hv < mac and Hv > mab
volatility := 7.8
else if Hv > mac
volatility := 9
else if Hv < maa and Hv > mad
volatility := 5
else if Hv < mad and Hv > mae
volatility := 4
else if Hv < mae
volatility := 3

// ─────────────────────────────────────────────────────────────
// Optional Plots
// ─────────────────────────────────────────────────────────────

plot(volatility, 'Volatility', color=color.red)


plot(maa, 'maa', color=color.new(color.aqua, 25))
plot(mab, 'mab', color=color.new(color.aqua, 25))
plot(mac, 'mac', color=color.new(color.aqua, 25))
plot(mad, 'mad', color=color.new(color.aqua, 25))
plot(mae, 'mae', color=color.new(color.aqua, 25))

// basic settings

signalPreset = input.string('None', 'Signal Preset', ['None', 'Trend Only'],


group='basic settings')

signalLogic = input.string('Pro Scalper', 'Signal Logic', ['Pro Scalper',


'Normal'], group='basic settings')

signalStyle = input.string('Normal', 'Signal Style', ['Normal', 'Minimal'],


group='basic settings')

signalAgility = input.string('Auto Pilot', 'Agility%', ['Auto Pilot',


'Manual'], group='basic settings')

signalMode = signalStyle == 'Normal' ? 'Simple Entry + Exits' : 'Minimized


Entry + Exits'

normalsensitivity = input.float(15, "Normal Sensitivity", 5.1, 50.1,


step=0.1, group="basic settings", tooltip='Change Your Signal Sensitivity And
Accuracy')

sensitivity = input.float(5, "Pro Scalper Sensitivity", 0.6, 15.1, step=0.1,


group="basic settings", tooltip='Change Your Signal Sensitivity And Accuracy')

strongSignalOnly = signalPreset == 'Trend Only' ? true : false


noRepainting = true

auto_button = signalAgility == 'Auto Pilot' ? true : false

// basic chart features

normalsignalsmode = normalsensitivity / 4.4

normalsignalvolatility = volatility - 1.7

if signalLogic == 'Pro Scalper'


sensitivity := sensitivity
else if signalLogic == 'Normal'
sensitivity := normalsignalsmode

if signalLogic == 'Pro Scalper'


volatility := volatility
else if signalLogic == 'Normal'
volatility := normalsignalvolatility

if auto_button == false
sensitivity := sensitivity
else if auto_button == true
sensitivity := volatility

// Feature Toggles and Inputs


ReversalCloud = input.bool(false, 'Reversal Cloud', group='basic chart features')
LongTrendAverage = input.bool(false, 'Long Trend Average', group='basic chart
features', tooltip='Places a reversal channel in which reversals can be predicted.\
n\nTrend Cloud Line (EMA) will be shown on the chart')
ReversalBands = input.bool(false, 'Reversal Bands', group='basic chart features')
TrendTracer = true
frequencyCloud = input.bool(false, 'Frequency Cloud', group='basic chart features',
tooltip='Displays short trend cloud')
CandleColor = input.string('Gradient Confirmation', 'Candle Stick Coloring',
options=['Gradient Confirmation', 'Off'], group='basic chart features')
Plot_MAs = input.bool(true, 'Trend Cloud', group='basic chart features')

// ─────────────────────────────────────────────────────────────
// EK Cloud — Moving Average Engine
// ─────────────────────────────────────────────────────────────

// ---- User Settings ----


Timeframe = ''
Repaint = false
MA_T1 = "Ehlers Kaufman"
MA_S1_Input = close
MA_L1 = 200
MA_T2 = "Ehlers Kaufman"
MA_S2_Input = close
MA_L2 = 350

MA_S1 = request.security(syminfo.tickerid, Timeframe, MA_S1_Input[Repaint ? 0 :


barstate.isrealtime ? 1 : 0])[Repaint ? 0 : barstate.isrealtime ? 0 : 1]
MA_S2 = request.security(syminfo.tickerid, Timeframe, MA_S2_Input[Repaint ? 0 :
barstate.isrealtime ? 1 : 0])[Repaint ? 0 : barstate.isrealtime ? 0 : 1]

// ---- Moving Averages ----


MA_1 = if MA_T1 == "Simple"
ta.sma(MA_S1, MA_L1)
else if MA_T1 == "Exponential"
ta.ema(MA_S1, MA_L1)
else if MA_T1 == "Double Exponential"
2 * ta.ema(MA_S1, MA_L1) - ta.ema(ta.ema(MA_S1, MA_L1), MA_L1)
else if MA_T1 == "Triple Exponential"
3 * (ta.ema(MA_S1, MA_L1) - ta.ema(ta.ema(MA_S1, MA_L1), MA_L1)) +
ta.ema(ta.ema(ta.ema(MA_S1, MA_L1), MA_L1), MA_L1)
else if MA_T1 == "Quadruple Exponential"
5 * ta.ema(MA_S1, MA_L1) - 10 * ta.ema(ta.ema(MA_S1, MA_L1), MA_L1) + 10 *
ta.ema(ta.ema(ta.ema(MA_S1, MA_L1), MA_L1), MA_L1) - 5 *
ta.ema(ta.ema(ta.ema(ta.ema(MA_S1, MA_L1), MA_L1), MA_L1), MA_L1) +
ta.ema(ta.ema(ta.ema(ta.ema(ta.ema(MA_S1, MA_L1), MA_L1), MA_L1), MA_L1), MA_L1)
else if MA_T1 == "Weighted"
ta.wma(MA_S1, MA_L1)
else if MA_T1 == "Volume-weighted"
ta.vwma(MA_S1, MA_L1)
else if MA_T1 == "Hull"
ta.hma(MA_S1, MA_L1)
else if MA_T1 == "Symmetrical"
ta.swma(MA_S1)
else if MA_T1 == "Arnaud Legoux"
ta.alma(MA_S1, MA_L1, 0.85, 6)
else if MA_T1 == "Least Squares"
ta.linreg(MA_S1, MA_L1, 0)
else if MA_T1 == "Relative Strength"
ta.rma(MA_S1, MA_L1)
else if MA_T1 == "Welles Wilder"
Wilder_MA1 = 0.0
Wilder_MA1 := 1 / MA_L1 * MA_S1 + (1 - 1 / MA_L1) * nz(Wilder_MA1[1])
Wilder_MA1
else if MA_T1 == "Triangular"
ta.sma(ta.sma(MA_S1, MA_L1), MA_L1)
else
KA_D1 = 0.0
for i = 0 to 79
KA_D1 += math.abs(nz(MA_S1[i]) - nz(MA_S1[i + 1]))
KA_EF1 = KA_D1 != 0 ? math.min(math.abs(MA_S1 - nz(MA_S1[79])) / KA_D1, 1) : 0
KAMA1 = 0.0
KAMA1 := math.pow((0.6667 * KA_EF1) + 0.0645, 2) * MA_S1 + (1 -
math.pow((0.6667 * KA_EF1) + 0.0645, 2)) * nz(KAMA1[1])
KAMA1

MA_2 = if MA_T2 == "Simple"


ta.sma(MA_S2, MA_L2)
else if MA_T2 == "Exponential"
ta.ema(MA_S2, MA_L2)
else if MA_T2 == "Double Exponential"
2 * ta.ema(MA_S2, MA_L2) - ta.ema(ta.ema(MA_S2, MA_L2), MA_L2)
else if MA_T2 == "Triple Exponential"
3 * (ta.ema(MA_S2, MA_L2) - ta.ema(ta.ema(MA_S2, MA_L2), MA_L2)) +
ta.ema(ta.ema(ta.ema(MA_S2, MA_L2), MA_L2), MA_L2)
else if MA_T2 == "Quadruple Exponential"
5 * ta.ema(MA_S2, MA_L2) - 10 * ta.ema(ta.ema(MA_S2, MA_L2), MA_L2) + 10 *
ta.ema(ta.ema(ta.ema(MA_S2, MA_L2), MA_L2), MA_L2) - 5 *
ta.ema(ta.ema(ta.ema(ta.ema(MA_S2, MA_L2), MA_L2), MA_L2), MA_L2) +
ta.ema(ta.ema(ta.ema(ta.ema(ta.ema(MA_S2, MA_L2), MA_L2), MA_L2), MA_L2), MA_L2)
else if MA_T2 == "Weighted"
ta.wma(MA_S2, MA_L2)
else if MA_T2 == "Volume-weighted"
ta.vwma(MA_S2, MA_L2)
else if MA_T2 == "Hull"
ta.hma(MA_S2, MA_L2)
else if MA_T2 == "Symmetrical"
ta.swma(MA_S2)
else if MA_T2 == "Arnaud Legoux"
ta.alma(MA_S2, MA_L2, 0.85, 6)
else if MA_T2 == "Least Squares"
ta.linreg(MA_S2, MA_L2, 0)
else if MA_T2 == "Relative Strength"
ta.rma(MA_S2, MA_L2)
else if MA_T2 == "Welles Wilder"
Wilder_MA2 = 0.0
Wilder_MA2 := 1 / MA_L2 * MA_S2 + (1 - 1 / MA_L2) * nz(Wilder_MA2[1])
Wilder_MA2
else if MA_T2 == "Triangular"
ta.sma(ta.sma(MA_S2, MA_L2), MA_L2)
else
KA_D2 = 0.0
for i = 0 to 134
KA_D2 += math.abs(nz(MA_S2[i]) - nz(MA_S2[i + 1]))
KA_EF2 = KA_D2 != 0 ? math.min(math.abs(MA_S2 - nz(MA_S2[134])) / KA_D2, 1) : 0
KAMA2 = 0.0
KAMA2 := math.pow((0.6667 * KA_EF2) + 0.0645, 2) * MA_S2 + (1 -
math.pow((0.6667 * KA_EF2) + 0.0645, 2)) * nz(KAMA2[1])
KAMA2

// ---- Plotting ----


MA_Color = Plot_MAs ? MA_1 > MA_2 ? color.new(#04994b, 80) : color.new(#b4060d, 80)
: na

P1 = plot(Plot_MAs ? MA_1 : na, title="Fast MA", color=MA_Color)


P2 = plot(Plot_MAs ? MA_2 : na, title="Slow MA", color=MA_Color)

table.cell(textWatermark, 0, 0, title, width, height, c_title, a_title,


text_size=s_title, bgcolor=c_bg)

fill(P1, P2, color=MA_Color)

// ─────────────────────────────────────────────────────────────
// Buy & Sell Signal Logic
// ─────────────────────────────────────────────────────────────

src = close

// Smooth Range Function


smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x[1]), t)
ta.ema(avrng, wper) * m

smrng = smoothrng(close, 100, sensitivity)

// Range Filter Function


rngfilt(x, r) =>
rngfilt = x
rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x - r
:
x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r
rngfilt

filt = rngfilt(src, smrng)

// Trend Counters
upward = 0.0
upward := filt > filt[1] ? nz(upward[1]) + 1 : filt < filt[1] ? 0 : nz(upward[1])

downward = 0.0
downward := filt < filt[1] ? nz(downward[1]) + 1 : filt > filt[1] ? 0 :
nz(downward[1])

// Keltner Channels
[mi, u, lo] = ta.kc(close, 90, 6.8)
[mid, upp, loww] = ta.kc(close, 90, 5.3)
[midd, ups, lowe] = ta.kc(close, 90, 4)

// Trend Cloud Comparison


shorttop = ta.sma(close, 13)
longtop = ta.ema(close, 65)
eq_cloud_is_bullish = shorttop > longtop

// Filter Bands
hband = filt + smrng
lband = filt - smrng

// Entry Conditions
longCond = bool(na)
shortCond = bool(na)

longCond := (src > filt and src > src[1] and upward > 0) or (src > filt and src <
src[1] and upward > 0)

shortCond := (src < filt and src < src[1] and downward > 0) or
(src < filt and src > src[1] and downward > 0)

// Signal State
CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]

// ─────────────────────────────────────────────────────────────
// Candle Rating — Trend Confidence Engine
// ─────────────────────────────────────────────────────────────

// CCI
TM_Long = ta.cci(close, 20) > 50
TM_Short = ta.cci(close, 20) < -50

// ADX
lenadx = 21
lensig = 21
limadx = 34

ADX_up = ta.change(high)
ADX_down = -ta.change(low)
trur = ta.rma(ta.tr, lenadx)
plus = fixnan(100 * ta.rma(ADX_up > ADX_down and ADX_up > 0 ? ADX_up : 0,
lenadx) / trur)
minus = fixnan(100 * ta.rma(ADX_down > ADX_up and ADX_down > 0 ? ADX_down : 0,
lenadx) / trur)

sum = plus + minus


adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)

macol = adx > limadx and plus > minus ? color.lime : adx > limadx and plus <
minus ? color.red : color.black

ADX_Long = adx > limadx and plus > minus


ADX_Short = adx > limadx and plus < minus

// Accumulation/Distribution
ACC_Dist = ta.sma(ta.accdist, 21)
ACC_Long = ta.accdist > ACC_Dist
ACC_Short = ta.accdist < ACC_Dist

// MFI
MFI = ta.mfi(close, 14)
MFI_SMA = ta.sma(MFI, 9)
MFI_Long = MFI > MFI_SMA
MFI_Short= MFI < MFI_SMA

// Momentum Linear Regression


mom = ta.mom(close, 21)
lrmom = ta.linreg(mom, 28, 0)

MOML_Long = lrmom > lrmom[1]


MOML_Short = lrmom < lrmom[1]

// ─────────────────────────────────────────────────────────────
// Entry Conditions
// ─────────────────────────────────────────────────────────────

entry_long = true
entry_short = entry_long // Same condition reused

// Signal Strength Counters


var Long_Signal_Strength = 0
var Short_Signal_Strength = 0

if entry_long
Long_Signal_Strength := 0
if TM_Long
Long_Signal_Strength += 1
if ADX_Long
Long_Signal_Strength += 1
if ACC_Long
Long_Signal_Strength += 1
if MFI_Long
Long_Signal_Strength += 1
if MOML_Long
Long_Signal_Strength += 1

if entry_short
Short_Signal_Strength := 0
if TM_Short
Short_Signal_Strength += 1
if ADX_Short
Short_Signal_Strength += 1
if ACC_Short
Short_Signal_Strength += 1
if MFI_Short
Short_Signal_Strength += 1
if MOML_Short
Short_Signal_Strength += 1

// ─────────────────────────────────────────────────────────────
// Trend Detecting — Settings & Global Variables
// ─────────────────────────────────────────────────────────────

// Settings
length = input.int(20, 'Length', minval=1, maxval=100)
incr = input.int(100, 'Increment', minval=1, maxval=200)
resetOn = input.string('CHoCH', 'Reset On', options=['CHoCH', 'Other'])
showMS = input.bool(false, 'Show MS')

// Style
bullCss = input.color(color.teal, 'Bullish Color')
bearCss = input.color(color.red, 'Bearish Color')
retCss = input.color(#ff5d00, 'Retrace Color')
areaTransp = input.int(100, 'Area Transparency', minval=0, maxval=100)

// Global Variables
var float ph_y = na
var int ph_x = na

var float pl_y = na


var int pl_x = na

var float topaman = na


var float btmaman = na

var bool ph_cross = false


var bool pl_cross = false

var float maxaman = na


var float minaman = na
var float ts = na

var int os = 0
var int ms = 0

// ─────────────────────────────────────────────────────────────
// Detect Pivots and Get Coordinates
// ─────────────────────────────────────────────────────────────

n = bar_index

ph = ta.pivothigh(length, length)
pl = ta.pivotlow(length, length)

if not na(ph)
ph_y := ph
ph_x := n - length
ph_cross := false
if not na(pl)
pl_y := pl
pl_x := n - length
pl_cross := false

// ─────────────────────────────────────────────────────────────
// Bullish Structures
// ─────────────────────────────────────────────────────────────

if close > ph_y and not ph_cross


ms := resetOn == 'CHoCH' ? (os == -1 ? 1 : 0) : 1
ph_cross := true

if showMS
line.new(ph_x, ph_y, n, ph_y, color=bullCss, style=os == -1 ?
line.style_dashed : line.style_dotted)

os := 1

// Search for local minima


btmaman := low
for i = 0 to (n - ph_x) - 1
btmaman := math.min(low[i], btmaman)

// ─────────────────────────────────────────────────────────────
// Bearish Structures
// ─────────────────────────────────────────────────────────────

if close < pl_y and not pl_cross


ms := resetOn == 'CHoCH' ? (os == 1 ? -1 : 0) : -1
pl_cross := true

if showMS
line.new(pl_x, pl_y, n, pl_y, color=bearCss, style=os == 1 ?
line.style_dashed : line.style_dotted)

os := -1

// Search for local maxima


topaman := high
for i = 0 to (n - pl_x) - 1
topaman := math.max(high[i], topaman)

// ─────────────────────────────────────────────────────────────
// Trailing Stop Logic
// ─────────────────────────────────────────────────────────────

// Trailing max/min
if ms == 1
maxaman := close
else if ms == -1
minaman := close
else
maxaman := math.max(close, maxaman)
minaman := math.min(close, minaman)

// Trailing stop calculation


ts := ms == 1 ? btmaman :
ms == -1 ? topaman :
os == 1 ? ts + (maxaman - maxaman[1]) * incr / 100 :
ts + (minaman - minaman[1]) * incr / 100

// ─────────────────────────────────────────────────────────────
// Plot Styling
// ─────────────────────────────────────────────────────────────

cssaman = not na(ms) and ms != 0 ? na : os == 1 ? bullCss : bearCss

// ─────────────────────────────────────────────────────────────
// Buy/Sell Signal Conditions
// ─────────────────────────────────────────────────────────────

buyCond = longCond and CondIni[1] == -1 and cssaman == bearCss


strongBuyCond1 = longCond and CondIni[1] == -1 and cssaman == bullCss
sellCond = shortCond and CondIni[1] == 1 and cssaman == bullCss
strongSellCond1 = shortCond and CondIni[1] == 1 and cssaman == bearCss

// ─────────────────────────────────────────────────────────────
// Signal Strength Text Labels
// ─────────────────────────────────────────────────────────────

enter_pluslong = str.tostring(Long_Signal_Strength)
enter_plussell = str.tostring(Short_Signal_Strength)
enter_longtrt = str.tostring(Long_Signal_Strength)
enter_selltrtt = str.tostring(Short_Signal_Strength)

smartbuysigtex = "Strong\n" + str.tostring(Long_Signal_Strength) + "★"


smartbuyminimal = "▲+\n" + str.tostring(Long_Signal_Strength) + "★"

smartselsigtex = str.tostring(Short_Signal_Strength) + "★\nStrong"


smartselminimal = str.tostring(Short_Signal_Strength) + "★\n▼+"

buysigtex = "Buy\n" + str.tostring(Long_Signal_Strength) + "★"


buyminimal = "▲\n" + str.tostring(Long_Signal_Strength) + "★"

selsigtex = str.tostring(Short_Signal_Strength) + "★\nSell"


selsminimal = str.tostring(Short_Signal_Strength) + "★\n▼"

// ─────────────────────────────────────────────────────────────
// Repainting Filter
// ─────────────────────────────────────────────────────────────
if noRepainting
buyCond := buyCond and barstate.isconfirmed
strongBuyCond1 := strongBuyCond1 and barstate.isconfirmed
sellCond := sellCond and barstate.isconfirmed
strongSellCond1 := strongSellCond1 and barstate.isconfirmed

// ─────────────────────────────────────────────────────────────
// Buy Signal Labels
// ─────────────────────────────────────────────────────────────
BuySignal = signalMode == 'Simple Entry + Exits' and buyCond and not
strongSignalOnly ? label.new(bar_index, low, buysigtex, xloc.bar_index,
yloc.belowbar, #00cf4b8c,
label.style_label_up, color.white, size.normal) : na

MinimalBuy = signalMode == 'Minimized Entry + Exits' and buyCond and not


strongSignalOnly ? label.new(bar_index, low, buyminimal, xloc.bar_index,
yloc.belowbar, #00cf4b8c,
label.style_label_up, color.white, size.normal) : na

StrongBuy = signalMode == 'Simple Entry + Exits' and strongBuyCond1 ?


label.new(bar_index, low, smartbuysigtex, xloc.bar_index, yloc.belowbar, #00cf4b8c,
label.style_label_up, color.white, size.normal) : na

MinimalStrongBuy = signalMode == 'Minimized Entry + Exits' and strongBuyCond1 ?


label.new(bar_index, low, smartbuyminimal, xloc.bar_index, yloc.belowbar,
#00cf4b8c,
label.style_label_up, color.white, size.normal) : na

// ─────────────────────────────────────────────────────────────
// Sell Signal Labels
// ─────────────────────────────────────────────────────────────
SellSignal = signalMode == 'Simple Entry + Exits' and sellCond and not
strongSignalOnly ? label.new(bar_index, high, selsigtex, xloc.bar_index,
yloc.abovebar, #ff00008c,
label.style_label_down, color.white, size.normal) : na

MinimalSell = signalMode == 'Minimized Entry + Exits' and sellCond and not


strongSignalOnly ? label.new(bar_index, high, selsminimal, xloc.bar_index,
yloc.abovebar, #ff00008c,
label.style_label_down, color.white, size.normal) : na

StrongSell = signalMode == 'Simple Entry + Exits' and strongSellCond1 ?


label.new(bar_index, high, smartselsigtex, xloc.bar_index, yloc.abovebar,
#ff00008c,
label.style_label_down, color.white, size.normal) : na

MinimalStrongSell = signalMode == 'Minimized Entry + Exits' and strongSellCond1 ?


label.new(bar_index, high, smartselminimal, xloc.bar_index, yloc.abovebar,
#ff00008c,
label.style_label_down, color.white, size.normal) : na

// ─────────────────────────────────────────────────────────────
// Candle Color Logic
// ─────────────────────────────────────────────────────────────

barcolor = src > filt and src > src[1] and upward > 0 ? color.new(#00db0a, 5) :
src > filt and src < src[1] and upward > 0 ? color.new(#00db05, 5) :
src < filt and src < src[1] and downward > 0 ? color.new(#c90505, 5) :
src < filt and src > src[1] and downward > 0 ? color.new(#ff0000, 5) :
color.new(#3ebe48, 5)

barcolor( CandleColor == 'Gradient Confirmation' ? barcolor : na, title='Candle


Colors')

// ─────────────────────────────────────────────────────────────
// Reversal Cloud Visualization
// ─────────────────────────────────────────────────────────────

u1 = plot(ReversalCloud ? ta.sma(u, 1) : na, color=color.new(color.white, 100),


editable=false)
u2 = plot(ReversalCloud ? ta.sma(upp, 5) : na, color=color.new(color.white, 100),
editable=false)
u3 = plot(ReversalCloud ? ta.sma(ups, 10): na, color=color.new(color.white, 100),
editable=false)
l1 = plot(ReversalCloud ? ta.sma(lo, 1) : na, color=color.new(color.white, 100),
editable=false)
l2 = plot(ReversalCloud ? ta.sma(loww, 5) : na, color=color.new(color.white, 100),
editable=false)
l3 = plot(ReversalCloud ? ta.sma(lowe, 10): na, color=color.new(color.white, 100),
editable=false)

// ─────────────────────────────────────────────────────────────
// Reversal Bands
// ─────────────────────────────────────────────────────────────

plot(ReversalBands ? ta.sma(u, 1) : na, color=color.new(#f23645, 60),


editable=false, offset=2)
plot(ReversalBands ? ta.sma(upp, 5) : na, color=color.new(#f23645, 70),
editable=false, offset=3)
plot(ReversalBands ? ta.sma(ups, 10) : na, color=color.new(#f23645, 65),
editable=false, offset=3)

plot(ReversalBands ? ta.sma(lowe, 10): na, color=color.new(#089981, 65),


editable=false, offset=3)
plot(ReversalBands ? ta.sma(loww, 5) : na, color=color.new(#089981, 70),
editable=false, offset=3)
plot(ReversalBands ? ta.sma(lo, 1) : na, color=color.new(#089981, 60),
editable=false, offset=2)

// Fill Zones
fill(u1, u2, color=color.new(#f23645, 65), title='Reversal Zones [R3, R2]')
fill(u2, u3, color=color.new(#f23645, 75), title='Reversal Zones [R2, R1]')
fill(l2, l3, color=color.new(#089981, 75), title='Reversal Zones [S2, S1]')
fill(l1, l2, color=color.new(#089981, 65), title='Reversal Zones [S3, S2]')

// ─────────────────────────────────────────────────────────────
// Trend Catcher
// ─────────────────────────────────────────────────────────────

filtcolor = upward > 0 ? color.rgb(0, 255, 85) : downward > 0 ? color.new(#ff0000,


0) : color.new(#56328f, 0)

plot(TrendTracer ? filt : na, color=filtcolor, linewidth=3, title='Trend Tracer')

// ─────────────────────────────────────────────────────────────
// Frequency Cloud
// ─────────────────────────────────────────────────────────────

plot_eq_closing_price = plot( frequencyCloud ? shorttop : na, title='EQ Closing


Price', color=color.new(color.white, 100), editable=false)

plot_eq_external_value = plot( frequencyCloud ? longtop : na, title='EQ External


Value', color=color.new(color.white, 100), editable=false)

// Watermark Table Cell


table.cell( textWatermark, 0, 1, subtitle, width, height, c_subtitle, a_subtitle,
text_size=s_subtitle, bgcolor=c_bg)

// Frequency Cloud Fill Color Logic


eqCloudColor = ta.sma(close, 26) < ta.sma(close, 48) ? color.new(#9f0700, 80) :
shorttop < longtop ? color.new(#ff1100, 80) :
ta.sma(close, 26) > ta.sma(close, 48) ? color.new(#10253b, 80) :
shorttop > longtop ? color.new(#0d67c2, 80) :
ta.sma(close, 34) > ta.sma(close, 56) ? color.new(#549de6, 80) : na

// Fill Between Frequency Cloud Plots


fill( plot_eq_closing_price, plot_eq_external_value, color=eqCloudColor,
title='Frequency Cloud Fill')

// ─────────────────────────────────────────────────────────────
// Order Block Configuration
// ─────────────────────────────────────────────────────────────

colup = #089981
coldn = #f23645

// Display Settings
obshow = input.bool(true, "Show Last", group="Order Blocks", inline='1',
tooltip="Show Last number of order blocks")
oblast = input.int(3, "", minval=0, maxval=50, step=1, group="Order
Blocks", inline='1')
obupcs = input.color(color.new(colup, 90), "", group="Order Blocks",
inline='1')
obdncs = input.color(color.new(coldn, 90), "", group="Order Blocks",
inline='1')

obshowactivity = input.bool(true, "Show Buy/Sell Activity", group="Order Blocks",


inline='2', tooltip="Display internal buy & sell activity")
obactup = input.color(color.new(colup, 50), "", group="Order Blocks",
inline='2')
obactdn = input.color(color.new(coldn, 50), "", group="Order Blocks",
inline='2')

obmode = input.string("Length", "Construction", options=["Length", "Full"],


tooltip="[Length] Use Length to adjust coordinate of the order blocks\n[Full] Use
whole candle body", group="Order Blocks", inline='3')
len_ob = input.int(5, "", minval=1, maxval=20, step=1, group="Order
Blocks", inline='3')

obmiti = input.string("Close", "Mitigation Method", options=["Close",


"Wick", "Avg"], tooltip="Mitigation method for when to trigger order blocks",
group="Order Blocks")
obtxt = input.string("Normal", "Metric Size", options=["Tiny", "Small",
"Normal", "Large", "Huge"], tooltip="Order block Metrics text size", group="Order
Blocks")

showmetric = input.bool(true, "Show Metrics", group="Order Blocks")


showline = input.bool(true, "Show Mid-Line", group="Order Blocks")
overlap_ob = input.bool(true, "Hide Overlap", group="Order Blocks",
tooltip="Most recent order block will be preserved")

// ─────────────────────────────────────────────────────────────
// Order Block Alerts
// ─────────────────────────────────────────────────────────────

blcreated = input.bool(false, "Bullish OB Formed", group="Order Block Alerts",


inline="Formed")
brcreated = input.bool(false, "Bearish OB Formed", group="Order Block Alerts",
inline="Formed")

blmitigated = input.bool(false, "Bullish OB Mitigated", group="Order Block


Alerts", inline="Mitigated")
brmitigated = input.bool(false, "Bearish OB Mitigated", group="Order Block
Alerts", inline="Mitigated")

blinside = input.bool(false, "Price Inside Bullish OB", group="Order Block


Alerts", inline="Inside")
brinside = input.bool(false, "Price Inside Bearish OB", group="Order Block
Alerts", inline="Inside")

// === Text Size Method ===


txSz(string s) =>
switch s
"Tiny" => size.tiny
"Small" => size.small
"Normal" => size.normal
"Large" => size.large
"Huge" => size.huge
=> size.normal

// Order Block Arrays


var array_ob_blob = array.new<float>()
var array_ob_brob = array.new<float>()

// Simplified Order Block Logic


if obshow
up = ta.highest(len_ob)
dn = ta.lowest(len_ob)
pv = ta.pivothigh(volume, len_ob, len_ob)

var dir = 0
dir := high[len_ob] > up ? -1 : low[len_ob] < dn ? 1 : dir[1]

atr = ta.atr(len_ob)

if pv and dir == 1
array.push(array_ob_blob, low[len_ob])
if blcreated
alert("Bullish OB Formed")

if pv and dir == -1
array.push(array_ob_brob, high[len_ob])
if brcreated
alert("Bearish OB Formed")

// Clean up old boxes and lines on each bar


if barstate.islast
for i = 0 to array.size(box.all) - 1
box.delete(array.get(box.all, i))
for i = 0 to array.size(line.all) - 1
line.delete(array.get(line.all, i))

You might also like