Candle Breakout Oscillator [LuxAlgo]The Candle Breakout Oscillator tool allows traders to identify the strength and weakness of the three main market states: bullish, bearish, and choppy.
Know who controls the market at any given moment with an oscillator display with values ranging from 0 to 100 for the three main plots and upper and lower thresholds of 80 and 20 by default.
🔶 USAGE
The Candle Breakout Oscillator represents the three main market states, with values ranging from 0 to 100. By default, the upper and lower thresholds are set at 80 and 20, and when a value exceeds these thresholds, a colored area is displayed for the trader's convenience.
This tool is based on pure price action breakouts. In this context, we understand a breakout as a close above the last candle's high or low, which is representative of market strength. All other close positions in relation to the last candle's limits are considered weakness.
So, when the bullish plot (in green) is at the top of the oscillator (values above 80), it means that the bullish breakouts (close below the last candle low) are at their maximum value over the calculation window, indicating an uptrend. The same interpretation can be made for the bearish plot (in red), indicating a downtrend when high.
On the other hand, weakness is indicated when values are below the lower threshold (20), indicating that breakouts are at their minimum over the last 100 candles. Below are some examples of the possible main interpretations:
There are three main things to look for in this oscillator:
Value reaches extreme
Value leaves extreme
Bullish/Bearish crossovers
As we can see on the chart, before the first crossover happens the bears come out of strength (top) and the bulls come out of weakness (bottom), then after the crossover the bulls reach strength (top) and the bears weakness (bottom), this process is repeated in reverse for the second crossover.
The other main feature of the oscillator is its ability to identify periods of sideways trends when the sideways values have upper readings above 80, and trending behavior when the sideways values have lower readings below 20. As we just saw in the case of bullish vs. bearish, sideways values signal a change in behavior when reaching or leaving the extremes of the oscillator.
🔶 DETAILS
🔹 Data Smoothing
The tool offers up to 10 different smoothing methods. In the chart above, we can see the raw data (smoothing: None) and the RMA, TEMA, or Hull moving averages.
🔹 Data Weighting
Users can add different weighting methods to the data. As we can see in the image above, users can choose between None, Volume, or Price (as in Price Delta for each breakout).
🔶 SETTINGS
Window: Execution window, 100 candles by default
🔹 Data
Smoothing Method: Choose between none or ten moving averages
Smoothing Length: Length for the moving average
Weighting Method: Choose between None, Volume, or Price
🔹 Thresholds
Top: 80 by default
Bottom: 20 by default
Indicatori e strategie
Dynamic Range Filter with Trend Candlesticks (Zeiierman)█ Overview
Dynamic Range Filter with Trend Candlesticks (Zeiierman) is a volatility-responsive trend engine that adapts in real-time to market structure, offering a clean and intelligent visualization of directional bias. It blends dynamic range calculation with customizable smoothing techniques and layered trend confirmation logic, making it ideal for traders who rely on clear trend direction, structural range analysis, and momentum-based candlestick signals.
By measuring scaled volatility over configurable lengths and applying advanced moving average techniques, this indicator filters out market noise while preserving true directional intent. Complementing this, a dual-trend system (range-based and candle-based) enhances clarity and responsiveness, particularly during shifting market conditions.
█ How It Works
⚪ Scaled Volatility Band Calculation
At the core lies a volatility engine that constructs adaptive range bands around price using smoothed high/low calculations. The bands are dynamically adjusted using:
High/Low Smoothing – Applies a moving average to the raw high and low data before calculating the range.
Scaled Range Volatility – A 2.618 multiplier scales the distance between smoothed highs and lows, forming a responsive volatility envelope.
Band Multiplier – Controls how wide the upper/lower range bands extend from the mean.
This filtering process minimizes false signals and highlights only structurally meaningful moves.
⚪ Multi-Type Smoothing Engine
Users can choose from a wide array of smoothing algorithms for trend construction, including:
HMA (default), SMA, EMA, RMA
KAMA – Adapts to market volatility using efficiency ratios.
VIDYA – Momentum-sensitive smoothing using CMO logic.
FRAMA – Dynamically adjusts to fractal dimension in price.
Super Smoother – Ideal for eliminating aliasing in range signals.
This provides the trader with fine-tuned control over reactivity vs. smoothness.
⚪ Trend Detection (Dual Engine)
The indicator includes two independent trend tracking systems:
Main Trend Filter – Based on adaptive volatility band shifts.
Candle Trend Filter – A second-tier confirmation using smoothed candle data, ideal for directional candles and confirmation entries.
█ How to Use
⚪ Trend Confirmation
Use the Trend Line and colored candlesticks for high-probability entries in the trend direction. The more trend layers that align, the higher the confidence.
⚪ Reversal Zones
When the price reaches the outer bands or fails to break them, look for candle color shifts or a crossover in the range to anticipate possible reversals or consolidations.
█ Settings
Scaled Volatility Length – Controls the lookback used to stabilize the base volatility band.
MA Type & Length – Choose and fine-tune the smoothing method (HMA, EMA, KAMA, etc.)
High/Low Smoother – Pre-smoothing for structural high/low banding.
Band Multiplier – Adjusts the width of the dynamic bands.
Trend Length (Candles) – Length used for candle-based trend confirmation.
-----------------
Disclaimer
The content provided in my scripts, indicators, ideas, algorithms, and systems is for educational and informational purposes only. It does not constitute financial advice, investment recommendations, or a solicitation to buy or sell any financial instruments. I will not accept liability for any loss or damage, including without limitation any loss of profit, which may arise directly or indirectly from the use of or reliance on such information.
All investments involve risk, and the past performance of a security, industry, sector, market, financial product, trading strategy, backtest, or individual's trading does not guarantee future results or returns. Investors are fully responsible for any investment decisions they make. Such decisions should be based solely on an evaluation of their financial circumstances, investment objectives, risk tolerance, and liquidity needs.
TrueTrend MaxRThe TrueTrend MaxR indicator is designed to identify the most consistent exponential price trend over extended periods. It uses statistical analysis on log-transformed prices to find the trendline that best fits historical price action, and highlights the most frequently tested or traded level within that trend channel.
For optimal results, especially on high timeframes such as weekly or monthly, it is recommended to use this indicator on charts set to logarithmic scale. This ensures proper visual alignment with the exponential nature of long-term price movements.
How it works
The indicator tests 50 different lookback periods, ranging from 300 to 1280 bars. For each period, it:
- Applies a linear regression on the natural logarithm of the price
- Computes the slope and intercept of the trendline
- Calculates the unbiased standard deviation from the regression line
- Measures the correlation strength using Pearson's R coefficient
The period with the highest Pearson R value is selected, meaning the trendline drawn corresponds to the log-scale trend with the best statistical fit.
Trendline and deviation bands
Once the optimal period is identified, the indicator plots:
- A main log-scale trendline
- Upper and lower bands, based on a user-defined multiple of the standard deviation
These bands help visualize how far price deviates from its core trend, and define the range of typical fluctuations.
Point of Control (POC)
Inside the trend channel, the space between upper and lower bands is divided into 15 logarithmic levels. The script evaluates how often price has interacted with each level, using one of two selectable methods:
- Touches: Counts the number of candles crossing each level
- Volume: Weighs each touch by the traded volume at that candle
The level with the highest cumulative interaction is considered the dynamic Point of Control (POC), and is plotted as a line.
Annualized performance and confidence display
When used on daily or weekly timeframes, the script also calculates the annualized return (CAGR) based on the detected trend, and displays:
- A performance estimate in percentage terms
- A textual label describing the confidence level based on the Pearson R value
Why this indicator is useful
- Automatically detects the most statistically consistent exponential trendline
- Designed for log-scale analysis, suited to long-term investment charts
- Highlights key price levels frequently visited or traded within the trend
- Provides objective, data-based trend and volatility insights
- Displays annualized growth rate and correlation strength for quick evaluation
Notes
- All calculations are performed only on the last bar
- No future data is used, and the script does not repaint
- Works on any instrument or timeframe, with optimal use on higher timeframes and logarithmic scaling
Abusuhil Bullish CandlesAbusuhil Bullish Candles is a pattern recognition indicator designed to identify key bullish reversal candlestick formations including Hammer, Bullish Engulfing, Morning Star, Piercing Line, Three White Soldiers, and Three Inside Up.
The script includes optional filters such as Stochastic and Volume Confirmation, providing more precise signal detection.
Each pattern and filter is fully customizable via settings. Alerts are also included to support active trading workflows.
This script was written originally and does not copy open-source indicators. It's ideal for traders seeking visual clarity on bullish opportunities with professional-grade logic.
مؤشر الشموع الصعودية هو مؤشر احترافي يكتشف أبرز نماذج الانعكاس الصعودي في الشموع اليابانية مثل: Hammer، Bullish Engulfing، Morning Star، Piercing Line، Three White Soldiers، و Three Inside Up.
يوفر المؤشر فلاتر إضافية مثل فلتر Stochastic وفلتر الفوليوم لتعزيز دقة الإشارات. جميع الإعدادات قابلة للتعديل بما يتناسب مع احتياج كل متداول.
يحتوي المؤشر أيضًا على تنبيهات تلقائية لدعم استراتيجيات التداول اللحظي. تمت برمجة المؤشر من الصفر ويعتمد على منطق خاص غير منسوخ من سكربتات مفتوحة المصدر.
Diagonal Support and Resistance Trend LinesA simple indicator to plot trend lines.
1. Adjust the "Pivot Lookback" (default: 20) to control pivot sensitivity. Larger values detect more significant pivots.
2. Adjust the "Max Trend Lines" (default: 4) to control how many support/resistance lines are drawn.
The indicator will plot:
1. Red dashed lines for resistance (based on pivot highs).
2. Green dashed lines for support (based on pivot lows).
3. Small red triangles above bars for pivot highs and green triangles below bars for pivot lows.
💎 Diamond Algo 💎//@version=5
indicator("💎 Diamond Algo 💎", overlay = true)
// Get user input
// Dashboard
showDashboard = input(true, "Smart Panel", group = 'Dashboard Settings')
locationDashboard = input.string("Bottom Right", "Location", , group = 'Dashboard Settings', inline = 'agfh1')
sizeDashboard = input.string("Small", "Size", , group = 'Dashboard Settings', inline = 'agfh1')
// Signals
nbuysell = input.bool(true, 'Show Signals', inline = "BSNM",group='BUY AND SELL SIGNALS SETTINGS')
nsensitivity = input.float(defval=2, title="Sensitivity", minval=1, maxval=20, group='BUY AND SELL SIGNALS SETTINGS')
smartsignalsonly = input.bool(false, 'Smart Signals Only',group='BUY AND SELL SIGNALS SETTINGS')
barcoloringmode = input.string("Trend", "Bar Coloring", , inline="levels", group = 'BUY AND SELL SIGNALS SETTINGS')
//candlecolor = input.bool(true, 'Buy/Sell Signal', inline = "BSNM",group='BUY/SELL SIGNAL')
ema200con = ta.ema(close,200)
// Risk Management
levels = input.bool(false, "Take Profit/ Stop-Loss Areas" , group = "RISK MANAGEMENT SETTINGS" , inline = "MMDB2")
lvlLines = true
linesStyle = "DASHED"
lvlDistance = input.int(20, "Distance", 1, inline="levels2", group = "RISK MANAGEMENT SETTINGS")
lvlDecimals = input.int(2, " Decimals", 1, 8, inline="levels2", group = "RISK MANAGEMENT SETTINGS")
atrRisk = input.int(1, "Risk % ", 1, group = "RISK MANAGEMENT SETTINGS" , inline="levels3")
atrLen = input.int(14, " ATR Length", 1, group = "RISK MANAGEMENT SETTINGS" , inline="levels3")
decimals = lvlDecimals == 1 ? "#.#" : lvlDecimals == 2 ? "#.##" : lvlDecimals == 3 ? "#.###" : lvlDecimals == 4 ? "#.####" : lvlDecimals == 5 ? "#.#####" : lvlDecimals == 6 ? "#.######" : lvlDecimals == 7 ? "#.#######" : "#.########"
// Trend Features
LongTrendAverage = input(false, 'Trend Cloud', group='INDICATOR OVERLAY', inline = '1')
TrendFollower = input(false, 'Trend Follower', group='INDICATOR OVERLAY', inline = '1')
ShowComulus = input(false, 'Comulus Cloud', group='INDICATOR OVERLAY', inline = '2')
CirrusCloud = input(false, 'Cirrus Cloud', group='INDICATOR OVERLAY', inline = '2')
ShowSmartTrail = input(false,'Smart Trail', group='INDICATOR OVERLAY', inline = '3')
Showtrendlines = input(false,'Trend Lines', group='INDICATOR OVERLAY', inline = '3')
showsr = input(false, title="Support & Resistance", group = 'INDICATOR OVERLAY', inline = '4')
// Input settings
history_of_demand_to_keep = 20
show_zigzag = false
show_price_action_labels = false
swing_length = 8
box_width = 4
box_extend_option = "Both"
res = ''
s1 = request.security(syminfo.tickerid, res, showsr, gaps=barmerge.gaps_on)
demand_color = #0395ff4d
supply_color = #ff00024d
// Signal Generation
supertrend(_close, factor, atrLen) =>
atr = ta.atr(atrLen)
upperBand = _close + factor * atr
lowerBand = _close - factor * atr
prevLowerBand = nz(lowerBand )
prevUpperBand = nz(upperBand )
lowerBand := lowerBand > prevLowerBand or close < prevLowerBand ? lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close > prevUpperBand ? upperBand : prevUpperBand
int direction = na
float superTrend = na
prevSuperTrend = superTrend
if na(atr )
direction := 1
else if prevSuperTrend == prevUpperBand
direction := close > upperBand ? -1 : 1
else
direction := close < lowerBand ? 1 : -1
superTrend := direction == -1 ? lowerBand : upperBand
// SMA
ocAvg = math.avg(open, close)
sma4 = ta.sma(close, 50)
sma5 = ta.sma(close, 200)
sma9 = ta.sma(close, 13)
psar = ta.sar(0.02, 0.02, 0.2)
//*in Easy Words Super Trend + SMA = Signals
= supertrend(close, nsensitivity*2, 11)
source = close, period = 150
// Colors
green = #0395ff, green2 = #0395ff
red = #ff0002, red2 = #ff0002
adxlen = 15
dilen = 15
dirmov(len) =>
up = ta.change(high)
down = -ta.change(low)
plusDM = na(up) ? na : up > down and up > 0 ? up : 0
minusDM = na(down) ? na : down > up and down > 0 ? down : 0
truerange = ta.rma(ta.tr, len)
plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
adx(dilen, adxlen) =>
= dirmov(dilen)
sum = plus + minus
adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
adx
sig = adx(dilen, adxlen)
// range ADX threshold
sidewaysThreshold = 15
// boolean expression to see if the ADX is below tehe sideways threshold
bool isSideways = sig < sidewaysThreshold
// adding the option to color the bars when in a trading range
useBarColor = true
bColor = isSideways ? color.new(#4b148d, 0) : na
//barcolor(isSideways and barcoloringmode == "Trend" ? bColor : na)
trendbarcolor = isSideways and barcoloringmode == "Trend" ? color.new(#4b148d, 0) : close > supertrend ? #0395ff : #ff0002
barcolor(trendbarcolor)
// High Lows
y1 = low - (ta.atr(30) * 2), y1B = low - ta.atr(30)
y2 = high + (ta.atr(30) * 2), y2B = high + ta.atr(30)
bull = ta.crossover(close, supertrend) and close >= sma9
bear = ta.crossunder(close, supertrend) and close <= sma9
// Plots
windowsize = 100
offset = 0.9
sigma = 6
//plot(ta.alma(source, windowsize, offset, sigma))
windowsize2 = 310
offset2 = 0.85
sigma2 = 32
//plot(ta.alma(source, windowsize2, offset2, sigma2))
// Chart Features
smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x ), t)
smoothrng = ta.ema(avrng, wper) * m
smoothrng
smrng = smoothrng(close, 22, 6)
rngfilt(x, r) =>
rngfilt = x
rngfilt := x > nz(rngfilt ) ? x - r < nz(rngfilt ) ? nz(rngfilt ) : x - r : x + r > nz(rngfilt ) ? nz(rngfilt ) : x + r
rngfilt
filt = rngfilt(close, smrng)
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
upward = 0.0
upward := filt > filt ? nz(upward ) + 1 : filt < filt ? 0 : nz(upward )
downward = 0.0
downward := filt < filt ? nz(downward ) + 1 : filt > filt ? 0 : nz(downward )
filtcolor = upward > 0 ? color.new(#00e2ff, 50) : downward > 0 ? color.new(#fe0100, 50) : color.new(#56328f, 0)
plot(TrendFollower ? filt : na, color=filtcolor, linewidth=1, title='Trend Tracer')
// Trend Cloud
tclength = 600
hullma = ta.wma(2*ta.wma(close, tclength/2)-ta.wma(close, tclength), math.floor(math.sqrt(tclength)))
plot(LongTrendAverage ? hullma : na, 'Trend Cloud', linewidth=4, color=close > hullma ? color.new(#00e2ff, 65) : color.new(#fe0100, 65))
// Comulus Cloud
candle = ta.alma(source, windowsize2, offset2, sigma2)
reach = ta.alma(source, windowsize, offset, sigma)
candlep = plot(ShowComulus ? candle : na, color=color.new(color.white, 100))
reachp = plot(ShowComulus ? reach : na, color=color.new(color.white, 100))
fill(reachp, candlep, color= candle > reach ? color.new(#fe0100, 85) : color.new(#00e2ff, 85))
// Chart Features
x1 = 22
x2 = 9
x3 = 15
x4 = 5
smoothrngX1(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x ), t)
smoothrngX1 = ta.ema(avrng, wper) * m
smoothrngX1
smrngx1x = smoothrngX1(close, x1, x2)
smrngx1x2 = smoothrngX1(close, x3, x4)
rngfiltx1x1(x, r) =>
rngfiltx1x1 = x
rngfiltx1x1 := x > nz(rngfiltx1x1 ) ? x - r < nz(rngfiltx1x1 ) ? nz(rngfiltx1x1 ) : x - r : x + r > nz(rngfiltx1x1 ) ? nz(rngfiltx1x1 ) : x + r
rngfiltx1x1
filtx1 = rngfiltx1x1(close, smrngx1x)
filtx12 = rngfiltx1x1(close, smrngx1x2)
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
upwardx1 = 0.0
upwardx1 := filtx1 > filtx1 ? nz(upwardx1 ) + 1 : filtx1 < filtx1 ? 0 : nz(upwardx1 )
downwardx1 = 0.0
downwardx1 := filtx1 < filtx1 ? nz(downwardx1 ) + 1 : filtx1 > filtx1 ? 0 : nz(downwardx1 )
filtx1colorx1 = color.rgb(0, 187, 212, 100)
xxx1 = plot(CirrusCloud ? filtx1 : na, color=filtx1colorx1, linewidth=1, title='Trend Tracer', editable = false)
xxx2 = plot(CirrusCloud ? filtx12 : na, color=filtx1colorx1, linewidth=1, title='Trend Tracer', editable = false)
fill(xxx1, xxx2, color= filtx1 > filtx12 ? color.new(#fd0205, 65) : color.new(#0395fc, 65))
buy = bull and nbuysell and smartsignalsonly == false ? label.new(bar_index, y1, close > ema200con ? "Smart Buy" : "Buy", xloc.bar_index, yloc.price, #0395fc, label.style_label_up, color.white, size.normal) : na
sell = bear and nbuysell and smartsignalsonly == false ? label.new(bar_index, y2, close < ema200con ? "Smart Sell" : "Sell", xloc.bar_index, yloc.price, #fd0205, label.style_label_down, color.white, size.normal) : na
SmartBuy = bull and nbuysell and close > ema200con and smartsignalsonly == true ? label.new(bar_index, y1, close > ema200con ? "Smart Buy" : "Buy", xloc.bar_index, yloc.price, #0395fc, label.style_label_up, color.white, size.normal) : na
SmartSell = bear and nbuysell and close < ema200con and smartsignalsonly == true ? label.new(bar_index, y2, close < ema200con ? "Smart Sell" : "Sell", xloc.bar_index, yloc.price, #fd0205, label.style_label_down, color.white, size.normal) : na
// Other initializations
avg_volume = ta.sma(volume, 20)
very_weak_multiplier = 0.5
weak_multiplier = 1
strong_multiplier = 1.5
// Rejection handling
var int demandRejections = array.new_int(history_of_demand_to_keep, 0)
var int supplyRejections = array.new_int(history_of_demand_to_keep, 0)
var int demandCreationBars = array.new_int(history_of_demand_to_keep, na)
var int supplyCreationBars = array.new_int(history_of_demand_to_keep, na)
var box current_demand_box = array.new_box(history_of_demand_to_keep, na)
var box current_supply_box = array.new_box(history_of_demand_to_keep, na)
f_check_demand_rejections() =>
for i = 0 to history_of_demand_to_keep - 1
if not na(array.get(demandCreationBars, i))
if bar_index - array.get(demandCreationBars, i) > 15 and bar_index - array.get(demandCreationBars, i) % 15 == 0
label.new(bar_index, high, "Checking demand rejection", color=#fd0205)
dBox = array.get(current_demand_box, i)
if (na(dBox))
continue
withinBox = (high >= box.get_bottom(dBox) and high <= box.get_top(dBox)) or (close >= box.get_bottom(dBox) and close <= box.get_top(dBox))
bearishCandlesCount = math.sum(close < open ? 1 : 0, 15)
if withinBox and bearishCandlesCount >= 7
label.new(bar_index, low, "Bearish count > 7", color=#0395fc)
array.set(demandRejections, i, array.get(demandRejections, i) + 1)
f_check_supply_rejections() =>
for i = 0 to history_of_demand_to_keep - 1
if not na(array.get(supplyCreationBars, i))
if bar_index - array.get(supplyCreationBars, i) > 15 and bar_index - array.get(supplyCreationBars, i) % 15 == 0
label.new(bar_index, low, "Checking supply rejection", color=#fd0205)
sBox = array.get(current_supply_box, i)
if (na(sBox))
continue
withinBox = (low <= box.get_top(sBox) and low >= box.get_bottom(sBox)) or (close <= box.get_top(sBox) and close >= box.get_bottom(sBox))
bullishCandlesCount = math.sum(close > open ? 1 : 0, 15)
if withinBox and bullishCandlesCount >= 7
label.new(bar_index, high, "Bullish count > 7", color=#0395fc)
array.set(supplyRejections, i, array.get(supplyRejections, i) + 1)
f_array_add_pop(array, new_value_to_add) =>
array.unshift(array, new_value_to_add)
array.pop(array)
f_sh_sl_labels(array, swing_type) =>
var string label_text = na
if swing_type == 1
if array.get(array, 0) >= array.get(array, 1)
label_text := 'HH'
else
label_text := 'LH'
label.new(bar_index - swing_length, array.get(array,0), text = label_text, style=label.style_label_down, textcolor = color.white, color = color.new(color.white, 100), size = size.tiny)
else if swing_type == -1
if array.get(array, 0) >= array.get(array, 1)
label_text := 'HL'
else
label_text := 'LL'
label.new(bar_index - swing_length, array.get(array,0), text = label_text, style=label.style_label_up, textcolor = color.white, color = color.new(color.white, 100), size = size.tiny)
f_check_overlapping(new_poi, box_array, atr) =>
atr_threshold = atr * 2
okay_to_draw = true
for i = 0 to array.size(box_array) - 1
top = box.get_top(array.get(box_array, i))
bottom = box.get_bottom(array.get(box_array, i))
poi = (top + bottom) / 2
upper_boundary = poi + atr_threshold
lower_boundary = poi - atr_threshold
if new_poi >= lower_boundary and new_poi <= upper_boundary
okay_to_draw := false
break
else
okay_to_draw := true
okay_to_draw
f_supply_demand(value_array, bn_array, box_array, label_array, box_type, atr) =>
atr_buffer = atr * (box_width / 10)
box_left = array.get(bn_array, 0)
box_right = bar_index + 20
var float box_top = 0.00
var float box_bottom = 0.00
var float poi = 0.00
if box_type == 1
box_top := array.get(value_array, 0)
box_bottom := box_top - atr_buffer
poi := (box_top + box_bottom) / 2
else if box_type == -1
box_bottom := array.get(value_array, 0)
box_top := box_bottom + atr_buffer
poi := (box_top + box_bottom) / 2
okay_to_draw = f_check_overlapping(poi, box_array, atr)
swing_volume = volume
var string strength_text = ""
highest_volume_last_20 = ta.highest(volume, 20)
volume_percentage = math.round(swing_volume / highest_volume_last_20 * 100)
volume_percentage := math.min(volume_percentage, 100) // Cap the volume percentage to 100
var extend_option = extend.right
if box_extend_option == "Right"
extend_option := extend.right
else if box_extend_option == "Both"
extend_option := extend.both
if box_type == 1 and okay_to_draw and s1
box.delete( array.get(box_array, array.size(box_array) - 5) )
f_array_add_pop(box_array, box.new( left = box_left, top = box_top, right = box_right, bottom = box_bottom, border_color = #fd020580, border_width=1,
bgcolor = supply_color, extend = extend_option, text = strength_text, text_halign = text.align_right, text_valign = text.align_center, text_color = color.white, text_size = size.small, xloc = xloc.bar_index))
box.delete( array.get(label_array, array.size(label_array) - 5) )
f_array_add_pop(label_array, box.new( left = box_left, top = poi, right = box_right, bottom = poi, border_color = #fd020580, border_width=1, border_style=line.style_dotted,
bgcolor = color.new(color.black,100), extend = extend_option, text = '', text_halign = text.align_left, text_valign = text.align_center, text_color = color.white, text_size = size.small, xloc = xloc.bar_index))
else if box_type == -1 and okay_to_draw and s1
box.delete( array.get(box_array, array.size(box_array) - 5) )
f_array_add_pop(box_array, box.new( left = box_left, top = box_top, right = box_right, bottom = box_bottom, border_color = #0395fc80, border_width=1,
bgcolor = demand_color, extend = extend_option, text = strength_text, text_halign = text.align_right, text_valign = text.align_center, text_color = color.white, text_size = size.small, xloc = xloc.bar_index))
box.delete( array.get(label_array, array.size(label_array) - 5) )
f_array_add_pop(label_array, box.new( left = box_left, top = poi, right = box_right, bottom = poi, border_color = #0395fc80, border_width=1, border_style=line.style_dotted,
bgcolor = color.new(color.black,100), extend = extend_option, text = '', text_halign = text.align_left, text_valign = text.align_center, text_color = color.white, text_size = size.small, xloc = xloc.bar_index))
f_sd_to_bos(box_array, bos_array, label_array, zone_type) =>
if zone_type == 1
for i = 0 to array.size(box_array) - 1
level_to_break = box.get_top(array.get(box_array,i))
if close >= level_to_break
box.delete(array.get(box_array, i))
box.delete(array.get(label_array, i))
if zone_type == -1
for i = 0 to array.size(box_array) - 1
level_to_break = box.get_bottom(array.get(box_array,i))
if close <= level_to_break
box.delete(array.get(box_array, i))
box.delete(array.get(label_array, i))
f_extend_box_endpoint(box_array) =>
for i = 0 to array.size(box_array) - 1
box.set_right(array.get(box_array, i), bar_index + 30) // Extend only 20 bars
atr567 = ta.atr(50)
swing_high = ta.pivothigh(high, swing_length, swing_length)
swing_low = ta.pivotlow(low, swing_length, swing_length)
var swing_high_values = array.new_float(5,0.00)
var swing_low_values = array.new_float(5,0.00)
var swing_high_bns = array.new_int(5,0)
var swing_low_bns = array.new_int(5,0)
var current_supply_poi = array.new_box(history_of_demand_to_keep, na)
var current_demand_poi = array.new_box(history_of_demand_to_keep, na)
var supply_bos = array.new_box(5, na)
var demand_bos = array.new_box(5, na)
if not na(swing_high)
f_array_add_pop(swing_high_values, swing_high)
f_array_add_pop(swing_high_bns, bar_index )
if show_price_action_labels
f_sh_sl_labels(swing_high_values, 1)
f_supply_demand(swing_high_values, swing_high_bns, current_supply_box, current_supply_poi, 1, atr567)
else if not na(swing_low)
f_array_add_pop(swing_low_values, swing_low)
f_array_add_pop(swing_low_bns, bar_index )
if show_price_action_labels
f_sh_sl_labels(swing_low_values, -1)
f_supply_demand(swing_low_values, swing_low_bns, current_demand_box, current_demand_poi, -1, atr567)
f_sd_to_bos(current_supply_box, supply_bos, current_supply_poi, 1)
f_sd_to_bos(current_demand_box, demand_bos, current_demand_poi, -1)
f_extend_box_endpoint(current_supply_box)
f_extend_box_endpoint(current_demand_box)
// Inside the main execution, after the box is drawn, check for rejections
if not na(swing_low)
f_array_add_pop(swing_low_values, swing_low)
f_array_add_pop(swing_low_bns, bar_index )
if show_price_action_labels
f_sh_sl_labels(swing_low_values, -1)
f_supply_demand(swing_low_values, swing_low_bns, current_demand_box, current_demand_poi, -1, atr567)
f_check_demand_rejections()
if not na(swing_high)
f_array_add_pop(swing_high_values, swing_high)
f_array_add_pop(swing_high_bns, bar_index )
if show_price_action_labels
f_sh_sl_labels(swing_high_values, 1)
f_supply_demand(swing_high_values, swing_high_bns, current_supply_box, current_supply_poi, 1, atr567)
f_check_supply_rejections()
trigger2 = bull ? 1 : 0
countBull = ta.barssince(bull)
countBear = ta.barssince(bear)
trigger = nz(countBull, bar_index) < nz(countBear, bar_index) ? 1 : 0
atrBand = ta.atr(atrLen) * atrRisk
atrStop = trigger == 1 ? low - atrBand : high + atrBand
currentposition = countBull > countBear ? 'Sell' : 'Buy'
lastTrade(close) => ta.valuewhen(bull or bear , close, 0)
entry = levels ? label.new(time, close, "ENTRY " + str.tostring(lastTrade(close), decimals), xloc.bar_time, yloc.price, color.orange, label.style_label_left, color.white, size.normal) : na
label.set_x(entry, label.get_x(entry) + math.round(ta.change(time) * lvlDistance))
label.set_y(entry, lastTrade(close))
label.delete(entry )
stop_y = lastTrade(atrStop)
stop = levels ? label.new(time, close, "SL " + str.tostring(stop_y, decimals), xloc.bar_time, yloc.price, red2, label.style_label_left, color.white, size.normal) : na
label.set_x(stop, label.get_x(stop) + math.round(ta.change(time) * lvlDistance))
label.set_y(stop, stop_y)
label.delete(stop )
tp1Rl_y = (lastTrade(close)-lastTrade(atrStop))*1 + lastTrade(close)
tp1Rl = levels ? label.new(time, close, "1:1 TP " + str.tostring(tp1Rl_y, decimals), xloc.bar_time, yloc.price, green2, label.style_label_left, color.white, size.normal ) : na
label.set_x(tp1Rl, label.get_x(tp1Rl) + math.round(ta.change(time) * lvlDistance))
label.set_y(tp1Rl, tp1Rl_y)
label.delete(tp1Rl )
tp2RL_y = (lastTrade(close)-lastTrade(atrStop))*2 + lastTrade(close)
tp2RL = levels ? label.new(time, close, "2:1 TP " + str.tostring(tp2RL_y, decimals), xloc.bar_time, yloc.price, green2, label.style_label_left, color.white, size.normal) : na
label.set_x(tp2RL, label.get_x(tp2RL) + math.round(ta.change(time) * lvlDistance))
label.set_y(tp2RL, tp2RL_y)
label.delete(tp2RL )
tp3RL_y = (lastTrade(close)-lastTrade(atrStop))*3 + lastTrade(close)
tp3RL = levels ? label.new(time, close, "3:1 TP " + str.tostring(tp3RL_y, decimals), xloc.bar_time, yloc.price, green2, label.style_label_left, color.white, size.normal) : na
label.set_x(tp3RL, label.get_x(tp3RL) + math.round(ta.change(time) * lvlDistance))
label.set_y(tp3RL, tp3RL_y)
label.delete(tp3RL )
style = linesStyle == "SOLID" ? line.style_solid : linesStyle == "DASHED" ? line.style_dashed : line.style_dotted
lineEntry = levels and lvlLines ? line.new(bar_index - (trigger == 0 ? countBull : countBear), lastTrade(close), bar_index + lvlDistance, lastTrade(close), xloc.bar_index, extend.none, color.orange, style, 2) : na, line.delete(lineEntry )
lineStop = levels and lvlLines ? line.new(bar_index - (trigger == 0 ? countBull : countBear), stop_y, bar_index + lvlDistance, stop_y, xloc.bar_index, extend.none, #fe0100, style, 2) : na, line.delete(lineStop )
lineTp1Rl = levels and lvlLines ? line.new(bar_index - (trigger == 0 ? countBull : countBear), tp1Rl_y, bar_index + lvlDistance, tp1Rl_y, xloc.bar_index, extend.none, green2, style, 2) : na, line.delete(lineTp1Rl )
lineTp2RL = levels and lvlLines ? line.new(bar_index - (trigger == 0 ? countBull : countBear), tp2RL_y, bar_index + lvlDistance, tp2RL_y, xloc.bar_index, extend.none, green2, style, 2) : na, line.delete(lineTp2RL )
lineTp3RL = levels and lvlLines ? line.new(bar_index - (trigger == 0 ? countBull : countBear), tp3RL_y, bar_index + lvlDistance, tp3RL_y, xloc.bar_index, extend.none, green2, style, 2) : na, line.delete(lineTp3RL )
alertcondition(bull, title='Buy Signal', message = "BUY")
alertcondition(bear, title='Buy Signal', message = "BUY")
//import protradingart/pta_plot/6 as pp
//pp.peakprofit(bull, bear)
//
////////////////////////////////////////////////////////////////////////////////////////////////
// Functions
// Functions
f_chartTfInMinutes() =>
float _resInMinutes = timeframe.multiplier * (
timeframe.isseconds ? 1. / 60 :
timeframe.isminutes ? 1. :
timeframe.isdaily ? 60. * 24 :
timeframe.isweekly ? 60. * 24 * 7 :
timeframe.ismonthly ? 60. * 24 * 30.4375 : na)
// Get components
vosc = ta.obv - ta.ema(ta.obv, 20)
bs = ta.ema(nz(math.abs((open - close) / (high - low) * 100)), 3)
ema = ta.ema(close, 200)
emaBull = close > ema
equal_tf(res) => str.tonumber(res) == f_chartTfInMinutes()
higher_tf(res) => str.tonumber(res) > f_chartTfInMinutes()
too_small_tf(res) => (timeframe.isweekly and res=="1") or (timeframe.ismonthly and str.tonumber(res) < 10)
securityNoRep(sym, res, src) =>
bool bull = na
bull := equal_tf(res) ? src : bull
bull := higher_tf(res) ? request.security(sym, res, src, barmerge.gaps_off, barmerge.lookahead_on) : bull
bull_array = request.security_lower_tf(syminfo.tickerid, higher_tf(res) ? str.tostring(f_chartTfInMinutes()) : too_small_tf(res) ? (timeframe.isweekly ? "3" : "10") : res, src)
if array.size(bull_array) > 1 and not equal_tf(res) and not higher_tf(res)
bull := array.pop(bull_array)
array.clear(bull_array)
bull
TF1Bull = securityNoRep(syminfo.tickerid, "1" , emaBull)
//TF3Bull = securityNoRep(syminfo.tickerid, "3" , emaBull)
TF5Bull = securityNoRep(syminfo.tickerid, "5" , emaBull)
//TF10Bull = securityNoRep(syminfo.tickerid, "10" , emaBull)
TF15Bull = securityNoRep(syminfo.tickerid, "15" , emaBull)
TF30Bull = securityNoRep(syminfo.tickerid, "30" , emaBull)
TF60Bull = securityNoRep(syminfo.tickerid, "60" , emaBull)
//TF120Bull = securityNoRep(syminfo.tickerid, "120" , emaBull)
TF240Bull = securityNoRep(syminfo.tickerid, "240" , emaBull)
//TF720Bull = securityNoRep(syminfo.tickerid, "720" , emaBull)
TFDBull = securityNoRep(syminfo.tickerid, "1440", emaBull)
indicatorTF = "Chart"
// Functions
sqz(bbLen, bbMult, kcLen, kcMult, source) =>
upperBB = ta.sma(source, bbLen) + ta.stdev(source, bbLen) * bbMult
lowerBB = ta.sma(source, bbLen) - ta.stdev(source, bbLen) * bbMult
upperKC = ta.sma(source, kcLen) + ta.sma(ta.tr, kcLen) * kcMult
lowerKC = ta.sma(source, kcLen) - ta.sma(ta.tr, kcLen) * kcMult
sqzOn = lowerBB > lowerKC and upperBB < upperKC
sqzOff = lowerBB < lowerKC and upperBB > upperKC
qqe(rsiLen, rsiSmooth, factor, source, bbLen, bbMult) =>
rsiMa = ta.ema(ta.rsi(source, rsiLen), rsiSmooth)
delta = ta.ema(ta.ema(math.abs(ta.mom(rsiMa, 1)), rsiLen * 2 - 1), rsiLen * 2 - 1) * factor
longBand = 0.0, longBand := rsiMa > longBand and rsiMa > longBand ? math.max(longBand , rsiMa - delta) : rsiMa - delta
shortBand = 0.0, shortBand := rsiMa < shortBand and rsiMa < shortBand ? math.min(shortBand , rsiMa + delta) : rsiMa + delta
cross1 = ta.cross(rsiMa, shortBand )
cross2 = ta.cross(rsiMa, longBand )
trend = 0.0, trend := cross1 ? 1 : cross2 ? -1 : nz(trend , 1)
fastDelta = trend == 1 ? longBand : shortBand
_hist = rsiMa - 50
_line = fastDelta - 50
= ta.bb(_line, bbLen, bbMult)
// Get components
cond(_offset) =>
top = ta.highest(high, 10)
bot = ta.lowest(low, 10)
osc = ta.ema(hlc3, 5) - ta.ema(ohlc4, 20)
oscRis = osc > osc
oscFal = osc < osc
oscA0 = osc > 0
oscB0 = osc < 0
oscTop = oscFal and oscRis
oscBot = oscRis and oscFal
bullR = oscB0 and oscBot and ((osc > ta.valuewhen(oscB0 and oscBot, osc, 1) and bot < ta.valuewhen(oscB0 and oscBot, bot, 1)))
bearR = oscA0 and oscTop and ((osc < ta.valuewhen(oscA0 and oscTop, osc, 1) and top > ta.valuewhen(oscA0 and oscTop, top, 1)))
bullH = oscB0 and oscBot and ((osc < ta.valuewhen(oscB0 and oscBot, osc, 1) and bot > ta.valuewhen(oscB0 and oscBot, bot, 1)))
bearH = oscA0 and oscTop and ((osc > ta.valuewhen(oscA0 and oscTop, osc, 1) and top < ta.valuewhen(oscA0 and oscTop, top, 1)))
= sqz(20, 2, 20, 2, close)
= qqe(6, 6, 3, close, 50, 0.001)
= qqe(6, 5, 1.618, close, 50, 1)
= ta.dmi(14, 14)
[osc , oscRis , oscFal , oscA0 , oscB0 , oscTop , oscBot , bullR , bearR , bullH , bearH , sqzOn , sqzOff , _hist1 , upper1 , lower1 , _hist2 , _line2 , tvr ]
tf = indicatorTF == "Chart" ? timeframe.period : indicatorTF == "1 minute" ? "1" : indicatorTF == "3 minutes" ? "3" : indicatorTF == "5 minutes" ? "5" : indicatorTF == "10 minutes" ? "10" : indicatorTF == "15 minutes" ? "15" : indicatorTF == "30 minutes" ? "30" : indicatorTF == "45 minutes" ? "45" : indicatorTF == "1 hour" ? "60" : indicatorTF == "2 hours" ? "120" : indicatorTF == "3 hours" ? "180" : indicatorTF == "4 hours" ? "240" : indicatorTF == "12 hours" ? "720" : indicatorTF == "1 day" ? "1D" : indicatorTF == "1 week" ? "1W" : indicatorTF == "1 month" ? "1M" : na
= request.security(syminfo.tickerid, tf, cond(indicatorTF != "Chart" and barstate.isrealtime ? 1 : 0))
//colorTVR = tvr < 15 ? #F6525F : tvr > 15 and tvr < 25 ? #B2B5BE : #66BB6A
// Plots
//plot(Presets == "Money Moves TrendVR" ? tvr : na, "", colorTVR, editable=false)
TrendText = "Trending"
if tvr < 15 and tvr < 25
TrendText := "No trend"
if tvr > 15 and tvr < 25
TrendText := "Ranging"
//------------------------------------------------------------------------------------------------------- Volatitiry
//Calculates Volatility for Dashboard
atrr = 3 * ta.atr(10)
stdAtr = 2 * ta.stdev(atrr, 20)
smaAtr = ta.sma(atrr, 20)
topAtrDev = smaAtr + stdAtr
bottomAtrDev = smaAtr - stdAtr
calcDev = (atrr - bottomAtrDev) / (topAtrDev - bottomAtrDev)
percentVol = 40 * calcDev + 30
AvrLength = 21
PercentFilter = 144
xAavrVolume = ta.rma(volume, AvrLength)
nResLess = volume * 100 / xAavrVolume < PercentFilter ? 0 : volume
nRes = nResLess
clr = close < open ? #b2b5be : #00dbff
//plot(nRes, color=clr, style=plot.style_columns, title='Volume Filter', transp=20)
VolitiText = "Inactive"
if nRes
VolitiText := "Active"
//////////////////////////////////////////
ema69 = ta.ema(close, 9)
totalSentTxt = ema69 > ema69 ? 'Bullish' : ema69 < ema69 ? 'Bearish' : 'Flat'
// INputs
//Timezones
tz_incr = 0
use_exchange = false
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
//Session A
NYSes = true
NYTxt = 'New York'
NYTime = '1300-2200'
//Session B
LDSes = true
sesb_txt = 'London'
sesb_ses = '0700-1600'
//Session C
show_sesc = true
sesc_txt = 'Tokyo'
sesc_ses = '0000-0900'
//Session D
show_sesd = true
sesd_txt = 'Sydney'
sesd_ses = '2100-0600'
//-----------------------------------------------------------------------------}
//Sessions
//-----------------------------------------------------------------------------{
tff = timeframe.period
var tz = use_exchange ? syminfo.timezone :
str.format('UTC{0}{1}', tz_incr >= 0 ? '+' : '-', math.abs(tz_incr))
is_sesa = math.sign(nz(time(tff, NYTime, tz)))
is_sesb = math.sign(nz(time(tff, sesb_ses, tz)))
is_sesc = math.sign(nz(time(tff, sesc_ses, tz)))
is_sesd = math.sign(nz(time(tff, sesd_ses, tz)))
////////////////////////////////////////////
SessionText = "Default"
if is_sesd
SessionText := sesd_txt
if is_sesc
SessionText := sesc_txt
if is_sesb
SessionText := sesb_txt
if is_sesa
SessionText := NYTxt
if is_sesd and is_sesc
SessionText := "Sydney/Tokyo"
if is_sesb and is_sesc
SessionText := "Tokyo/London"
if is_sesb and is_sesa
SessionText := "London/Newyork"
if is_sesa and is_sesd
SessionText := "Newyork/Sydney"
//-----------------------------------------------------------------------------}
//Overlays color.green : color.red
//
var dashboard_loc = locationDashboard == "Top Right" ? position.top_right : locationDashboard == "Middle Right" ? position.middle_right : locationDashboard == "Bottom Right" ? position.bottom_right : locationDashboard == "Top Center" ? position.top_center : locationDashboard == "Middle Center" ? position.middle_center : locationDashboard == "Bottom Center" ? position.bottom_center : locationDashboard == "Top Left" ? position.top_left : locationDashboard == "Middle Left" ? position.middle_left : position.bottom_left
var dashboard_size = sizeDashboard == "Large" ? size.large : sizeDashboard == "Normal" ? size.normal : sizeDashboard == "Small" ? size.small : size.tiny
var dashboard = showDashboard ? table.new(dashboard_loc, 3, 8, color.rgb(30, 34, 45 , 60), #3d384300, 2, color.rgb(30, 34, 45 , 60), 1) : na
dashboard_cell(column, row, txt, signal=false) => table.cell(dashboard, column, row, txt, 0, 0, signal ? #000000 : color.white, text_size=dashboard_size)
dashboard_cell_bg(column, row, col) => table.cell_set_bgcolor(dashboard, column, row, col)
if barstate.islast and showDashboard
// MTF Trend
dashboard_cell(0, 0 , "MTF")
dashboard_cell(0, 1 , "M1") , dashboard_cell_bg(0, 1 , TF1Bull ? #0395fc : #fd0205)
dashboard_cell(0, 2 , "M5") , dashboard_cell_bg(0, 2 , TF5Bull ? #0395fc : #fd0205)
dashboard_cell(0, 3 , "M15") , dashboard_cell_bg(0, 3 , TF15Bull ? #0395fc : #fd0205)
dashboard_cell(0, 4 , "M30") , dashboard_cell_bg(0, 4 , TF30Bull ? #0395fc : #fd0205)
dashboard_cell(0, 5 , "1H") , dashboard_cell_bg(0, 5 , TF60Bull ? #0395fc : #fd0205)
dashboard_cell(0, 6 , "4H") , dashboard_cell_bg(0, 6 , TF240Bull ? #0395fc : #fd0205)
dashboard_cell(0, 7 , "D1") , dashboard_cell_bg(0, 7 , TFDBull ? #0395fc : #fd0205)
// Middel part
dashboard_cell(1, 0 , "💎 Diamond Algo 💎")
dashboard_cell(1, 1 , "👉 Current Position ")
dashboard_cell(1, 2 , "🔎 Current Sensitivity ")
dashboard_cell(1, 3 , "🔥 Market State ")
dashboard_cell(1, 4 , "⚠️ Volatility ")
dashboard_cell(1, 5 , "🏦 Institutional Activity ")
dashboard_cell(1, 6 , "🕒 Current Session (UTC) ")
dashboard_cell(1, 7 , "🌊 Trend Pressure ")
// End part
dashboard_cell(2, 0 , "AlgoPoint")
dashboard_cell(2, 1 , str.tostring(currentposition))
dashboard_cell(2, 2 , str.tostring(nsensitivity))
dashboard_cell(2, 3 , TrendText)
dashboard_cell(2, 4 , str.tostring(percentVol, '##.##') + '%')
dashboard_cell(2, 5 , VolitiText)
dashboard_cell(2, 6 , SessionText)
dashboard_cell(2, 7 , totalSentTxt)
// Other Features
// inputs //
//{
trailType = 'modified'
ATRPeriod = 14
ATRFactor = 6
smoothing = 8
norm_o = request.security(ticker.new(syminfo.prefix, syminfo.ticker), timeframe.period, open)
norm_h = request.security(ticker.new(syminfo.prefix, syminfo.ticker), timeframe.period, high)
norm_l = request.security(ticker.new(syminfo.prefix, syminfo.ticker), timeframe.period, low)
norm_c = request.security(ticker.new(syminfo.prefix, syminfo.ticker), timeframe.period, close)
//}
//////// FUNCTIONS //////////////
//{
// Wilders ma //
Wild_ma(_src, _malength) =>
_wild = 0.0
_wild := nz(_wild ) + (_src - nz(_wild )) / _malength
_wild
/////////// TRUE RANGE CALCULATIONS /////////////////
HiLo = math.min(norm_h - norm_l, 1.5 * nz(ta.sma(norm_h - norm_l, ATRPeriod)))
HRef = norm_l <= norm_h ? norm_h - norm_c : norm_h - norm_c - 0.5 * (norm_l - norm_h )
LRef = norm_h >= norm_l ? norm_c - norm_l : norm_c - norm_l - 0.5 * (norm_l - norm_h)
trueRange = trailType == 'modified' ? math.max(HiLo, HRef, LRef) : math.max(norm_h - norm_l, math.abs(norm_h - norm_c ), math.abs(norm_l - norm_c ))
//}
/////////// TRADE LOGIC ////////////////////////
//{
loss = ATRFactor * Wild_ma(trueRange, ATRPeriod)
Up = norm_c - loss
Dn = norm_c + loss
TrendUp = Up
TrendDown = Dn
Trend = 1
TrendUp := norm_c > TrendUp ? math.max(Up, TrendUp ) : Up
TrendDown := norm_c < TrendDown ? math.min(Dn, TrendDown ) : Dn
Trend := norm_c > TrendDown ? 1 : norm_c < TrendUp ? -1 : nz(Trend , 1)
trail = Trend == 1 ? TrendUp : TrendDown
ex = 0.0
ex := ta.crossover(Trend, 0) ? norm_h : ta.crossunder(Trend, 0) ? norm_l : Trend == 1 ? math.max(ex , norm_h) : Trend == -1 ? math.min(ex , norm_l) : ex
//}
// //////// PLOT TP and SL /////////////
////// FIBONACCI LEVELS ///////////
//{
state = Trend == 1 ? 'long' : 'short'
fib1Level = 61.8
fib2Level = 78.6
fib3Level = 88.6
f1 = ex + (trail - ex) * fib1Level / 100
f2 = ex + (trail - ex) * fib2Level / 100
f3 = ex + (trail - ex) * fib3Level / 100
l100 = trail + 0
fill(plot(ShowSmartTrail ? (ta.sma(trail, smoothing)) : na, 'Trailingstop', style=plot.style_line, color=Trend == 1 ? color.new(#2157f9, 0) : Trend == -1 ? color.new(#ff1100, 0) : na),
plot( ShowSmartTrail ? (ta.sma(f2, smoothing)) : na, 'Fib 2', style=plot.style_line, display=display.none),
color=state == 'long' ? color.new(#2157f9, 80) : state == 'short' ? color.new(#ff1100, 80) : na)
//}
// Trend Lines
shortPeriod = 30
longPeriod = 100
if barstate.islast
float lowest_y2 = 60000
float lowest_x2 = 0
float highest_y2 = 0
float highest_x2 = 0
for i = 1 to shortPeriod by 1
if low < lowest_y2
lowest_y2 := low
lowest_x2 := i
lowest_x2
if high > highest_y2
highest_y2 := high
highest_x2 := i
highest_x2
float lowest_y1 = 60000
float lowest_x1 = 0
float highest_y1 = 0
float highest_x1 = 0
for j = shortPeriod + 1 to longPeriod by 1
if low < lowest_y1
lowest_y1 := low
lowest_x1 := j
lowest_x1
if high > highest_y1
highest_y1 := high
highest_x1 := j
highest_x1
sup = Showtrendlines == true ? line.new(x1=bar_index , y1=lowest_y1, x2=bar_index , y2=lowest_y2, extend=extend.right, width=2, color=#0598ff) : na
res = Showtrendlines == true ? line.new(x1=bar_index , y1=highest_y1, x2=bar_index , y2=highest_y2, extend=extend.right, width=2, color=#fe0101) : na
line.delete(sup )
line.delete(res )
if ta.crossunder(close, line.get_price(sup, bar_index ))
alert('break down trendline', freq=alert.freq_once_per_bar_close)
if ta.crossover(close, line.get_price(res, bar_index ))
alert('break upper trendline', freq=alert.freq_once_per_bar_close)
// Alerts
buyalert = input(true, "Buy Alert", group = 'Alerts')
sellalert = input(true, "Sell Alert", group = 'Alerts')
if bull and buyalert
alert("Buy Alert",alert.freq_once_per_bar_close)
if bear and sellalert
alert("Sell Alert",alert.freq_once_per_bar_close)
CAFX Liquidity Pro V1CAFX Liquidity Pro Indicator
Precision Engineered for Smart Profit-Taking
The CAFX Liquidity Pro Indicator is a powerful trading tool designed to help traders pinpoint high-probability liquidity zones, making it ideal for setting accurate and strategic take profit levels. By identifying where institutional interest is likely to reside, this indicator highlights the areas where price is most likely to react, reverse, or pause—giving you the edge in locking in profits before the market shifts.
Whether you're scalping, day trading, or swing trading, the CAFX Liquidity Pro provides clear visual cues that simplify your decision-making process and enhance your trade management. With a focus on precision and reliability, it helps you avoid emotional exits and instead base your take profits on real market behavior and liquidity dynamics.
Use CAFX Liquidity Pro to stay one step ahead—because knowing where to exit is just as important as knowing when to enter.
TOTOOLI X11 (by 3DOTS)// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org
// © 3DOTS
//Usage : Only Wait for an order block confirmation.
//@version=5
indicator("TOTOOLI X11 (by 3DOTS)" , shorttitle = "This is Totooli for professional usage",overlay = false)
greencolor = #2DD204
redcolor = #D2042D
lightgreencolor = #96E881
lightredcolor = #DF4F6C
darkGreenColor = #1B7E02
darkRedColor = #93021F
kpoDeviations = input.float(2.0, "Deviations", group= "Basic Settings") // Kase peak oscillator deviations
kpoShortCycle = input.int(8, "Short Cycle Period", group= "Basic Settings") // Kase peak oscillator short cycle
kpoLongCycle = input.int(65, "Long Cycle Period", group= "Basic Settings") // Kase peak oscillator long cycle
kpoSensitivity = input.float(40, "Sensitivity", group= "Basic Settings") // Kase peak oscillator sensitivity
allPeaksMode = input.bool(true, "Show all peaks?", group= "Basic Settings") // Show all peaks?
colorbars = input.bool(false, "Color bars?", group= "UI Options")
mutebars = input.bool(false, "Mute bars?", group= "UI Options")
lbR = input(title="Pivot Lookback Right", defval=5, group = "Divergences Settings")
lbL = input(title="Pivot Lookback Left", defval=5, group = "Divergences Settings")
rangeUpper = input(title="Max of Lookback Range", defval=60, group = "Divergences Settings")
rangeLower = input(title="Min of Lookback Range", defval=5, group = "Divergences Settings")
plotBull = input(title="Plot Bullish", defval=true, group = "Divergences Settings")
plotHiddenBull = input(title="Plot Hidden Bullish", defval=false, group = "Divergences Settings")
plotBear = input(title="Plot Bearish", defval=true, group = "Divergences Settings")
plotHiddenBear = input(title="Plot Hidden Bearish", defval=false, group = "Divergences Settings")
bearColor = darkRedColor
bullColor = darkGreenColor
hiddenBullColor = color.new(darkGreenColor, 80)
hiddenBearColor = color.new(darkRedColor, 80)
textColor = color.white
noneColor = color.new(color.white, 100)
x1 = 0.
xs = 0.
x1 := nz(x1 )
xs := nz(xs )
ccLog = math.log(close / nz(close ))
ccDev = ta.stdev(ccLog, 9)
avg = ta.sma(ccDev, 30)
max1 = 0.
maxs = 0.
for k = kpoShortCycle to kpoLongCycle - 1
max1 := math.max(math.log(high / nz(low )) / math.sqrt(k), max1)
maxs := math.max(math.log(nz(high ) / low) / math.sqrt(k), maxs)
x1 := max1 / avg
xs := maxs / avg
xp = kpoSensitivity * (ta.sma(x1, 3) - ta.sma(xs, 3))
xpAbs = math.abs(xp)
kppBuffer = 0.
kpoBuffer = xp
kphBuffer = xp
tmpVal = ta.sma(xpAbs, 50) + kpoDeviations * (ta.stdev(xpAbs, 50))
maxVal = math.max(90.0, tmpVal)
minVal = math.min(90.0, tmpVal)
kpdBuffer = 0.
kpmBuffer = 0.
if kpoBuffer > 0.
kpdBuffer := maxVal
kpmBuffer := minVal
else
kpdBuffer := -maxVal
kpmBuffer := -minVal
if (not allPeaksMode)
if (nz(kpoBuffer ) > 0 and nz(kpoBuffer ) > kpoBuffer and nz(kpoBuffer ) >= nz(kpoBuffer ) and nz(kpoBuffer ) >= maxVal)
kppBuffer := kpoBuffer
if (nz(kpoBuffer ) < 0 and nz(kpoBuffer ) < kpoBuffer and nz(kpoBuffer ) <= nz(kpoBuffer ) and nz(kpoBuffer ) <= -maxVal)
kppBuffer := kpoBuffer
else
if (nz(kpoBuffer ) > 0 and nz(kpoBuffer ) > kpoBuffer and nz(kpoBuffer ) >= nz(kpoBuffer ))
kppBuffer := kpoBuffer
if (nz(kpoBuffer ) < 0 and nz(kpoBuffer ) < kpoBuffer and nz(kpoBuffer ) <= nz(kpoBuffer ))
kppBuffer := kpoBuffer
plot(kpoBuffer, "Kase Peak Oscillator", color = color.gray)
plot(kphBuffer, "Kase Peak Oscillator Histogram", color = color.gray, style=plot.style_histogram)
plot(kpdBuffer, "Max Peak Value", color = color.blue, linewidth = 1) //Blue Kpeak-Min line is a maximum of two standard deviations of the PeakOscillator value.
//plot(kpmBuffer, "Min Peak Value", color = color.white, linewidth = 1) //Red PeakOut line is a minimum of two standard deviations of the PeakOscillator value
colorout = kppBuffer ? kppBuffer > 0 ? redcolor : greencolor : mutebars ? color.gray : na
plot(kppBuffer, "Market Extreme", color = kppBuffer ? colorout : na, style = plot.style_histogram, linewidth = 3)
barcolor(colorbars ? colorout : na)
osc = kpoBuffer
plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true
phFound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true
_inRange(cond) =>
bars = ta.barssince(cond == true)
rangeLower <= bars and bars <= rangeUpper
//------------------------------------------------------------------------------
// Regular Bullish
// Osc: Higher Low
oscHL = osc > ta.valuewhen(plFound, osc , 1) and _inRange(plFound )
// Price: Lower Low
priceLL = low < ta.valuewhen(plFound, low , 1)
bullCond = plotBull and priceLL and oscHL and plFound
plot(
plFound ? osc : na,
offset=-lbR,
title="Regular Bullish",
linewidth=2,
color=(bullCond ? bullColor : noneColor)
)
plotshape(
bullCond ? osc : na,
offset=-lbR,
title="Regular Bullish Label",
text="R",
style=shape.labelup,
location=location.absolute,
color=bullColor,
textcolor=textColor
)
//------------------------------------------------------------------------------
// Hidden Bullish
// Osc: Lower Low
oscLL = osc < ta.valuewhen(plFound, osc , 1) and _inRange(plFound )
// Price: Higher Low
priceHL = low > ta.valuewhen(plFound, low , 1)
hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound
plot(
plFound ? osc : na,
offset=-lbR,
title="Hidden Bullish",
linewidth=2,
color=(hiddenBullCond ? hiddenBullColor : noneColor)
)
plotshape(
hiddenBullCond ? osc : na,
offset=-lbR,
title="Hidden Bullish Label",
text="H",
style=shape.labelup,
location=location.absolute,
color=bullColor,
textcolor=textColor
)
//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High
oscLH = osc < ta.valuewhen(phFound, osc , 1) and _inRange(phFound )
// Price: Higher High
priceHH = high > ta.valuewhen(phFound, high , 1)
bearCond = plotBear and priceHH and oscLH and phFound
plot(
phFound ? osc : na,
offset=-lbR,
title="Regular Bearish",
linewidth=2,
color=(bearCond ? bearColor : noneColor)
)
plotshape(
bearCond ? osc : na,
offset=-lbR,
title="Regular Bearish Label",
text="R",
style=shape.labeldown,
location=location.absolute,
color=bearColor,
textcolor=textColor
)
//------------------------------------------------------------------------------
// Hidden Bearish
// Osc: Higher High
oscHH = osc > ta.valuewhen(phFound, osc , 1) and _inRange(phFound )
// Price: Lower High
priceLH = high < ta.valuewhen(phFound, high , 1)
hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound
plot(
phFound ? osc : na,
offset=-lbR,
title="Hidden Bearish",
linewidth=2,
color=(hiddenBearCond ? hiddenBearColor : noneColor)
)
plotshape(
hiddenBearCond ? osc : na,
offset=-lbR,
title="Hidden Bearish Label",
text="H",
style=shape.labeldown,
location=location.absolute,
color=bearColor,
textcolor=textColor
)
goLong = kppBuffer < 0
goShort = kppBuffer > 0
alertcondition(goLong, title="Long", message="Kase Peak Oscillator w/ Divergences : Long Symbol: {{ticker}} Price: {{close}}")
alertcondition(goShort, title="Short", message="Kase Peak Oscillator w/ Divergences : Short Symbol: {{ticker}} Price: {{close}}")
alertcondition(hiddenBearCond, title="Hidden Bear Divergence", message="Kase Peak Oscillator w/ Divergences : Hidden Bear Divergence Symbol: {{ticker}} Price: {{close}}")
alertcondition(bearCond, title="Regular Bear Divergence", message="Kase Peak Oscillator w/ Divergences : Regular Bear Divergence Symbol: {{ticker}} Price: {{close}}")
alertcondition(hiddenBullCond, title="Hidden Bull Divergence", message="Kase Peak Oscillator w/ Divergences : Hidden Bull Divergence Symbol: {{ticker}} Price: {{close}}")
alertcondition(bullCond, title="Regular Bull Divergence", message="Kase Peak Oscillator w/ Divergences : Regular Bull Divergence Symbol: {{ticker}} Price: {{close}}")
//********************************
var string GP3 = "Power 3 Visual"
i_label_toggle = input.bool(defval=true, title="", group=GP3, inline="labels")
i_label_text_color = input.color(defval=color.rgb(255, 255, 255, 0), title="Display Labels", group=GP3, inline="labels")
c_tooltip_timeframe = "Switch the Power 3 Visual between the current Day or current Week"
i_timeframe = input.timeframe(defval="W", title="Timeframe", options= , group=GP3, tooltip=c_tooltip_timeframe)
i_daily_start = input.timeframe(defval="Midnight", title="Daily Start", options= , group=GP3, tooltip="Pick either Daily open price or Midnight EST open price")
c_tooltip_move = "The Futures market is open 23/5. It is closed everyday for 1-hour at 5pm EST and closed over the weekends. Because this Intraday Power 3 Visual is drawing in the 'future' on the users TradingView chart, when the visual is close or in a time when the market is closed, the visual doesn't behave properly. This is because TradingView doesn't display times when the Market is closed, thus the drawings cannot be displayed during those times. There is nothing wrong with the script. Please wait until the Market is open and the visual will be drawn normally."
i_right_movement = input.int(defval=5, minval=1, step=1, title="Visual Right Movement", group=GP3, tooltip=c_tooltip_move)
i_line_color = input.color(defval=color.rgb(255, 255, 255, 0), title="Line Color", group=GP3)
i_line_width = input.int(defval=2, minval=1, maxval=20, step=1, title="Line Width", group=GP3)
i_line_style = input.string(defval="solid (-)", title="Line Style", options= , group=GP3)
///////////////////////////////////////////////////////////////////////////////// HELPER FUNCTIONS
// Function the converts string inputs to line style code
line_style_function(input_var) =>
switch input_var
"dotted (?)" => line.style_dotted
"dashed (?)" => line.style_dashed
=> line.style_solid
///////////////////////////////////////////////////////////////////////////////// TIMEFRAME
timeframe_high = request.security(syminfo.tickerid, i_timeframe, high)
timeframe_low = request.security(syminfo.tickerid, i_timeframe, low)
timeframe_open_req = request.security(syminfo.tickerid, i_timeframe, open)
timeframe_close = request.security(syminfo.tickerid, i_timeframe, close)
// Logic for midnight est open or daily open
// Time variables
midnight_window = (hour(time, "America/New_York") == 0) and (minute(time) == 0)
midnight_timespan_est = time(timeframe.period, '0001-1659', "America/New_York")
var float midnight_open = na
var float timeframe_open = na
if i_timeframe == "W"
timeframe_open := timeframe_open_req
else
// Timeframe set to daily
if i_daily_start == "Open"
timeframe_open := timeframe_open_req
else
// Get price at midnight open EST
if midnight_window
midnight_open := open
// If time is after midnight est then use midnight price, if price before midnight price then use daily open price
if midnight_timespan_est
timeframe_open := midnight_open
else
timeframe_open := timeframe_open_req
///////////////////////////////////////////////////////////////////////////////// BULL & BEAR VARIABLES
var float manipulation_value = na
var float distribution_value = na
range_explansion_value = (timeframe_open + timeframe_close) / 2
// Sets values based on whether daily/weekly range is bear or bull direction
if timeframe_open > timeframe_close
// Bearish candle
manipulation_value := (timeframe_open + timeframe_high) / 2
distribution_value := (timeframe_close + timeframe_low) / 2
else
// Bullish candle
manipulation_value := (timeframe_open + timeframe_low) / 2
distribution_value := (timeframe_close + timeframe_high) / 2
///////////////////////////////////////////////////////////////////////////////// POWER 3 VISUAL
// Move timebased labels right
dt = time + i_right_movement * (time - time )
dt_current = time + (i_right_movement * 2) * (time - time )
// Visual line style
line_style_power3 = line_style_function(i_line_style)
// Set defaults for all lines and labels
var line line_vertical = na
var line line_power3_open = na
var line line_power3_current = na
var label label_range_expansion = na
var label label_accumulation = na
var label label_manipulation = na
var label label_distribution = na
// Saves TradingView resources by only drawing the visual once
if timeframe.isintraday and barstate.islast
// Draw Power 3 lines
// Vertical line
line_vertical := line.new(x1=dt, y1=timeframe_high, x2=dt, y2=timeframe_low, xloc=xloc.bar_time, color=i_line_color, style=line_style_power3, width=i_line_width,force_overlay = true)
line.delete(line_vertical )
// Left horizontal line
line_power3_open := line.new(x1=time, y1=timeframe_open, x2=dt, y2=timeframe_open, xloc=xloc.bar_time, color=i_line_color, style=line_style_power3, width=i_line_width,force_overlay = true)
line.delete(line_power3_open )
// Right horizontal line
line_power3_current := line.new(x1=dt, y1=timeframe_close, x2=dt_current, y2=timeframe_close, xloc=xloc.bar_time, color=i_line_color, style=line_style_power3, width=i_line_width,force_overlay = true)
line.delete(line_power3_current )
// Toggle on/off lables
if i_label_toggle
// Place labels
// Range Expanseion label
label_range_expansion := label.new(x=dt, y=range_explansion_value, text="Range Expansion", xloc=xloc.bar_time, style=label.style_none, textcolor=i_label_text_color, textalign=text.align_center, tooltip="Range Expansion is ...",force_overlay = true)
label.delete(label_range_expansion )
// Accumulation label
label_accumulation := label.new(x=dt, y=timeframe_open, text="Accumulation", xloc=xloc.bar_time, style=label.style_none, textcolor=i_label_text_color, textalign=text.align_right, tooltip="Accumulation is ...",force_overlay = true)
label.delete(label_accumulation )
// Manipulation label
label_manipulation := label.new(x=dt, y=manipulation_value, text="Manipulation", xloc=xloc.bar_time, style=label.style_none, textcolor=i_label_text_color, textalign=text.align_center, tooltip="Manipulation is ...",force_overlay = true)
label.delete(label_manipulation )
// Distribution label
label_distribution := label.new(x=dt, y=distribution_value, text="Distribution", xloc=xloc.bar_time, style=label.style_none, textcolor=i_label_text_color, textalign=text.align_center, tooltip="Distribution is ...",force_overlay = true)
label.delete(label_distribution )
// RSI Settings for user
rsiSource = input(title='RSI Source', defval=close)
rsiLength = input(title='RSI Length', defval=7)
rsiOverbought1 = input.int(title='RSI Overbought', defval=70, minval=50, maxval=100)
rsiOvesold = input.int(title='RSI Oversold', defval=30, minval=1, maxval=50)
upcol = input(defval=color.new(color.olive,100), title='Zig Zag 1 Up Color')
dncol = input(defval=color.new(color.fuchsia,100), title='Zig Zag 1 Down Color')
// RSI value based on inbuilt RSI
rsiValue = ta.rsi(rsiSource, rsiLength)
// Get the current state
isOverbought = rsiValue >= rsiOverbought1
isOversold = rsiValue <= rsiOvesold
// State of the last extreme 0 for initialization, 1 = overbought, 2 = oversold
var laststate = 0
// Highest and Lowest prices since the last state change
var hhh = low
var lll = high
// Labels
var label labelll = na
var label labelhh = na
// Swing lines
var line line_up = na
var line line_down = na
// We go from overbought straight to oversold NEW DRAWINGS CREATED HERE
if laststate == 1 and isOversold
lll := low
labelll := label.new(bar_index, high, style=label.style_label_up, color=color.rgb(0,255,0,35), size=size.small,force_overlay = true)
label.set_text( labelll, "Wait for" + " " + "Confirmation" + " " + "BUY")
labelhh_low = label.get_x(labelhh)
labelhh_pos = label.get_y(labelhh)
line_down := line.new(bar_index, high, labelhh_low, labelhh_pos, width=2, color = dncol,force_overlay = true)
label.set_text(id=labelll, text="Wait for" + " " + "Confirmation" + " " + "BUY")
// We go from oversold straight to overbought NEW DRAWINGS CREATED HERE
if laststate == 2 and isOverbought
hhh := high
labelhh := label.new(bar_index, high, style=label.style_label_down, color=color.rgb(255,0,98,35), size=size.small,force_overlay = true)
label.set_text( labelhh, "SELL" + " " + "Wait for" + " " + "Confirmation")
labelll_low = label.get_x(labelll)
labelll_pos = label.get_y(labelll)
line_up := line.new(bar_index, high, labelll_low, labelll_pos, width=2, color = upcol,force_overlay = true)
// If we are overbought
if isOverbought
if high >= hhh
hhh := high
label.set_x(labelhh, bar_index)
label.set_y(labelhh, high)
line.set_x1(line_up, bar_index)
line.set_y1(line_up, high)
laststate := 1
laststate
// If we are oversold
if isOversold
if low <= lll
lll := low
label.set_x(labelll, bar_index)
label.set_y(labelll, low)
line.set_x1(line_down, bar_index)
line.set_y1(line_down, low)
laststate := 2
laststate
// If last state was overbought and we are overbought
if laststate == 1 and isOverbought
if hhh <= high
hhh := high
label.set_x(labelhh, bar_index)
label.set_y(labelhh, high)
line.set_x1(line_up, bar_index)
line.set_y1(line_up, high)
//If we are oversold and the last state was oversold, move the drawings to the lowest price
if laststate == 2 and isOversold
if low <= lll
lll := low
label.set_x(labelll, bar_index)
label.set_y(labelll, low)
line.set_x1(line_down, bar_index)
line.set_y1(line_down, low)
// If last state was overbought
if laststate == 1
if hhh <= high
hhh := high
label.set_x(labelhh, bar_index)
label.set_y(labelhh, high)
line.set_x1(line_up, bar_index)
line.set_y1(line_up, high)
// If last stare was oversold
if laststate == 2
if lll >= low
lll := low
label.set_x(labelll, bar_index)
label.set_y(labelll, low)
line.set_x1(line_down, bar_index)
line.set_y1(line_down, low)
lb = input.int(3, title='Left Bars', minval=1)
rb = input.int(15, title='Right Bars', minval=1)
showsupres = input.bool(true, title='Support/Resistance', inline='srcol')
supcol = input.color(color.white, title='', inline='srcol')
rescol = input.color(color.white, title='', inline='srcol')
srlinestyle = input.string(line.style_dashed, title='Line Style/Width', options= , inline='style')
srlinewidth = input.int(1, title='', minval=1, maxval=5, inline='style')
//changebarcol = input.bool(true, title='Change Bar Color', inline='bcol')
//bcolup = input.color(color.blue, title='', inline='bcol')
//bcoldn = input.color(color.black, title='', inline='bcol')
phh = ta.pivothigh(lb, rb)
pll = ta.pivotlow(lb, rb)
iff_1 = pll ? -1 : na // Trend direction
hl = phh ? 1 : iff_1
iff_2 = pll ? pll : na // similar to zigzag but may have multiple highs/lows
zz = phh ? phh : iff_2
valuewhen_1 = ta.valuewhen(hl, hl, 1)
valuewhen_2 = ta.valuewhen(zz, zz, 1)
zz := pll and hl == -1 and valuewhen_1 == -1 and pll > valuewhen_2 ? na : zz
valuewhen_3 = ta.valuewhen(hl, hl, 1)
valuewhen_4 = ta.valuewhen(zz, zz, 1)
zz := phh and hl == 1 and valuewhen_3 == 1 and phh < valuewhen_4 ? na : zz
valuewhen_5 = ta.valuewhen(hl, hl, 1)
valuewhen_6 = ta.valuewhen(zz, zz, 1)
hl := hl == -1 and valuewhen_5 == 1 and zz > valuewhen_6 ? na : hl
valuewhen_7 = ta.valuewhen(hl, hl, 1)
valuewhen_8 = ta.valuewhen(zz, zz, 1)
hl := hl == 1 and valuewhen_7 == -1 and zz < valuewhen_8 ? na : hl
zz := na(hl) ? na : zz
findprevious() => // finds previous three points (b, c, d, e)
ehl = hl == 1 ? -1 : 1
loc1 = 0.0
loc2 = 0.0
loc3 = 0.0
loc4 = 0.0
xx = 0
for x = 1 to 1000 by 1
if hl == ehl and not na(zz )
loc1 := zz
xx := x + 1
break
ehl := hl
for x = xx to 1000 by 1
if hl == ehl and not na(zz )
loc2 := zz
xx := x + 1
break
ehl := hl == 1 ? -1 : 1
for x = xx to 1000 by 1
if hl == ehl and not na(zz )
loc3 := zz
xx := x + 1
break
ehl := hl
for x = xx to 1000 by 1
if hl == ehl and not na(zz )
loc4 := zz
break
float aa = na
float bb = na
float w = na
float dd = na
float e = na
if not na(hl)
= findprevious()
aa := zz
bb := loc1
w := loc2
dd := loc3
e := loc4
e
_hh = zz and aa > bb and aa > w and w > bb and w > dd
_ll = zz and aa < bb and aa < w and w < bb and w < dd
_hl = zz and (aa >= w and bb > w and bb > dd and dd > w and dd > e or aa < bb and aa > w and bb < dd)
_lh = zz and (aa <= w and bb < w and bb < dd and dd < w and dd < e or aa > bb and aa < w and bb > dd)
plotshape(_hl, text='HL', title='Higher Low', style=shape.labelup, color=color.new(color.white, 0), textcolor=color.new(color.black, 0), location=location.belowbar, offset=-rb,force_overlay = true)
//plotshape(_hh, text='HH', title='Higher High', style=shape.labeldown, color=color.new(color.aqua, 0), textcolor=color.new(color.black, 0), location=location.abovebar, offset=-rb)
//plotshape(_ll, text='LL', title='Lower Low', style=shape.labelup, color=color.new(color.red, 0), textcolor=color.new(color.white, 0), location=location.belowbar, offset=-rb)
plotshape(_lh, text='LH', title='Lower High', style=shape.labeldown, color=color.new(color.white, 0), textcolor=color.new(color.black, 0), location=location.abovebar, offset=-rb,force_overlay = true)
float res1 = na
float sup = na
res1 := _lh ? zz : res1
sup := _hl ? zz : sup
int trend = na
iff_3 = close < sup ? -1 : nz(trend )
trend := close > res1 ? 1 : iff_3
res1 := trend == 1 and _hh or trend == -1 and _lh ? zz : res1
sup := trend == 1 and _hl or trend == -1 and _ll ? zz : sup
rechange = res1 != res1
suchange = sup != sup
var line resline = na
var line supline = na
if showsupres
if rechange
line.set_x2(resline, bar_index)
line.set_extend(resline, extend=extend.none)
resline := line.new(x1=bar_index - rb, y1=res1, x2=bar_index, y2=res1, color=rescol, extend=extend.right, style=srlinestyle, width=srlinewidth,force_overlay = true)
resline
if suchange
line.set_x2(supline, bar_index)
line.set_extend(supline, extend=extend.none)
supline := line.new(x1=bar_index - rb, y1=sup, x2=bar_index, y2=sup, color=supcol, extend=extend.right, style=srlinestyle, width=srlinewidth,force_overlay = true)
supline
//iff_4 = trend == 1 ? bcolup : bcoldn
//
CRAK1 = input.int(13, step=10)
CRAK2 = input.int(17, step=10)
CRAK3 = input.int(110, step=10)
CRAK4 = input.int(109, step=10)
CRAK5 = input.int(103, step=10)
CRAK6 = input.int(1, step=10)
CRAK7 = input.int(1, step=10)
CRAK8 = input.int(9, step=10)
CRAK9 = input.int(11, step=10)
CRAK10 = input.int(120, step=10)
CRAK11 = input.int(200, step=10)
CRAK12 = input.int(200, step=10)
CRAK13 = input.int(110, step=10)
CRAK14 = input.int(11, step=10)
CRAK15 = input.int(12, step=10)
CRAK16 = input.int(2, step=10)
CRAK17 = input.int(1, step=10)
CRAK18 = input.int(2, step=10)
CRAK19 = input.int(1, step=10)
CRAK20 = input.int(2, step=10)
///
DETECT3 = input.int(18, step=10)
PATTERN1 = input(true)
PATTERN10 = input.int(18, step=5, minval=1)
COLORP1 = input(color.rgb(43, 52, 146, 55))
zigzag1Width = 1
zigzag1Style = line.style_dotted
PATTERN2 = input(true)
PATTERN20 = input.int(24, step=5, minval=1)
COLORP2 = input(color.rgb(43, 52, 146, 55))
zigzag2Width = 1
zigzag2Style = line.style_dotted
PATTERN3 = input(true)
PATTERN30 = input.int(32, step=5, minval=1)
COLORP3 = input(color.rgb(43, 52, 146, 55))
zigzag3Width = 1
zigzag3Style = line.style_dotted
PATTERN4 = input(true)
PATTERN40 = input.int(38, step=5, minval=1)
COLORP4 = input(color.rgb(43, 52, 146, 55))
zigzag4Width = 1
zigzag4Style = line.style_dotted
P11 = input(true)
P22 = input(true)
P33 = input(true)
P44 = input(true)
P55 = input(true)
P66 = input(true)
DETECTM = input.int(18, minval=5, step=5, maxval=200)
//
DATAC = input.int(350, step=10)
DATAC2 = input.int(400, step=10)
//
MaxRiskPerReward = input.int(29, title='DETECT/PER', step=10, minval=0)
//
//
E1 = input.int(370, step=10)
E2 = input.int(390, step=10)
showStatTable = false
CANCLE_PATTERNS = input(false)
//
CRAKD90 = input.int(200, step=10)
CRAKFALSE200 = input.int(200, step=10)
CRAKFALSE100 = input.int(300, step=10)
///
BULL_PATTERNS = input(color.silver)
BEAR_PATTERNS = input(color.blue)
err_min = (100 - DETECTM) / 100
err_max = (100 + DETECTM) / 100
var zigzagpivots1 = array.new_float(0)
var zigzagpivotbars1 = array.new_int(0)
var zigzagpivotdirs1 = array.new_int(0)
var zigzagpivots2 = array.new_float(0)
var zigzagpivotbars2 = array.new_int(0)
var zigzagpivotdirs2 = array.new_int(0)
var zigzagpivots3 = array.new_float(0)
var zigzagpivotbars3 = array.new_int(0)
var zigzagpivotdirs3 = array.new_int(0)
var zigzagpivots4 = array.new_float(0)
var zigzagpivotbars4 = array.new_int(0)
var zigzagpivotdirs4 = array.new_int(0)
var wmlines1 = array.new_line(8)
var wmtype1 = array.new_int(2, 1)
var wmLabels1 = array.new_bool(13, false)
var wmLabel1 = array.new_label(1)
var wmlines2 = array.new_line(8)
var wmtype2 = array.new_int(2, 1)
var wmLabels2 = array.new_bool(13, false)
var wmLabel2 = array.new_label(1)
var wmlines3 = array.new_line(8)
var wmtype3 = array.new_int(2, 1)
var wmLabels3 = array.new_bool(13, false)
var wmLabel3 = array.new_label(1)
var wmlines4 = array.new_line(8)
var wmtype4 = array.new_int(2, 1)
var wmLabels4 = array.new_bool(13, false)
var wmLabel4 = array.new_label(1)
pivots(length) =>
float phigh = ta.highestbars(high, length) == 0 ? high : na
float plow = ta.lowestbars(low, length) == 0 ? low : na
dir = 0
iff_1 = plow and na(phigh) ? -1 : dir
dir := phigh and na(plow) ? 1 : iff_1
zigzag(length, zigzagpivots, zigzagpivotbars, zigzagpivotdirs) =>
= pivots(length)
dirchanged = ta.change(dir)
if phigh or plow
value = dir == 1 ? phigh : plow
bar = bar_index
newDir = dir
if not dirchanged and array.size(zigzagpivots) >= 1
pivot = array.shift(zigzagpivots)
pivotbar = array.shift(zigzagpivotbars)
pivotdir = array.shift(zigzagpivotdirs)
useNewValues = value * pivotdir < pivot * pivotdir
value := useNewValues ? pivot : value
bar := useNewValues ? pivotbar : bar
bar
if array.size(zigzagpivots) >= 2
LastPoint = array.get(zigzagpivots, 1)
newDir := dir * value > dir * LastPoint ? dir * 2 : dir
newDir
array.unshift(zigzagpivots, value=value)
array.unshift(zigzagpivotbars, bar)
array.unshift(zigzagpivotdirs, newDir)
if array.size(zigzagpivots) > DETECT3
array.pop(zigzagpivots)
array.pop(zigzagpivotbars)
array.pop(zigzagpivotdirs)
get_harmonic_label(wmLabels, dir, price, bar) =>
isP11 = array.get(wmLabels, 0)
isP22 = array.get(wmLabels, 1)
isP33 = array.get(wmLabels, 2)
isP44 = array.get(wmLabels, 3)
isP55 = array.get(wmLabels, 4)
isP66 = array.get(wmLabels, 5)
labelText = isP11 ? 'Gartley' : ''
labelText := labelText + (isP22 ? (labelText == '' ? '' : ' ') + 'Crab' : '')
labelText := labelText + (isP33 ? (labelText == '' ? '' : ' ') + 'Deep Crab' : '')
labelText := labelText + (isP44 ? (labelText == '' ? '' : ' ') + 'Bat' : '')
labelText := labelText + (isP55 ? (labelText == '' ? '' : ' ') + 'Butterfly' : '')
labelText := labelText + (isP66 ? (labelText == '' ? '' : ' ') + 'Shark' : '')
trendColor = dir > 0 ? BULL_PATTERNS : BEAR_PATTERNS
baseLabel = label.new(x=bar, y=price, text=labelText, yloc=yloc.price, color=trendColor, style=dir < 1 ? label.style_label_down : label.style_label_up, textcolor=color.black, size=size.normal,force_overlay = true)
//baseLabel
detect_harmonic_pattern(zigzagpivots, zigzagpivotbars, zigzagpivotdirs, wmlines, wmlabel, wmtype, wmLabels, zigzagColor, zigzagWidth, zigzagStyle, showZigZag) =>
start = CANCLE_PATTERNS ? 1 : 0
wm_pattern = false
abcd_pattern = false
double_pattern = false
if array.size(zigzagpivots) >= 6 + start and showZigZag
d = array.get(zigzagpivots, start + 0)
dBar = array.get(zigzagpivotbars, start + 0)
dDir = array.get(zigzagpivotdirs, start + 0)
c = array.get(zigzagpivots, start + 1)
cBar = array.get(zigzagpivotbars, start + 1)
cDir = array.get(zigzagpivotdirs, start + 1)
b = array.get(zigzagpivots, start + 2)
bBar = array.get(zigzagpivotbars, start + 2)
bDir = array.get(zigzagpivotdirs, start + 2)
a = array.get(zigzagpivots, start + 3)
aBar = array.get(zigzagpivotbars, start + 3)
aDir = array.get(zigzagpivotdirs, start + 3)
x = array.get(zigzagpivots, start + 4)
xBar = array.get(zigzagpivotbars, start + 4)
xDir = array.get(zigzagpivotdirs, start + 4)
y = array.get(zigzagpivots, start + 5)
yBar = array.get(zigzagpivotbars, start + 5)
yDir = array.get(zigzagpivotdirs, start + 5)
highPoint = math.max(x, a, b, c, d)
lowPoint = math.min(x, a, b, c, d)
dir = c > d ? 1 : -1
xabRatio = math.abs(b - a) / math.abs(x - a)
abcRatio = math.abs(c - b) / math.abs(a - b)
bcdRatio = math.abs(d - c) / math.abs(b - c)
xadRatio = math.abs(d - a) / math.abs(x - a)
yxaRatio = math.abs(a - x) / math.abs(y - x)
abTime = math.abs(aBar - bBar)
cdTime = math.abs(cBar - dBar)
abPrice = math.abs(a - b)
cdPrice = math.abs(c - d)
time_ratio = cdTime / abTime
price_ratio = cdPrice / abPrice
abcdDirection = a < b and a < c and c < b and c < d and a < d and b < d ? 1 : a > b and a > c and c > b and c > d and a > d and b > d ? -1 : 0
risk = math.abs(b - d)
reward = math.abs(c - d)
riskPerReward = risk * 100 / (risk + reward)
if b < highPoint and b > lowPoint
//gartley
if P11 and xabRatio >= 0.588 * err_min and xabRatio <= 0.648 * err_max and abcRatio >= 0.382 * err_min and abcRatio <= 0.886 * err_max and xadRatio >= 0.786 * err_min and xadRatio <= 0.886 * err_max
wm_pattern := true
array.set(wmLabels, 0, true)
else
array.set(wmLabels, 0, false)
//Crab
if P22 and xabRatio >= 0.382 * err_min and xabRatio <= 0.618 * err_max and abcRatio >= 0.382 * err_min and abcRatio <= 0.886 * err_max and xadRatio >= 1.618 * err_min and xadRatio <= 1.902 * err_max
wm_pattern := true
array.set(wmLabels, 1, true)
else
array.set(wmLabels, 1, false)
//Deep Crab
if P33 and xabRatio >= 0.886 * err_min and xabRatio <= 0.936 * err_max and abcRatio >= 0.382 * err_min and abcRatio <= 0.886 * err_max and xadRatio >= 1.618 * err_min and xadRatio <= 1.902 * err_max
wm_pattern := true
array.set(wmLabels, 2, true)
else
array.set(wmLabels, 2, false)
//Bat
if P44 and xabRatio >= 0.382 * err_min and xabRatio <= 0.55 * err_max and abcRatio >= 0.382 * err_min and abcRatio <= 0.886 * err_max and xadRatio >= 0.886 * err_min and xadRatio <= 0.886 * err_max
wm_pattern := true
array.set(wmLabels, 3, true)
else
array.set(wmLabels, 3, false)
//Butterfly
if P55 and xabRatio >= 0.755 * err_min and xabRatio <= 0.816 * err_max and abcRatio >= 0.382 * err_min and abcRatio <= 0.886 * err_max and xadRatio >= 1.272 * err_min and xadRatio <= 1.272 * err_max
wm_pattern := true
array.set(wmLabels, 4, true)
else
array.set(wmLabels, 4, false)
//Shark
if P66 and xabRatio >= 0.382 * err_min and xabRatio <= 0.618 * err_max and abcRatio >= 1.13 * err_min and abcRatio <= 1.618 * err_max and xadRatio >= 0.886 * err_min and xadRatio <= 1.13 * err_max
wm_pattern := true
array.set(wmLabels, 5, true)
else
array.set(wmLabels, 5, false)
cancelW = false
cancelA = false
cancelD = false
if wm_pattern and x == x and a == a and b == b and c == c
line.delete(array.get(wmlines, 0))
line.delete(array.get(wmlines, 1))
line.delete(array.get(wmlines, 2))
line.delete(array.get(wmlines, 3))
line.delete(array.get(wmlines, 4))
line.delete(array.get(wmlines, 5))
line.delete(array.get(wmlines, 6))
line.delete(array.get(wmlines, 7))
label.delete(array.get(wmlabel, 0))
cancelW := true
cancelW
if abcd_pattern and a == a and b == b and c == c
line.delete(array.get(wmlines, 1))
line.delete(array.get(wmlines, 2))
line.delete(array.get(wmlines, 3))
label.delete(array.get(wmlabel, 0))
cancelA := true
cancelA
if double_pattern and a == a and b == b and c == c
line.delete(array.get(wmlines, 5))
label.delete(array.get(wmlabel, 0))
cancelD := true
cancelD
if wm_pattern
xa = line.new(y1=x, y2=a, x1=xBar, x2=aBar, color=zigzagColor, width=zigzagWidth, style=zigzagStyle,force_overlay = true)
ab = line.new(y1=a, y2=b, x1=aBar, x2=bBar, color=zigzagColor, width=zigzagWidth, style=zigzagStyle,force_overlay = true)
bc = line.new(y1=b, y2=c, x1=bBar, x2=cBar, color=zigzagColor, width=zigzagWidth, style=zigzagStyle,force_overlay = true)
cd = line.new(y1=c, y2=d, x1=cBar, x2=dBar, color=zigzagColor, width=zigzagWidth, style=zigzagStyle,force_overlay = true)
xb = line.new(y1=x, y2=b, x1=xBar, x2=bBar, color=zigzagColor, width=zigzagWidth, style=zigzagStyle,force_overlay = true)
bd = line.new(y1=b, y2=d, x1=bBar, x2=dBar, color=zigzagColor, width=zigzagWidth, style=zigzagStyle,force_overlay = true)
xd = line.new(y1=x, y2=d, x1=xBar, x2=dBar, color=zigzagColor, width=zigzagWidth, style=zigzagStyle,force_overlay = true)
ac = line.new(y1=a, y2=c, x1=aBar, x2=cBar, color=zigzagColor, width=zigzagWidth, style=zigzagStyle,force_overlay = true)
array.set(wmlines, 0, xa)
array.set(wmlines, 1, ab)
array.set(wmlines, 2, bc)
array.set(wmlines, 3, cd)
array.set(wmlines, 4, xb)
array.set(wmlines, 5, bd)
array.set(wmlines, 6, xd)
array.set(wmlines, 7, ac)
array.set(wmtype, 0, dir)
linefill.new(xa, xb, color=color.rgb(44, 93, 136, 94))
linefill.new(bc, bd, color=color.rgb(44, 93, 136, 94))
if abcd_pattern and not wm_pattern
ab = line.new(y1=a, y2=b, x1=aBar, x2=bBar, color=zigzagColor, width=zigzagWidth, style=zigzagStyle)
bc = line.new(y1=b, y2=c, x1=bBar, x2=cBar, color=zigzagColor, width=zigzagWidth, style=zigzagStyle)
cd = line.new(y1=c, y2=d, x1=cBar, x2=dBar, color=zigzagColor, width=zigzagWidth, style=zigzagStyle)
array.set(wmlines, 1, ab)
array.set(wmlines, 2, bc)
array.set(wmlines, 3, cd)
array.set(wmtype, 0, dir)
if double_pattern and not wm_pattern
bd = line.new(y1=b, y2=d, x1=bBar, x2=dBar, color=zigzagColor, width=zigzagWidth, style=zigzagStyle)
array.set(wmlines, 5, bd)
array.set(wmtype, 0, dir)
if wm_pattern or abcd_pattern or double_pattern
array.set(wmlabel, 0, get_harmonic_label(wmLabels, dir, d, dBar))
pattern = wm_pattern and not wm_pattern or abcd_pattern and not abcd_pattern or double_pattern and not double_pattern
pattern
zigzag(PATTERN10, zigzagpivots1, zigzagpivotbars1, zigzagpivotdirs1)
zigzag(PATTERN20, zigzagpivots2, zigzagpivotbars2, zigzagpivotdirs2)
zigzag(PATTERN30, zigzagpivots3, zigzagpivotbars3, zigzagpivotdirs3)
zigzag(PATTERN40, zigzagpivots4, zigzagpivotbars4, zigzagpivotdirs4)
wm_pattern1 = detect_harmonic_pattern(zigzagpivots1, zigzagpivotbars1, zigzagpivotdirs1, wmlines1, wmLabel1, wmtype1, wmLabels1, COLORP1, zigzag1Width, zigzag1Style, PATTERN1)
wm_pattern2 = detect_harmonic_pattern(zigzagpivots2, zigzagpivotbars2, zigzagpivotdirs2, wmlines2, wmLabel2, wmtype2, wmLabels2, COLORP2, zigzag2Width, zigzag2Style, PATTERN2)
wm_pattern3 = detect_harmonic_pattern(zigzagpivots3, zigzagpivotbars3, zigzagpivotdirs3, wmlines3, wmLabel3, wmtype3, wmLabels3, COLORP3, zigzag3Width, zigzag3Style, PATTERN3)
wm_pattern4 = detect_harmonic_pattern(zigzagpivots4, zigzagpivotbars4, zigzagpivotdirs4, wmlines4, wmLabel4, wmtype4, wmLabels4, COLORP4, zigzag4Width, zigzag4Style, PATTERN4)
alertcondition(wm_pattern1 or wm_pattern2 or wm_pattern3 or wm_pattern4, title='Harmonic Alert', message='Harmonic Alert {{ticker}}')
var stats = table.new(position=position.top_right, columns=8, rows=DETECT3 + 2, border_width=1)
if barstate.islast and showStatTable
if PATTERN1
table.cell(table_id=stats, column=0, row=0, text='Zigzag ' + str.tostring(PATTERN10), bgcolor=color.black, text_color=color.white)
table.cell(table_id=stats, column=0, row=1, text='Price', bgcolor=color.black, text_color=color.white)
table.cell(table_id=stats, column=1, row=1, text='BarIndex', bgcolor=color.black, text_color=color.white)
for i = 0 to array.size(zigzagpivots1) - 1 by 1
bgcolor = array.get(zigzagpivotdirs1, i) == 1 ? color.lime : color.orange
table.cell(table_id=stats, column=0, row=i + 2, text=str.tostring(array.get(zigzagpivots1, i)), bgcolor=bgcolor)
table.cell(table_id=stats, column=1, row=i + 2, text=str.tostring(array.get(zigzagpivotbars2, i)), bgcolor=bgcolor)
if PATTERN2
table.cell(table_id=stats, column=2, row=0, text='Zigzag ' + str.tostring(PATTERN20), bgcolor=color.black, text_color=color.white)
table.cell(table_id=stats, column=2, row=1, text='Price', bgcolor=color.black, text_color=color.white)
table.cell(table_id=stats, column=3, row=1, text='BarIndex', bgcolor=color.black, text_color=color.white)
for i = 0 to array.size(zigzagpivots2) - 1 by 1
bgcolor = array.get(zigzagpivotdirs2, i) == 1 ? color.lime : color.orange
table.cell(table_id=stats, column=2, row=i + 2, text=str.tostring(array.get(zigzagpivots2, i)), bgcolor=bgcolor)
table.cell(table_id=stats, column=3, row=i + 2, text=str.tostring(array.get(zigzagpivotbars2, i)), bgcolor=bgcolor)
if PATTERN3
table.cell(table_id=stats, column=4, row=0, text='Zigzag ' + str.tostring(PATTERN30), bgcolor=color.black, text_color=color.white)
table.cell(table_id=stats, column=4, row=1, text='Price', bgcolor=color.black, text_color=color.white)
table.cell(table_id=stats, column=5, row=1, text='BarIndex', bgcolor=color.black, text_color=color.white)
for i = 0 to array.size(zigzagpivots3) - 1 by 1
bgcolor = array.get(zigzagpivotdirs3, i) == 1 ? color.lime : color.orange
table.cell(table_id=stats, column=4, row=i + 2, text=str.tostring(array.get(zigzagpivots3, i)), bgcolor=bgcolor)
table.cell(table_id=stats, column=5, row=i + 2, text=str.tostring(array.get(zigzagpivotbars3, i)), bgcolor=bgcolor)
if PATTERN4
table.cell(table_id=stats, column=6, row=0, text='Zigzag ' + str.tostring(PATTERN40), bgcolor=color.black, text_color=color.white)
table.cell(table_id=stats, column=6, row=1, text='Price', bgcolor=color.black, text_color=color.white)
table.cell(table_id=stats, column=7, row=1, text='BarIndex', bgcolor=color.black, text_color=color.white)
for i = 0 to array.size(zigzagpivots4) - 1 by 1
bgcolor = array.get(zigzagpivotdirs4, i) == 1 ? color.lime : color.orange
table.cell(table_id=stats, column=6, row=i + 2, text=str.tostring(array.get(zigzagpivots4, i)), bgcolor=bgcolor)
table.cell(table_id=stats, column=7, row=i + 2, text=str.tostring(array.get(zigzagpivotbars4, i)), bgcolor=bgcolor)
/////////
// functions
get(arr, index) =>
index < array.size(arr) ? array.get(arr, index) : na
busted(highs, lows, times, bounces) =>
array.shift(highs)
array.shift(lows)
array.shift(times)
array.shift(bounces) or true
bounced(bounces) =>
status = array.get(bounces, 0)
array.set(bounces, 0, true)
status
// A. CORE
ceiling = math.max(high, close , open )
floor = math.min(low, close , open )
buying = close >= open and high != low
selling = close <= open and low != high
green = close > open and close > close
red = close < open and close < close
gapup = open > close
gapdown = open < close
higher = high > high
lowerf = low < low
bullish = green and higher
bearish = red and lowerf
// notable price actions
bullishEngulf = selling and (gapdown or lowerf) and bullish and close > open
bearishEngulf = buying and (gapup or higher) and bearish and close < open
breakHigh = (selling or selling ) and buying and close > ceiling
breakLow = (buying or buying ) and selling and close < floor
whiteSoldiers = bearish and buying and bullish and bullish and close > high
blackCrows = bullish and selling and bearish and bearish and close < low
// pivot setups
soaring = bullishEngulf or breakHigh or whiteSoldiers
tumbling = bearishEngulf or breakLow or blackCrows
reversal = switch
whiteSoldiers => not soaring and not soaring
blackCrows => not tumbling and not tumbling
breakHigh => not soaring and (bearish or bearish )
breakLow => not tumbling and (bullish or bullish )
continuation = switch
breakHigh => bullish and close > high and not bearish
breakLow => bearish and close < low and not bullish
engulfing = (bullishEngulf or bearishEngulf) and (higher or lowerf )
// B. PIVOT ZONES
var buyzoneHigh = array.new_float(0)
var buyzoneLow = array.new_float(0)
var buyzoneTime = array.new_int(0)
var bounceUp = array.new_bool(0)
var sellzoneHigh = array.new_float(0)
var sellzoneLow = array.new_float(0)
var sellzoneTime = array.new_int(0)
var bounceDown = array.new_bool(0)
// 1. Broken Pivot Zones
brokenHigh = while get(sellzoneHigh, 0) < high
busted(sellzoneHigh, sellzoneLow, sellzoneTime, bounceDown)
brokenLow = while get(buyzoneLow, 0) > low
busted(buyzoneHigh, buyzoneLow, buyzoneTime, bounceUp)
// 2. Distribution/Accumulation Bar and Pivot Bar
upturn = soaring and (reversal or continuation or engulfing)
downturn = tumbling and (reversal or continuation or engulfing)
dacbar = switch
upturn => whiteSoldiers ? 3 : (breakHigh and selling ? 2 : 1)
downturn => blackCrows ? 3 : (breakLow and buying ? 2 : 1)
pivotbar = switch
upturn => whiteSoldiers ? 2 : (green ? 1 : 0)
downturn => blackCrows ? 2 : (red ? 1 : 0)
// 3. Pivot Zone Values
pzHigh = float(na)
pzLow = float(na)
switch
upturn =>
// low at wick
pzLow := math.min(low , low , low , low)
// high at wick or open
pzHigh := switch
close > high => high
open > open => open
=> open
downturn =>
// high at wick
pzHigh := math.max(high , high , high , high)
// low at wick or open
pzLow := switch
close < low => low
open < open => open
=> open
// 4. Overlapping Pivot Zones
overlap = switch
upturn => get(buyzoneHigh, 0) >= pzLow
downturn => get(sellzoneLow, 0) <= pzHigh
replace = switch
overlap and upturn => bounced(bounceUp)
overlap and downturn => bounced(bounceDown)
// remove replaced zone or adjust overlapped zone
switch
replace and upturn => busted(buyzoneHigh, buyzoneLow, buyzoneTime, bounceUp)
replace and downturn => busted(sellzoneHigh, sellzoneLow, sellzoneTime, bounceDown)
overlap and upturn => array.set(buyzoneHigh, 0, pzLow)
overlap and downturn => array.set(sellzoneLow, 0, pzHigh)
// 5. Pivot Zones Queue
switch
upturn =>
array.unshift(buyzoneHigh, pzHigh)
array.unshift(buyzoneLow, pzLow)
array.unshift(buyzoneTime, time )
array.unshift(bounceUp, false)
downturn =>
array.unshift(sellzoneHigh, pzHigh)
array.unshift(sellzoneLow, pzLow)
array.unshift(sellzoneTime, time )
array.unshift(bounceDown, false)
// 6. Pivot Zones Markup
maxbox(redraw) => redraw ? 22 : na
newbox(bg) =>
box.new(0, 0, 0, 0, xloc=xloc.bar_time, border_color=color.rgb(127,127,127,50), bgcolor=bg, extend=extend.right,force_overlay = true)
render(boxes, index, highs, lows, times) =>
ibox = get(boxes, index)
top = get(highs, index)
bottom = get(lows, index)
left = get(times, index)
overlapped = if index > 0
lastbox = index - 1
top == get(lows, lastbox) or bottom == get(highs, lastbox)
box.set_lefttop(ibox, left, overlapped ? na : top)
box.set_rightbottom(ibox, time, overlapped ? na : bottom)
textM=""
if int(top-bottom)==0
textM:= str.tostring(top-bottom)
else
textM := str.tostring(int(top-bottom))
box.set_text(ibox,"Strength of Order Block = "+ textM)
box.set_text_color(ibox,color.gray)
box.set_text_halign(ibox,text.align_left)
box.set_text_size(ibox,size.small)
var supply = input.color(color.rgb(253,224,110,50), 'Supply Zones')
var demand = input.color(color.rgb(212,224,255,50), 'Demand Zones')
var buyBox = array.new_box(0)
var sellBox = array.new_box(0)
for i = 0 to maxbox(na(close ))
array.push(buyBox, newbox(demand))
array.push(sellBox, newbox(supply))
for i = 0 to maxbox(upturn or brokenLow)
render(buyBox, i, buyzoneHigh, buyzoneLow, buyzoneTime)
for i = 0 to maxbox(downturn or brokenHigh)
render(sellBox, i, sellzoneHigh, sellzoneLow, sellzoneTime)
// C. ALERTS
if brokenHigh
alert('Breakout', alert.freq_once_per_bar)
if brokenLow
alert('Breakdown', alert.freq_once_per_bar)
if upturn or downturn
setup = switch
whiteSoldiers => 'White Soldiers'
blackCrows => 'Black Crows'
breakHigh => bullishEngulf ? 'Engulf & Break High' : 'Break High'
breakLow => bearishEngulf ? 'Engulf & Break Low' : 'Break Low'
bullishEngulf => 'Bullish Engulf'
bearishEngulf => 'Bearish Engulf'
occurence = replace ? 'Replace' : (overlap ? 'Bounce' : 'Fresh')
message = setup + ' (' + occurence + ')'
alert(message, alert.freq_once_per_bar_close)
// The code ended here TOTOOLI X11
Auto AI Trendlines [TradingFinder] Clustering & Filtering Trends🔵 Introduction
Auto AI trendlines Clustering & Filtering Trends Indicator, draws a variety of trendlines. This auto plotting trendline indicator plots precise trendlines and regression lines, capturing trend dynamics.
Trendline trading is the strongest strategy in the financial market.
Regression lines, unlike trendlines, use statistical fitting to smooth price data, revealing trend slopes. Trendlines connect confirmed pivots, ensuring structural accuracy. Regression lines adapt dynamically.
The indicator’s ascending trendlines mark bullish pivots, while descending ones signal bearish trends. Regression lines extend in steps, reflecting momentum shifts. As the trend is your friend, this tool aligns traders with market flow.
Pivot-based trendlines remain fixed once confirmed, offering reliable support and resistance zones. Regression lines, adjusting to price changes, highlight short-term trend paths. Both are vital for traders across asset classes.
🔵 How to Use
There are four line types that are seen in the image below; Precise uptrend (green) and downtrend (red) lines connect exact price extremes, while Pivot-based uptrend and downtrend lines use significant swing points, both remaining static once formed.
🟣 Precise Trendlines
Trendlines only form after pivot points are confirmed, ensuring reliability. This reduces false signals in choppy markets. Regression lines complement with real-time updates.
The indicator always draws two precise trendlines on confirmed pivot points, one ascending and one descending. These are colored distinctly to mark bullish and bearish trends. They remain fixed, serving as structural anchors.
🟣 Dynamic Regression Lines
Regression lines, adjusting dynamically with price, reflect the latest trend slope for real-time analysis. Use these to identify trend direction and potential reversals.
Regression lines, updated dynamically, reflect real-time price trends and extend in steps. Ascending lines are green, descending ones orange, with shades differing from trendlines. This aids visual distinction.
🟣 Bearish Chart
A Bullish State emerges when uptrend lines outweigh or match downtrend lines, with recent upward momentum signaling a potential rise. Check the trend count in the state table to confirm, using it to plan long positions.
🟣 Bullish Chart
A Bearish State is indicated when downtrend lines dominate or equal uptrend lines, with recent downward moves suggesting a potential drop. Review the state table’s trend count to verify, guiding short position entries. The indicator reflects this shift for strategic planning.
🟣 Alarm
Set alerts for state changes to stay informed of Bullish or Bearish shifts without constant monitoring. For example, a transition to Bullish State may signal a buying opportunity. Toggle alerts On or Off in the settings.
🟣 Market Status
A table summarizes the chart’s status, showing counts of ascending and descending lines. This real-time overview simplifies trend monitoring. Check it to assess market bias instantly.
Monitor the table to track line counts and trend dominance.
A higher count of ascending lines suggests bullish bias. This helps traders align with the prevailing trend.
🔵 Settings
Number of Trendlines : Sets total lines (max 10, min 3), balancing chart clarity and trend coverage.
Max Look Back : Defines historical bars (min 50) for pivot detection, ensuring robust trendlines.
Pivot Range : Sets pivot sensitivity (min 2), adjusting trendline precision to market volatility.
Show Table Checkbox : Toggles display of a table showing ascending/descending line counts.
Alarm : Enable or Disable the alert.
🔵 Conclusion
The multi slopes indicator, blending pivot-based trendlines and dynamic regression lines, maps market trends with precision. Its dual approach captures both structural and short-term momentum.
Customizable settings, like trendline count and pivot range, adapt to diverse trading styles. The real-time table simplifies trend monitoring, enhancing efficiency. It suits forex, stocks, and crypto markets.
While trendlines anchor long-term trends, regression lines track intraday shifts, offering versatility. Contextual analysis, like price action, boosts signal reliability. This indicator empowers data-driven trading decisions.
Range Filter - B&S Signals+OB+SND// This source code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org
// Credits to the original Script - Range Filter DonovanWall
// This version is the old version of the Range Filter with less settings to tinker with
//@version=5
indicator(title='Range Filter - B&S; Signals+OB+SND', shorttitle='RF - B&S; Signals+OB+SND', overlay=true, max_labels_count = 500, max_boxes_count = 500, max_lines_count = 500)
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Functions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Range Size Function
rng_size(x, qty, n) =>
// AC = Cond_EMA(abs(x - x ), 1, n)
wper = n * 2 - 1
avrng = ta.ema(math.abs(x - x ), n)
AC = ta.ema(avrng, wper) * qty
rng_size = AC
rng_size
//Range Filter Function
rng_filt(x, rng_, n) =>
r = rng_
var rfilt = array.new_float(2, x)
array.set(rfilt, 1, array.get(rfilt, 0))
if x - r > array.get(rfilt, 1)
array.set(rfilt, 0, x - r)
if x + r < array.get(rfilt, 1)
array.set(rfilt, 0, x + r)
rng_filt1 = array.get(rfilt, 0)
hi_band = rng_filt1 + r
lo_band = rng_filt1 - r
rng_filt = rng_filt1
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Inputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Range Source
rng_src = input(defval=close, title='Swing Source')
//Range Period
rng_per = input.int(defval=200, minval=1, title='Swing Period')
//Range Size Inputs
rng_qty = input.float(defval=7.5, minval=0.0000001, title='Swing Multiplier')
//Bar Colors
use_barcolor = input(defval=true, title='Bar Colors On/Off')
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Definitions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Range Filter Values
= rng_filt(rng_src, rng_size(rng_src, rng_qty, rng_per), rng_per)
//Direction Conditions
var fdir = 0.0
fdir := filt > filt ? 1 : filt < filt ? -1 : fdir
upward = fdir == 1 ? 1 : 0
downward = fdir == -1 ? 1 : 0
//Trading Condition
longCond = rng_src > filt and rng_src > rng_src and upward > 0 or rng_src > filt and rng_src < rng_src and upward > 0
shortCond = rng_src < filt and rng_src < rng_src and downward > 0 or rng_src < filt and rng_src > rng_src and downward > 0
CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni
longCondition = longCond and CondIni == -1
shortCondition = shortCond and CondIni == 1
//Colors
filt_color = upward ? #2adf06e5 : downward ? #ec0606e0 : #cccccc
bar_color = upward and rng_src > filt ? rng_src > rng_src ? #76ff05 : #76ff05 : downward and rng_src < filt ? rng_src < rng_src ? #ff0505 : #ff0505 : #109404
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Outputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Filter Plot
filt_plot = plot(filt, color=filt_color, linewidth=3, title='Filter', transp=67)
//Band Plots
h_band_plot = plot(h_band, color=color.new(#05ff9b, 100), title='High Band')
l_band_plot = plot(l_band, color=color.new(#ff0583, 100), title='Low Band')
//Band Fills
fill(h_band_plot, filt_plot, color=#00b36b00, title='High Band Fill')
fill(l_band_plot, filt_plot, color=#b8005c00, title='Low Band Fill')
//Bar Color
barcolor(use_barcolor ? bar_color : na)
//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
// ---------------------------------------------- Order Blocks ------------------------------------------------
// Order Blocks
const color colup = #089981
const color coldn = #f23645
const string tm = " Use Length to adjust cordinate of the orderblocks Use whole candle body"
const string tn = "Mitigation method for when to trigger order blocks"
const string tj = "Order block Metrics text size"
const string ta = 'Display internal buy & sell activity'
const string tsorder = 'Show Last number of orderblocks'
const string gv = "Volumetric Order Blocks"
obshow = input.bool (false , "Show Last" , tsorder, '1', gv)
oblast = input.int (3 , "" , 0, 50, 1 , inline = '1', group = gv)
obupcs = input.color (color.new(colup, 90), "" , inline = '1', group = gv)
obdncs = input.color (color.new(coldn, 90), "" , inline = '1', group = gv)
obshowactivity = input.bool (true , "Show Buy/Sell Activity ", ta, '2', gv)
obactup = input.color (color.new(colup, 50), "" , inline = '2', group = gv)
obactdn = input.color (color.new(coldn, 50), "" , inline = '2', group = gv)
obmode = input.string("Length" , "Construction " , , tm, '3', gv)
len = input.int (5 , "" , 1, 20, 1 , inline = '3', group = gv)
obmiti = input.string("Close" , "Mitigation Method" , , tn, group = gv)
obtxt = input.string("Normal" , "Metric Size" , , tj, group = gv)
showmetric = input.bool (false , "Show Metrics" , group = gv)
showline = input.bool (false , "Show Mid-Line" , group = gv)
overlap = input.bool (true , "Hide Overlap" , group = gv, tooltip = "Most recent order block will be preserved")
bull = input.bool(true , "Buy signal" , inline = "Inside" , group = "ANY ALERT")
bear = input.bool(true , "Sell Signal" , inline = "Formed" , group = "ANY ALERT")
blcreated = input.bool(false , "Bullish OB Formed " , inline = "Formed" , group = "ANY ALERT")
brcreated = input.bool(false , "Bearish OB Formed" , inline = "Formed" , group = "ANY ALERT")
blmitigated = input.bool(false , "Bullish OB Mitigated " , inline = "Mitigated" , group = "ANY ALERT")
brmitigated = input.bool(false , "Bearish OB Mitigated" , inline = "Mitigated" , group = "ANY ALERT")
blinside = input.bool(true , "Price Inside Bullish OB" , inline = "Inside" , group = "ANY ALERT")
brinside = input.bool(true , "Price Inside Bearish OB" , inline = "Inside" , group = "ANY ALERT")
type bar
float o = open
float h = high
float l = low
float c = close
float v = volume
int i = bar_index
int t = time
type ob
float top
float btm
float avg
int loc
color css
float vol
int dir
int move
int blPOS
int brPOS
int xlocbl
int xlocbr
type alert
bool created = false
bool inside = false
bool mitigated = false
type cross
bool reset = false
bar b = bar .new()
alert blal = alert.new()
alert bral = alert.new()
var cross blIS = cross.new()
var cross brIS = cross.new()
method txSz(string s) =>
out = switch s
"Tiny" => size.tiny
"Small" => size.small
"Normal" => size.normal
"Large" => size.large
"Huge" => size.huge
out
method display(ob id, ob full, int i) =>
box.new (top = id.top, bottom = id.btm, left = id.loc, right = b.t , border_color = na, bgcolor = id.css, xloc = xloc.bar_time)
box.new (top = id.top, bottom = id.btm, left = b.t , right = b.t + 1 , border_color = na, bgcolor = id.css, xloc = xloc.bar_time, extend = extend.right)
if obshowactivity
box.new(top = id.top, bottom = id.avg, left = id.loc, right = id.xlocbl, border_color = na, bgcolor = obactup, xloc = xloc.bar_time)
box.new(top = id.avg, bottom = id.btm, left = id.loc, right = id.xlocbr, border_color = na, bgcolor = obactdn, xloc = xloc.bar_time)
if showline
line.new(
x1 = id.loc
, x2 = b.t
, y1 = id.avg
, y2 = id.avg
, color = color.new(id.css, 0)
, xloc = xloc.bar_time
, style = line.style_dashed
)
if showmetric
if i == math.min(oblast - 1, full.size() - 1)
float tV = 0
float dV = array.new()
seq = math.min(oblast - 1, full.size() - 1)
for j = 0 to seq
cV = full.get(j)
tV += cV.vol
if j == seq
for y = 0 to seq
dV.push(
math.floor(
(full.get(y).vol / tV) * 100)
)
id = full.get(y)
label.new(
b.i + 1
, id.avg
, textcolor = color.new(id.css, 0)
, style = label.style_label_left
, size = obtxt.txSz()
, color = #ffffff00
, text =
str.tostring(
math.round(full.get(y).vol, 3), format = format.volume) + " (" + str.tostring(dV.get(y)) + "%)"
)
method overlap(ob id) =>
if id.size() > 1
for i = id.size() - 1 to 1
stuff = id.get(i)
current = id.get(0)
switch
stuff.btm > current.btm and stuff.btm < current.top => id.remove(i)
stuff.top < current.top and stuff.btm > current.btm => id.remove(i)
stuff.top > current.top and stuff.btm < current.btm => id.remove(i)
stuff.top < current.top and stuff.top > current.btm => id.remove(i)
method umt(ob metric) =>
switch metric.dir
1 =>
switch metric.move
1 => metric.blPOS := metric.blPOS + 1, metric.move := 2
2 => metric.blPOS := metric.blPOS + 1, metric.move := 3
3 => metric.brPOS := metric.brPOS + 1, metric.move := 1
-1 =>
switch metric.move
1 => metric.brPOS := metric.brPOS + 1, metric.move := 2
2 => metric.brPOS := metric.brPOS + 1, metric.move := 3
3 => metric.blPOS := metric.blPOS + 1, metric.move := 1
if (b.t - b.t ) == (b.t - b.t )
metric.xlocbl := metric.loc + (b.t - b.t ) * metric.blPOS
metric.xlocbr := metric.loc + (b.t - b.t ) * metric.brPOS
fnOB() =>
var ob blob = array.new()
var ob brob = array.new()
var int dir = 0
up = ta.highest ( len )
dn = ta.lowest ( len )
pv = ta.pivothigh(b.v, len, len)
dir := b.h > up ? -1 : b.l < dn ? 1 : dir
atr = ta.atr(len)
btmP = obmode == "Length" ? (b.h - 1 * atr ) < b.l ? b.l : (b.h - 1 * atr ) : b.l
topP = obmode == "Length" ? (b.l + 1 * atr ) > b.h ? b.h : (b.l + 1 * atr ) : b.h
if pv and dir == 1
blob.unshift(
ob.new(topP, b.l , math.avg(topP, b.l ), b.t , obupcs, b.v , b.c > b.o ? 1 : -1, 1, 0, 0, b.t ))
blal.created := true
blIS.reset := false
if pv and dir == -1
brob.unshift(
ob.new(
b.h
, btmP
, math.avg(btmP, b.h )
, b.t
, obdncs
, b.v
, b.c > b.o ? 1 : -1
, 1
, 0
, 0
, b.t
)
)
bral.created := true
brIS.reset := false
if blob.size() > 0 and barstate.isconfirmed
for in blob
for j = 0 to len - 1
if obmiti == "Close" ? math.min(b.c , b.o ) < ob.btm : obmiti == "Wick" ? b.l < ob.btm : obmiti == "Avg" ? b.l < ob.avg : na
blob.remove(i)
blal.mitigated := true
break
if brob.size() > 0 and barstate.isconfirmed
for in brob
for j = 0 to len - 1
if obmiti == "Close" ? math.max(b.c , b.o ) > ob.top : obmiti == "Wick" ? b.h > ob.top : obmiti == "Avg" ? b.h > ob.avg : na
brob.remove(i)
bral.mitigated := true
break
if blob.size() > 0
for in blob
metric.umt()
if brob.size() > 0
for in brob
metric.umt()
if overlap
blob.overlap()
brob.overlap()
if barstate.isconfirmed
if blob.size() > 0
ob = blob.get(0)
if low < ob.top and blIS.reset == false
blal.inside := true
blIS.reset := true
if brob.size() > 0
ob = brob.get(0)
if high > ob.btm and brIS.reset == false
bral.inside := true
brIS.reset := true
if barstate.islast
for bx in box.all
bx.delete()
for ln in line.all
ln.delete()
// for lb in label.all //Razzere Fixed!
// lb.delete() //Razzere Fixed!
if blob.size() > 0
for i = 0 to math.min(oblast - 1, blob.size() - 1)
blob.get(i).display(blob, i)
if brob.size() > 0
for i = 0 to math.min(oblast - 1, brob.size() - 1)
brob.get(i).display(brob, i)
if obshow
fnOB()
if bull and longCondition
alert("Buy Signal")
if bear and shortCondition
alert("Sell Signal")
if blinside and blal.inside
alert("Price Inside Bullish OB")
if blcreated and blal.created
alert("Bullish OB Formed")
if blmitigated and blal.mitigated
alert("Bullish OB Mitigated")
if brinside and bral.inside
alert("Price Inside Bearish OB")
if brcreated and bral.created
alert("Bearish OB Formed")
if brmitigated and bral.mitigated
alert("Bearish OB Mitigated")
// Risk Management
levels = input.bool(true, "Show TP/SL Levels" , group = "Risk Management" , inline = "MMDB2")
lvlLines = input.bool(false, "Show Lines ", inline="levels", group = "Risk Management")
linesStyle = input.string("SOLID", "", , inline="levels", group = "Risk Management")
lvlDistance = input.int(105, "Distance", 1, inline="levels2", group = "Risk Management")
lvlDecimals = input.int(2, " Decimals", 1, 8, inline="levels2", group = "Risk Management")
atrRisk = input.int(5, "Risk % ", 1, group = "Risk Management" , inline="levels3")
atrLen = input.int(14, " ATR Length", 1, group = "Risk Management" , inline="levels3")
decimals = lvlDecimals == 1 ? "#.#" : lvlDecimals == 2 ? "#.##" : lvlDecimals == 3 ? "#.###" : lvlDecimals == 4 ? "#.####" : lvlDecimals == 5 ? "#.#####" : lvlDecimals == 6 ? "#.######" : lvlDecimals == 7 ? "#.#######" : "#.########"
trigger2 = longCondition ? 1 : 0
countBull = ta.barssince(longCondition)
countBear = ta.barssince(shortCondition)
trigger = nz(countBull, bar_index) < nz(countBear, bar_index) ? 1 : 0
atrBand = ta.atr(atrLen) * atrRisk
atrStop = trigger == 1 ? low - atrBand : high + atrBand
lastTrade(close) => ta.valuewhen(longCondition or shortCondition, close, 0)
entry = levels ? label.new(time, close, "ENTRY " + str.tostring(lastTrade(close), decimals), xloc.bar_time, yloc.price, #e0ad06, label.style_label_left, color.white, size.normal) : na
label.set_x(entry, label.get_x(entry) + math.round(ta.change(time) * lvlDistance))
label.set_y(entry, lastTrade(close))
label.delete(entry )
stop_y = lastTrade(atrStop)
stop = levels ? label.new(time, close, "SL " + str.tostring(stop_y, decimals), xloc.bar_time, yloc.price, #ff00008c, label.style_label_left, color.white, size.normal) : na
label.set_x(stop, label.get_x(stop) + math.round(ta.change(time) * lvlDistance))
label.set_y(stop, stop_y)
label.delete(stop )
tp1Rl_y = (lastTrade(close)-lastTrade(atrStop))*1 + lastTrade(close)
tp1Rl = levels ? label.new(time, close, "1:1 TP " + str.tostring(tp1Rl_y, decimals), xloc.bar_time, yloc.price, #00cf4b8c, label.style_label_left, color.white, size.normal ) : na
label.set_x(tp1Rl, label.get_x(tp1Rl) + math.round(ta.change(time) * lvlDistance))
label.set_y(tp1Rl, tp1Rl_y)
label.delete(tp1Rl )
tp2RL_y = (lastTrade(close)-lastTrade(atrStop))*2 + lastTrade(close)
tp2RL = levels ? label.new(time, close, "2:1 TP " + str.tostring(tp2RL_y, decimals), xloc.bar_time, yloc.price, #00cf4b8c, label.style_label_left, color.white, size.normal) : na
label.set_x(tp2RL, label.get_x(tp2RL) + math.round(ta.change(time) * lvlDistance))
label.set_y(tp2RL, tp2RL_y)
label.delete(tp2RL )
tp3RL_y = (lastTrade(close)-lastTrade(atrStop))*3 + lastTrade(close)
tp3RL = levels ? label.new(time, close, "3:1 TP " + str.tostring(tp3RL_y, decimals), xloc.bar_time, yloc.price, #00cf4b8c, label.style_label_left, color.white, size.normal) : na
label.set_x(tp3RL, label.get_x(tp3RL) + math.round(ta.change(time) * lvlDistance))
label.set_y(tp3RL, tp3RL_y)
label.delete(tp3RL )
style = linesStyle == "SOLID" ? line.style_solid : linesStyle == "DASHED" ? line.style_dashed : line.style_dotted
lineEntry = levels and lvlLines ? line.new(bar_index - (trigger == 0 ? countBull : countBear), lastTrade(close), bar_index + lvlDistance, lastTrade(close), xloc.bar_index, extend.none, #e0ad06, style, 2) : na, line.delete(lineEntry )
lineStop = levels and lvlLines ? line.new(bar_index - (trigger == 0 ? countBull : countBear), stop_y, bar_index + lvlDistance, stop_y, xloc.bar_index, extend.none, #ff00008c, style, 2) : na, line.delete(lineStop )
lineTp1Rl = levels and lvlLines ? line.new(bar_index - (trigger == 0 ? countBull : countBear), tp1Rl_y, bar_index + lvlDistance, tp1Rl_y, xloc.bar_index, extend.none, #00cf4b8c, style, 2) : na, line.delete(lineTp1Rl )
lineTp2RL = levels and lvlLines ? line.new(bar_index - (trigger == 0 ? countBull : countBear), tp2RL_y, bar_index + lvlDistance, tp2RL_y, xloc.bar_index, extend.none, #00cf4b8c, style, 2) : na, line.delete(lineTp2RL )
lineTp3RL = levels and lvlLines ? line.new(bar_index - (trigger == 0 ? countBull : countBear), tp3RL_y, bar_index + lvlDistance, tp3RL_y, xloc.bar_index, extend.none, #00cf4b8c, style, 2) : na, line.delete(lineTp3RL )
//Plot Buy and Sell Labels
plotshape(longCondition, title='Buy Signal', text='Buy ▲+ ', textcolor=color.white, style=shape.labelup, size=size.normal, location=location.belowbar, color=#00cf4b8c)
plotshape(shortCondition, title='Sell Signal', text='Sell ▼+', textcolor=color.white, style=shape.labeldown, size=size.normal, location=location.abovebar, color=#ff00008c)
//Alerts
alertcondition(longCondition, title='Buy Alert', message='BUY')
alertcondition(shortCondition, title='Sell Alert', message='SELL')
//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
// ---------------------------------------------- SR ------------------------------------------------
//
show_current_sr = input.bool(true, title = "Show Current TF S/R", group = "Setting")
swing_length = input.int(10, title = 'Swing Length', group = 'Setting', minval = 1, maxval = 50)
history_of_demand_to_keep = input.int(20, title = 'Lookback', minval = 5, maxval = 50, group = "Setting")
box_width = input.float(10, title = 'S/R Range', group = 'Setting', minval = 1, maxval = 10, step = 0.5)
string group3 = "TF Setting"
enableHtf1 = input.bool(false, group = group3, inline = "htf1", title = "")
htf1 = input.timeframe("W", "TF1", group = group3, inline = "htf1")
enableHtf2 = input.bool(false, group = group3, inline = "htf2", title = "")
htf2 = input.timeframe("D", "TF2", group = group3, inline = "htf2")
enableHtf3 = input.bool(false, group = group3, inline = "htf3", title = "")
htf3 = input.timeframe("240", "TF3", group = group3, inline = "htf3")
enableHtf4 = input.bool(false, group = group3, inline = "htf4", title = "")
htf4 = input.timeframe("180", "TF4", group = group3, inline = "htf4")
enableHtf5 = input.bool(false, group = group3, inline = "htf5", title = "")
htf5 = input.timeframe("120", "TF5", group = group3, inline = "htf5")
enableHtf6 = input.bool(false, group = group3, inline = "htf6", title = "")
htf6 = input.timeframe("60", "TF6", group = group3, inline = "htf6")
enableHtf7 = input.bool(false, group = group3, inline = "htf7", title = "")
htf7 = input.timeframe("45", "TF7", group = group3, inline = "htf7")
enableHtf8 = input.bool(true, group = group3, inline = "htf8", title = "")
htf8 = input.timeframe("30", "TF8", group = group3, inline = "htf8")
enableHtf9 = input.bool(false, group = group3, inline = "htf9", title = "")
htf9 = input.timeframe("15", "TF9", group = group3, inline = "htf9")
supply_color = input.color(#f236468a, title = 'Support Zone', group = 'Color Settings', inline = '3')
supply_outline_color = input.color(#f236468a, title = 'BoS', group = 'Color Settings', inline = '3')
demand_color = input.color(#2962ff8a, title = 'Resistance Zone', group = 'Color Settings', inline = '4')
demand_outline_color = input.color(#2962ff8a, title = 'BoR', group = 'Color Settings', inline = '4')
// bos_label_color = input.color(color.white, title = 'Fracture Zone', group = 'Color Settings', inline = '5')
poi_label_color = input.color(#b9b9b9, title = 'S/R Zone Label', group = 'Color Settings', inline = '7')
type zone_with_strength
box zone
int count = 0
string tf
// FUNCTION TO ADD NEW AND REMOVE LAST IN ARRAY
array_add_pop(array, new_value_to_add) =>
array.unshift(array, new_value_to_add)
array.pop(array)
// FUNCTION MAKE SURE SUPPLY ISNT OVERLAPPING
check_overlapping(new_poi, box_array, atr) =>
atr_threshold = atr * 2
okay_to_draw = true
for i = 0 to array.size(box_array) - 1
zone_with_strength zws = array.get(box_array, i)
if not na(zws)
box b = zws.zone
top = box.get_top(b)
bottom = box.get_bottom(b)
poi = (top + bottom) / 2
upper_boundary = poi + atr_threshold
lower_boundary = poi - atr_threshold
if new_poi >= lower_boundary and new_poi <= upper_boundary
okay_to_draw := false
break
else
okay_to_draw := true
okay_to_draw
// FUNCTION TO DRAW SUPPLY OR DEMAND ZONE
support_resistance(value_array, bn_array, box_array, label_array, count_array, box_type, atr, tf_label, tfbarindex, is_htf) =>
atr_buffer = atr * (box_width / 10)
box_left = is_htf ? bar_index : array.get(bn_array, 0)
box_right = bar_index
var float box_top = 0.00
var float box_bottom = 0.00
var float poi = 0.00
if box_type == 1
box_top := array.get(value_array, 0)
box_bottom := box_top - atr_buffer
poi := (box_top + box_bottom) / 2
else if box_type == -1
box_bottom := array.get(value_array, 0)
box_top := box_bottom + atr_buffer
poi := (box_top + box_bottom) / 2
okay_to_draw = check_overlapping(poi, box_array, atr)
// okay_to_draw = true
//delete oldest box, and then create a new box and add it to the array
if box_type == 1 and okay_to_draw
zone_with_strength last = array.get(box_array, array.size(box_array) - 1)
if not na(last)
box.delete(last.zone)
box b = box.new(left = box_left, top = box_top, right = bar_index, bottom = box_bottom, border_color = supply_outline_color,
bgcolor = color.new(supply_color, 80), extend = extend.none, text = tf_label, text_halign = text.align_right, text_valign = text.align_center, text_color = poi_label_color, text_size = size.small, xloc = xloc.bar_index)
zone_with_strength zws = zone_with_strength.new(b, 0, tf_label)
array_add_pop(box_array, zws)
else if box_type == -1 and okay_to_draw
zone_with_strength last = array.get(box_array, array.size(box_array) - 1)
if not na(last)
box.delete(last.zone)
box b = box.new(left = box_left, top = box_top, right = bar_index, bottom = box_bottom, border_color = demand_outline_color,
bgcolor = color.new(demand_color, 80), extend = extend.none, text = tf_label, text_halign = text.align_right, text_valign = text.align_center, text_color = poi_label_color, text_size = size.small, xloc = xloc.bar_index)
zone_with_strength zws = zone_with_strength.new(b, 0, tf_label)
array_add_pop(box_array, zws)
// FUNCTION TO CHANGE SUPPLY/DEMAND TO A BOS IF BROKEN
sd_to_bos(box_array, bos_array, count_array, label_array, zone_type, tfclose, tfbarindex) =>
for i = 0 to array.size(box_array) - 1
zone_with_strength zws = array.get(box_array, i)
if not na(zws)
box b = zws.zone
level_to_break_top = box.get_top(b)
level_to_break_bottom = box.get_bottom(b)
// if ta.crossover(close, level_to_break)
if (zone_type == 1 and close >= level_to_break_top) or (zone_type == -1 and close <= level_to_break_bottom)
copied_zone = zone_with_strength.copy(zws)
box cz = copied_zone.zone
mid = (box.get_top(b) + box.get_bottom(b)) / 2
line bosline = line.new(box.get_left(cz), mid, bar_index, mid, xloc.bar_index, extend.none, zone_type == 1 ? supply_outline_color : demand_outline_color, line.style_dotted)
array_add_pop(bos_array, bosline)
// box bos = array.get(bos_array, 0)
// box.set_top(bos, mid)
// box.set_bottom(bos, mid)
// box.set_right(bos, bar_index)
// box.set_extend(bos, extend.none)
// box.set_text(bos, '')
// box.set_text_color( bos, bos_label_color)
// box.set_text_size(bos, size.small)
// box.set_text_halign(bos, text.align_center)
// box.set_text_valign(bos, text.align_center)
box.delete(b)
array.set(box_array, i, na)
// array.remove(box_array, i)
// box.delete(array.get(label_array, i))
// FUNCTION MANAGE CURRENT BOXES BY CHANGING ENDPOINT
extend_box_endpoint(box_array, count_array, tfbarindex, tfhigh, tflow) =>
for i = 0 to array.size(box_array) - 1
zone_with_strength zws = array.get(box_array, i)
if not na(zws)
box b = zws.zone
top = box.get_top(b)
bottom = box.get_bottom(b)
count = zws.count
if (high >= bottom and high <= top) or (low >= bottom and low <= top)
count := count + 1
zws.count := count
// count := count + 1
// zws.count := count
box.set_right(b, bar_index + 40)
box.set_text(b, str.format("{0} / {1}", count, zws.tf))
zws.zone := b
array.set(box_array, i, zws)
//
//END FUNCTIONS
//
//
// CALCULATIONS FOR SUPPORT AND RESISTANCE
//
calculateSR(swing_high_values, swing_low_values, swing_high_bns, swing_low_bns, supply_zone, demand_zone, current_supply_touch_count, current_demand_touch_count, current_supply_poi, current_demand_poi, supply_bos, demand_bos, series1, series2, tf_label, tfbarindex, tfclose, atr, is_htf, swing_high, swing_low, swing_index) =>
// NEW SWING HIGH
if not na(swing_high)
//MANAGE SWING HIGH VALUES
array_add_pop(swing_high_values, swing_high)
array_add_pop(swing_high_bns, swing_index)
support_resistance(swing_high_values, swing_high_bns, supply_zone, current_supply_poi, current_supply_touch_count, 1, atr, tf_label, tfbarindex, is_htf)
// NEW SWING LOW
else if not na(swing_low)
//MANAGE SWING LOW VALUES
array_add_pop(swing_low_values, swing_low)
array_add_pop(swing_low_bns, swing_index)
support_resistance(swing_low_values, swing_low_bns, demand_zone, current_demand_poi, current_demand_touch_count, -1, atr, tf_label, tfbarindex, is_htf)
sd_to_bos(supply_zone, supply_bos, current_supply_touch_count, current_supply_poi, 1, tfclose, tfbarindex)
sd_to_bos(demand_zone, demand_bos, current_demand_touch_count, current_demand_poi, -1, tfclose, tfbarindex)
extend_box_endpoint(supply_zone, current_supply_touch_count, tfbarindex, series1, series2)
extend_box_endpoint(demand_zone, current_demand_touch_count, tfbarindex, series1, series2)
var swing_high_values = array.new_float(5,0.00)
var swing_low_values = array.new_float(5,0.00)
var swing_high_bns = array.new_int(5,0)
var swing_low_bns = array.new_int(5,0)
// ARRAYS FOR SUPPORT / RESISTANCE POI LABELS
var current_supply_poi = array.new_box(history_of_demand_to_keep, na)
var current_demand_poi = array.new_box(history_of_demand_to_keep, na)
var supply_zones = array.new(history_of_demand_to_keep, na)
var demand_zones = array.new(history_of_demand_to_keep, na)
var touches_for_supply = array.new_int(history_of_demand_to_keep, 0)
var touches_for_demand = array.new_int(history_of_demand_to_keep, 0)
// ARRAYS FOR BOS
var supply_bos = array.new_line(5, na)
var demand_bos = array.new_line(5, na)
var swing_high_values1 = array.new_float(5,0.00)
var swing_low_values1 = array.new_float(5,0.00)
var swing_high_bns1 = array.new_int(5,0)
var swing_low_bns1 = array.new_int(5,0)
// ARRAYS FOR SUPPORT / RESISTANCE
var supply_zones1 = array.new(history_of_demand_to_keep, na)
var demand_zones1 = array.new(history_of_demand_to_keep, na)
var touches_for_supply1 = array.new_int(history_of_demand_to_keep, 0)
var touches_for_demand1 = array.new_int(history_of_demand_to_keep, 0)
// ARRAYS FOR SUPPORT / RESISTANCE POI LABELS
var current_supply_poi1 = array.new_box(history_of_demand_to_keep, na)
var current_demand_poi1 = array.new_box(history_of_demand_to_keep, na)
// ARRAYS FOR BOS
var supply_bos1 = array.new_line(5, na)
var demand_bos1 = array.new_line(5, na)
var swing_high_values2 = array.new_float(5,0.00)
var swing_low_values2 = array.new_float(5,0.00)
var swing_high_bns2 = array.new_int(5,0)
var swing_low_bns2 = array.new_int(5,0)
// ARRAYS FOR SUPPORT / RESISTANCE
var supply_zones2 = array.new(history_of_demand_to_keep, na)
var demand_zones2 = array.new(history_of_demand_to_keep, na)
var touches_for_supply2 = array.new_int(history_of_demand_to_keep, 0)
var touches_for_demand2 = array.new_int(history_of_demand_to_keep, 0)
// ARRAYS FOR SUPPORT / RESISTANCE POI LABELS
var current_supply_poi2 = array.new_box(history_of_demand_to_keep, na)
var current_demand_poi2 = array.new_box(history_of_demand_to_keep, na)
// ARRAYS FOR BOS
var supply_bos2 = array.new_line(5, na)
var demand_bos2 = array.new_line(5, na)
var swing_high_values3 = array.new_float(5,0.00)
var swing_low_values3 = array.new_float(5,0.00)
var swing_high_bns3 = array.new_int(5,0)
var swing_low_bns3 = array.new_int(5,0)
// ARRAYS FOR SUPPORT / RESISTANCE
var supply_zones3 = array.new(history_of_demand_to_keep, na)
var demand_zones3 = array.new(history_of_demand_to_keep, na)
var touches_for_supply3 = array.new_int(history_of_demand_to_keep, 0)
var touches_for_demand3 = array.new_int(history_of_demand_to_keep, 0)
// ARRAYS FOR SUPPORT / RESISTANCE POI LABELS
var current_supply_poi3 = array.new_box(history_of_demand_to_keep, na)
var current_demand_poi3 = array.new_box(history_of_demand_to_keep, na)
// ARRAYS FOR BOS
var supply_bos3 = array.new_line(5, na)
var demand_bos3 = array.new_line(5, na)
var swing_high_values4 = array.new_float(5,0.00)
var swing_low_values4 = array.new_float(5,0.00)
var swing_high_bns4 = array.new_int(5,0)
var swing_low_bns4 = array.new_int(5,0)
// ARRAYS FOR SUPPORT / RESISTANCE
var supply_zones4 = array.new(history_of_demand_to_keep, na)
var demand_zones4 = array.new(history_of_demand_to_keep, na)
var touches_for_supply4 = array.new_int(history_of_demand_to_keep, 0)
var touches_for_demand4 = array.new_int(history_of_demand_to_keep, 0)
// ARRAYS FOR SUPPORT / RESISTANCE POI LABELS
var current_supply_poi4 = array.new_box(history_of_demand_to_keep, na)
var current_demand_poi4 = array.new_box(history_of_demand_to_keep, na)
// ARRAYS FOR BOS
var supply_bos4 = array.new_line(5, na)
var demand_bos4 = array.new_line(5, na)
var swing_high_values5 = array.new_float(5,0.00)
var swing_low_values5 = array.new_float(5,0.00)
var swing_high_bns5 = array.new_int(5,0)
var swing_low_bns5 = array.new_int(5,0)
// ARRAYS FOR SUPPORT / RESISTANCE
var supply_zones5 = array.new(history_of_demand_to_keep, na)
var demand_zones5 = array.new(history_of_demand_to_keep, na)
var touches_for_supply5 = array.new_int(history_of_demand_to_keep, 0)
var touches_for_demand5 = array.new_int(history_of_demand_to_keep, 0)
// ARRAYS FOR SUPPORT / RESISTANCE POI LABELS
var current_supply_poi5 = array.new_box(history_of_demand_to_keep, na)
var current_demand_poi5 = array.new_box(history_of_demand_to_keep, na)
// ARRAYS FOR BOS
var supply_bos5 = array.new_line(5, na)
var demand_bos5 = array.new_line(5, na)
var swing_high_values6 = array.new_float(5,0.00)
var swing_low_values6 = array.new_float(5,0.00)
var swing_high_bns6 = array.new_int(5,0)
var swing_low_bns6 = array.new_int(5,0)
// ARRAYS FOR SUPPORT / RESISTANCE
var supply_zones6 = array.new(history_of_demand_to_keep, na)
var demand_zones6 = array.new(history_of_demand_to_keep, na)
var touches_for_supply6 = array.new_int(history_of_demand_to_keep, 0)
var touches_for_demand6 = array.new_int(history_of_demand_to_keep, 0)
// ARRAYS FOR SUPPORT / RESISTANCE POI LABELS
var current_supply_poi6 = array.new_box(history_of_demand_to_keep, na)
var current_demand_poi6 = array.new_box(history_of_demand_to_keep, na)
// ARRAYS FOR BOS
var supply_bos6 = array.new_line(5, na)
var demand_bos6 = array.new_line(5, na)
var swing_high_values7 = array.new_float(5,0.00)
var swing_low_values7 = array.new_float(5,0.00)
var swing_high_bns7 = array.new_int(5,0)
var swing_low_bns7 = array.new_int(5,0)
// ARRAYS FOR SUPPORT / RESISTANCE
var supply_zones7 = array.new(history_of_demand_to_keep, na)
var demand_zones7 = array.new(history_of_demand_to_keep, na)
var touches_for_supply7 = array.new_int(history_of_demand_to_keep, 0)
var touches_for_demand7 = array.new_int(history_of_demand_to_keep, 0)
// ARRAYS FOR SUPPORT / RESISTANCE POI LABELS
var current_supply_poi7 = array.new_box(history_of_demand_to_keep, na)
var current_demand_poi7 = array.new_box(history_of_demand_to_keep, na)
// ARRAYS FOR BOS
var supply_bos7 = array.new_line(5, na)
var demand_bos7 = array.new_line(5, na)
var swing_high_values8 = array.new_float(5,0.00)
var swing_low_values8 = array.new_float(5,0.00)
var swing_high_bns8 = array.new_int(5,0)
var swing_low_bns8 = array.new_int(5,0)
// ARRAYS FOR SUPPORT / RESISTANCE
var supply_zones8 = array.new(history_of_demand_to_keep, na)
var demand_zones8 = array.new(history_of_demand_to_keep, na)
var touches_for_supply8 = array.new_int(history_of_demand_to_keep, 0)
var touches_for_demand8 = array.new_int(history_of_demand_to_keep, 0)
// ARRAYS FOR SUPPORT / RESISTANCE POI LABELS
var current_supply_poi8 = array.new_box(history_of_demand_to_keep, na)
var current_demand_poi8 = array.new_box(history_of_demand_to_keep, na)
// ARRAYS FOR BOS
var supply_bos8 = array.new_line(5, na)
var demand_bos8 = array.new_line(5, na)
var swing_high_values9 = array.new_float(5,0.00)
var swing_low_values9 = array.new_float(5,0.00)
var swing_high_bns9 = array.new_int(5,0)
var swing_low_bns9 = array.new_int(5,0)
// ARRAYS FOR SUPPORT / RESISTANCE
var supply_zones9 = array.new(history_of_demand_to_keep, na)
var demand_zones9 = array.new(history_of_demand_to_keep, na)
var touches_for_supply9 = array.new_int(history_of_demand_to_keep, 0)
var touches_for_demand9 = array.new_int(history_of_demand_to_keep, 0)
// ARRAYS FOR SUPPORT / RESISTANCE POI LABELS
var current_supply_poi9 = array.new_box(history_of_demand_to_keep, na)
var current_demand_poi9 = array.new_box(history_of_demand_to_keep, na)
// ARRAYS FOR BOS
var supply_bos9 = array.new_line(5, na)
var demand_bos9 = array.new_line(5, na)
atr = ta.atr(50)
if show_current_sr
cur_tf_label = timeframe.isintraday ? str.tostring(timeframe.in_seconds() / 60, "#.## MIN") : timeframe.period
swing_high = ta.pivothigh(swing_length, swing_length)
swing_low = ta.pivotlow(swing_length, swing_length)
swing_index = bar_index
calculateSR(swing_high_values, swing_low_values, swing_high_bns, swing_low_bns, supply_zones, demand_zones, touches_for_supply, touches_for_demand, current_supply_poi, current_demand_poi, supply_bos, demand_bos, high, low, cur_tf_label, bar_index, close, atr, false, swing_high, swing_low, swing_index)
// SUPPORT / RESISTANCE FOR HTF1
= request.security(syminfo.tickerid, htf1, [high, low, close, bar_index, ta.atr(50), timeframe.isintraday ? str.tostring(timeframe.in_seconds() / 60, "#.## MIN") : timeframe.period, ta.pivothigh(swing_length, swing_length), ta.pivotlow(swing_length, swing_length), bar_index ])
// SUPPORT / RESISTANCE FOR HTF2
= request.security(syminfo.tickerid, htf2, [high, low, close, bar_index, ta.atr(50), timeframe.isintraday ? str.tostring(timeframe.in_seconds() / 60, "#.## MIN") : timeframe.period, ta.pivothigh(swing_length, swing_length), ta.pivotlow(swing_length, swing_length), bar_index ])
// SUPPORT / RESISTANCE FOR HTF3
= request.security(syminfo.tickerid, htf3, [high, low, close, bar_index, ta.atr(50), timeframe.isintraday ? str.tostring(timeframe.in_seconds() / 60, "#.## MIN") : timeframe.period, ta.pivothigh(swing_length, swing_length), ta.pivotlow(swing_length, swing_length), bar_index ])
// SUPPORT / RESISTANCE FOR HTF4
= request.security(syminfo.tickerid, htf4, [high, low, close, bar_index, ta.atr(50), timeframe.isintraday ? str.tostring(timeframe.in_seconds() / 60, "#.## MIN") : timeframe.period, ta.pivothigh(swing_length, swing_length), ta.pivotlow(swing_length, swing_length), bar_index ])
// SUPPORT / RESISTANCE FOR HTF5
= request.security(syminfo.tickerid, htf5, [high, low, close, bar_index, ta.atr(50), timeframe.isintraday ? str.tostring(timeframe.in_seconds() / 60, "#.## MIN") : timeframe.period, ta.pivothigh(swing_length, swing_length), ta.pivotlow(swing_length, swing_length), bar_index ])
// SUPPORT / RESISTANCE FOR HTF6
= request.security(syminfo.tickerid, htf6, [high, low, close, bar_index, ta.atr(50), timeframe.isintraday ? str.tostring(timeframe.in_seconds() / 60, "#.## MIN") : timeframe.period, ta.pivothigh(swing_length, swing_length), ta.pivotlow(swing_length, swing_length), bar_index ])
// SUPPORT / RESISTANCE FOR HTF7
= request.security(syminfo.tickerid, htf7, [high, low, close, bar_index, ta.atr(50), timeframe.isintraday ? str.tostring(timeframe.in_seconds() / 60, "#.## MIN") : timeframe.period, ta.pivothigh(swing_length, swing_length), ta.pivotlow(swing_length, swing_length), bar_index ])
// SUPPORT / RESISTANCE FOR HTF8
= request.security(syminfo.tickerid, htf8, [high, low, close, bar_index, ta.atr(50), timeframe.isintraday ? str.tostring(timeframe.in_seconds() / 60, "#.## MIN") : timeframe.period, ta.pivothigh(swing_length, swing_length), ta.pivotlow(swing_length, swing_length), bar_index ])
// SUPPORT / RESISTANCE FOR HTF9
= request.security(syminfo.tickerid, htf9, [high, low, close, bar_index, ta.atr(50), timeframe.isintraday ? str.tostring(timeframe.in_seconds() / 60, "#.## MIN") : timeframe.period, ta.pivothigh(swing_length, swing_length), ta.pivotlow(swing_length, swing_length), bar_index ])
if enableHtf1 and htf1 != ""
calculateSR(swing_high_values1, swing_low_values1, swing_high_bns1, swing_low_bns1, supply_zones1, demand_zones1, touches_for_supply1, touches_for_demand1, current_supply_poi1, current_demand_poi1, supply_bos1, demand_bos1, high1, low1, timeframe1, barindex1, close1, atr1, true, swing_high1, swing_low1, swing_index1)
if enableHtf2 and htf2 != ""
calculateSR(swing_high_values2, swing_low_values2, swing_high_bns2, swing_low_bns2, supply_zones2, demand_zones2, touches_for_supply2, touches_for_demand2, current_supply_poi2, current_demand_poi2, supply_bos2, demand_bos2, high2, low2, timeframe2, barindex2, close2, atr2, true, swing_high2, swing_low2, swing_index2)
if enableHtf3 and htf3 != ""
calculateSR(swing_high_values3, swing_low_values3, swing_high_bns3, swing_low_bns3, supply_zones3, demand_zones3, touches_for_supply3, touches_for_demand3, current_supply_poi3, current_demand_poi3, supply_bos3, demand_bos3, high3, low3, timeframe3, barindex3, close3, atr3, true, swing_high3, swing_low3, swing_index3)
if enableHtf4 and htf4 != ""
calculateSR(swing_high_values4, swing_low_values4, swing_high_bns4, swing_low_bns4, supply_zones4, demand_zones4, touches_for_supply4, touches_for_demand4, current_supply_poi4, current_demand_poi4, supply_bos4, demand_bos4, high4, low4, timeframe4, barindex4, close4, atr4, true, swing_high4, swing_low4, swing_index4)
if enableHtf5 and htf5 != ""
calculateSR(swing_high_values5, swing_low_values5, swing_high_bns5, swing_low_bns5, supply_zones5, demand_zones5, touches_for_supply5, touches_for_demand5, current_supply_poi5, current_demand_poi5, supply_bos5, demand_bos5, high5, low5, timeframe5, barindex5, close5, atr5, true, swing_high5, swing_low5, swing_index5)
if enableHtf6 and htf6 != ""
calculateSR(swing_high_values6, swing_low_values6, swing_high_bns6, swing_low_bns6, supply_zones6, demand_zones6, touches_for_supply6, touches_for_demand6, current_supply_poi6, current_demand_poi6, supply_bos6, demand_bos6, high6, low6, timeframe6, barindex6, close6, atr6, true, swing_high6, swing_low6, swing_index6)
if enableHtf7 and htf7 != ""
calculateSR(swing_high_values7, swing_low_values7, swing_high_bns7, swing_low_bns7, supply_zones7, demand_zones7, touches_for_supply7, touches_for_demand7, current_supply_poi7, current_demand_poi7, supply_bos7, demand_bos7, high7, low7, timeframe7, barindex7, close7, atr7, true, swing_high7, swing_low7, swing_index7)
if enableHtf8 and htf8 != ""
calculateSR(swing_high_values8, swing_low_values8, swing_high_bns8, swing_low_bns8, supply_zones8, demand_zones8, touches_for_supply8, touches_for_demand8, current_supply_poi8, current_demand_poi8, supply_bos8, demand_bos8, high8, low8, timeframe8, barindex8, close8, atr8, true, swing_high8, swing_low8, swing_index8)
if enableHtf9 and htf9 != ""
calculateSR(swing_high_values9, swing_low_values9, swing_high_bns9, swing_low_bns9, supply_zones9, demand_zones9, touches_for_supply9, touches_for_demand9, current_supply_poi9, current_demand_poi9, supply_bos9, demand_bos9, high9, low9, timeframe9, barindex9, close9, atr9, true, swing_high9, swing_low9, swing_index9)
Master Smart BUY/ SELL & TP
indicator(title="Master Smart BUY/ SELL & TP", shorttitle="MASTER BUY/ SELL & TP", overlay=true)
// Color variables
upTrendColor = color.rgb(1, 42, 226, 5)
neutralColor = #0e0e0e
downTrendColor = color.rgb(255, 38, 0)
fillColor = color.rgb(12, 12, 12, 70) // Color between lines
yellowColor = color.rgb(230, 214, 2)
blackTextColor = color.rgb(0, 0, 0)
blueColor = color.rgb(233, 217, 0)
whiteTextColor = color.rgb(7, 7, 7)
greenColor = #0248e0
redColor = color.rgb(249, 47, 6)
// Source
source = input(defval=close, title="Source")
// Sampling Period
period = input.int(defval=100, minval=1, title="Sampling Period")
// Range Multiplier
multiplier = input.float(defval=3.0, minval=0.1, title="Range Multiplier")
// Take Profit Settings
takeProfitPips = input.float(defval=600.0, title="Take Profit (in pips)")
// Smooth Average Range
smoothRange(x, t, m) =>
adjustedPeriod = t * 2 - 1
avgRange = ta.ema(math.abs(x - x ), t)
smoothRange = ta.ema(avgRange, adjustedPeriod) * m
smoothRange
smoothedRange = smoothRange(source, period, multiplier)
// Trend Filter
trendFilter(x, r) =>
filtered = x
filtered := x > nz(filtered ) ? (x - r < nz(filtered ) ? nz(filtered ) : x - r) :
(x + r > nz(filtered ) ? nz(filtered ) : x + r)
filtered
filter = trendFilter(source, smoothedRange)
// Filter Direction
upCount = 0.0
upCount := filter > filter ? nz(upCount ) + 1 : filter < filter ? 0 : nz(upCount )
downCount = 0.0
downCount := filter < filter ? nz(downCount ) + 1 : filter > filter ? 0 : nz(downCount )
// Colors
filterColor = upCount > 0 ? upTrendColor : downCount > 0 ? downTrendColor : neutralColor
// Double Line Design
lineOffset = smoothedRange * 0.1
upperLinePlot = plot(filter + lineOffset, color=filterColor, linewidth=3, title="Upper Trend Line")
lowerLinePlot = plot(filter - lineOffset, color=filterColor, linewidth=3, title="Lower Trend Line")
fill(upperLinePlot, lowerLinePlot, color=fillColor, title="Trend Fill")
// Break Outs
longCondition = bool(na)
shortCondition = bool(na)
longCondition := (source > filter and source > source and upCount > 0) or
(source > filter and source < source and upCount > 0)
shortCondition := (source < filter and source < source and downCount > 0) or
(source < filter and source > source and downCount > 0)
initialCondition = 0
initialCondition := longCondition ? 1 : shortCondition ? -1 : initialCondition
longSignal = longCondition and initialCondition == -1
shortSignal = shortCondition and initialCondition == 1
// Take Profit Logic
var float entryPriceBuy = na
var float entryPriceSell = na
takeProfitSignalBuy = false
takeProfitSignalSell = false
if (longSignal)
entryPriceBuy := source
if (not na(entryPriceBuy) and source >= entryPriceBuy + takeProfitPips * syminfo.mintick)
takeProfitSignalBuy := true
entryPriceBuy := na
if (shortSignal)
entryPriceSell := source
if (not na(entryPriceSell) and source <= entryPriceSell - takeProfitPips * syminfo.mintick)
takeProfitSignalSell := true
entryPriceSell := na
// Alerts and Signals
plotshape(longSignal, title="Smart Buy Signal", text="Smart Buy", textcolor=color.white, style=shape.labelup, size=size.small, location=location.belowbar, color=greenColor)
plotshape(shortSignal, title="Smart Sell Signal", text="Smart Sell", textcolor=color.white, style=shape.labeldown, size=size.small, location=location.abovebar, color=redColor)
plotshape(takeProfitSignalBuy, title="Book Profit Buy", text="Book Profit", textcolor=blackTextColor, style=shape.labeldown, size=size.small, location=location.abovebar, color=yellowColor)
plotshape(takeProfitSignalSell, title="Book Profit Sell", text="Book Profit", textcolor=whiteTextColor, style=shape.labelup, size=size.small, location=location.belowbar, color=blueColor)
alertcondition(longSignal, title="Smart Buy alert on Master Trend Filter", message="Smart Buy alert on Master Trend Filter")
alertcondition(shortSignal, title="Smart Sell alert on Master Trend Filter", message="Smart Sell alert on Master Trend Filter")
alertcondition(takeProfitSignalBuy, title="Take Profit Buy alert", message="Take Profit Buy reached")
alertcondition(takeProfitSignalSell, title="Take Profit Sell alert", message="Take Profit Sell reached")
karaLytix - Options SuperNova_v1.0//@version=5
indicator('karaLytix - Options SuperNova_v1.0', shorttitle='karaLytix - OSN_v1.0_Major', overlay=true)
showMTFSR = input(title='Show MTFSR', defval=true, group = '===== MTF S/R =====')
// Daily Lines
showdOpen = input.bool(true, title='. O', group='Daily Levels', inline='1')
showdHigh = input.bool(true, title='. H', group='Daily Levels', inline='1')
showdLow = input.bool(true, title='. L', group='Daily Levels', inline='1')
showpdOpen = input.bool(true, title='. pO', group='Daily Levels', inline='1')
showpdHigh = input.bool(true, title='. pH', group='Daily Levels', inline='1')
showpdLow = input.bool(true, title='. pL', group='Daily Levels', inline='1')
showpdEQ = input.bool(true, title='. pEQ', group='Daily Levels', inline='1', tooltip='p = previous, O = Open, H = High, L = Low, EQ = Equilibrium (50%)')
// Weekly Lines
showwOpen = input.bool(true, title='. O', group='Weekly Levels', inline='1')
showwHigh = input.bool(true, title='. H', group='Weekly Levels', inline='1')
showwLow = input.bool(true, title='. L', group='Weekly Levels', inline='1')
showpwOpen = input.bool(true, title='. pO', group='Weekly Levels', inline='1')
showpwHigh = input.bool(true, title='. pH', group='Weekly Levels', inline='1')
showpwLow = input.bool(true, title='. pL', group='Weekly Levels', inline='1')
showpwEQ = input.bool(true, title='. pEQ', group='Weekly Levels', inline='1', tooltip='p = previous, O = Open, H = High, L = Low, EQ = Equilibrium (50%)')
// Monthly Lines
showmOpen = input.bool(true, title='- O', group='Monthly Levels', inline='1')
showmHigh = input.bool(true, title='- H', group='Monthly Levels', inline='1')
showmLow = input.bool(true, title='- L', group='Monthly Levels', inline='1')
showpmOpen = input.bool(true, title='. pO', group='Monthly Levels', inline='1')
showpmHigh = input.bool(true, title='. pH', group='Monthly Levels', inline='1')
showpmLow = input.bool(true, title='. pL', group='Monthly Levels', inline='1', tooltip='p = previous, O = Open, H = High, L = Low')
// Yealy Lines
showyOpen = input.bool(true, title='. O', group='Yearly Levels', inline='1')
showyHigh = input.bool(true, title='. H', group='Yearly Levels', inline='1')
showyLow = input.bool(true, title='. L', group='Yearly Levels', inline='1', tooltip='O = Open, H = High, L = Low')
// VWAPS
show_DVWAPs = input.bool(true, title='Daily', group='Standard VWAPS - Daily, Weekly, Monthly', inline='VWAP1')
show_WVWAPs = input.bool(true, title='Weekly', group='Standard VWAPS - Daily, Weekly, Monthly', inline='VWAP1')
show_MVWAPs = input.bool(true, title='Monthly', group='Standard VWAPS - Daily, Weekly, Monthly', inline='VWAP1')
show_YVWAPs = input.bool(true, title='Yearly', group='Standard VWAPS - Daily, Weekly, Monthly', inline='VWAP1', tooltip='M-VWAP and Y-VWAP only shows on higher time frames')
var DSpaces = ' '
var DPSpaces = ' '
var DNoSpaces = ' '
var DPNoSpaces = ' '
var WSpaces = ' '
var WPSpaces = ' '
var WNoSpaces = ' '
var WPNoSpaces = ' '
var MSpaces = ' '
var MPSpaces = ' '
var MNoSpaces = ' '
var MPNoSpaces = ' '
var YSpaces = ' '
var YPSpaces = ' '
var YNoSpaces = ' '
var YPNoSpaces = ' '
x1 = ta.valuewhen(barstate.islast, bar_index, 0)
D_extend_length = input.int(25, title='Extend Daily short line', group='Line Options', inline='1')
D_x2 = x1 + D_extend_length
W_extend_length = input.int(35, title='Extend Weekly short line', group='Line Options', inline='1')
W_x2 = x1 + W_extend_length
M_extend_length = input.int(45, title='Extend Monthly short line', group='Line Options', inline='1')
M_x2 = x1 + M_extend_length
Y_extend_length = input.int(55, title='Extend Yearly short line', group='Line Options', inline='1')
Y_x2 = x1 + Y_extend_length
//Round of Line Value
f_round_up_to_tick(x, mintick) =>
mult = 1 / mintick
value = math.ceil(x * mult) / mult
value
// Line Options
extend = extend.none
exnone = input.bool(true, title='Short Line', group='Line Options', inline='2')
exboth = input.bool(false, title='Line Across Screen', group='Line Options', inline='3')
exright = input.bool(false, title='Line To Right', group='Line Options', inline='3')
showPrice = input.bool(false, title='Show Level Prices', group='Line Options', inline='4')
showVPrice = input.bool(false, title='Show VWAP Prices', group='Line Options', inline='4')
extend := exnone ? extend.none : exboth ? extend.both : exright ? extend.right : extend
D_x2loc = D_x2
D_x2loc := exnone ? D_x2 : exboth ? bar_index : exright ? bar_index : D_x2loc
W_x2loc = W_x2
W_x2loc := exnone ? W_x2 : exboth ? bar_index : exright ? bar_index : W_x2loc
M_x2loc = M_x2
M_x2loc := exnone ? M_x2 : exboth ? bar_index : exright ? bar_index : M_x2loc
Y_x2loc = Y_x2
Y_x2loc := exnone ? Y_x2 : exboth ? bar_index : exright ? bar_index : Y_x2loc
DailySpaces = DNoSpaces
DailySpaces := exnone ? DNoSpaces : exboth ? DSpaces : exright ? DSpaces : DailySpaces
DailyPSpaces = DPNoSpaces
DailyPSpaces := exnone ? DPNoSpaces : exboth ? DPSpaces : exright ? DPSpaces : DailyPSpaces
WeeklySpaces = WNoSpaces
WeeklySpaces := exnone ? WNoSpaces : exboth ? WSpaces : exright ? WSpaces : WeeklySpaces
WeeklyPSpaces = WPNoSpaces
WeeklyPSpaces := exnone ? WPNoSpaces : exboth ? WPSpaces : exright ? WPSpaces : WeeklyPSpaces
MonthlySpaces = MNoSpaces
MonthlySpaces := exnone ? MNoSpaces : exboth ? MSpaces : exright ? MSpaces : MonthlySpaces
MonthlyPSpaces = MPNoSpaces
MonthlyPSpaces := exnone ? MPNoSpaces : exboth ? MPSpaces : exright ? MPSpaces : MonthlyPSpaces
YearlySpaces = YNoSpaces
YearlySpaces := exnone ? YNoSpaces : exboth ? YSpaces : exright ? YSpaces : YearlySpaces
YearlyPSpaces = YPNoSpaces
YearlyPSpaces := exnone ? YPNoSpaces : exboth ? YPSpaces : exright ? YPSpaces : YearlyPSpaces
//Line Colors
DailyInputColor = input.color(color.blue, title='Daily', group='User Selectable Line Colors', inline='Input 0')
WeeklyInputColor = input.color(color.yellow, title='Weekly', group='User Selectable Line Colors', inline='Input 0')
MonthlyInputColor = input.color(color.purple, title='Monthly', group='User Selectable Line Colors', inline='Input 1')
YearlyInputColor = input.color(color.red, title='Yearly', group='User Selectable Line Colors', inline='Input 1')
show_DVWAPs_color = show_DVWAPs ? DailyInputColor : na
show_WVWAPs_color = show_WVWAPs ? WeeklyInputColor : na
show_MVWAPs_color = show_MVWAPs ? MonthlyInputColor : na
show_YVWAPs_color = show_YVWAPs ? YearlyInputColor : na
//////////////////////////////////////
/////Previous Day Values//////////////
//////////////////////////////////////
// Previous Day Open
// showpdOpen = input(true, title="- pdOpen", group="pd Values", inline = "Daily")
pdOpen = request.security(syminfo.tickerid, 'D', open , lookahead=barmerge.lookahead_on)
var line pdOpenLine = na
var label pdOpenLabel = na
if showpdOpen
pdOpenLine := line.new(x1=x1, y1=pdOpen, x2=D_x2, y2=pdOpen, xloc=xloc.bar_index, width=1, color=DailyInputColor, style=line.style_dashed, extend=extend)
pdOpenLabel := label.new(D_x2loc, pdOpen, text=DailySpaces + 'pdOpen', color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(pdOpenLine )
label.delete(pdOpenLabel )
var label pdOpenLabelPrice = na
if showpdOpen and showPrice
pdOpenLabelPrice := label.new(D_x2loc, pdOpen, text=DailyPSpaces + str.tostring(f_round_up_to_tick(pdOpen, syminfo.mintick)), color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(pdOpenLabelPrice )
i_text1 = '₿ - Scripts by Frien_dd - ₿'
// Previous Day High
// showpdHigh = input(true, title="- pdHigh", group="pd Values", inline = "Daily")
pdHigh = request.security(syminfo.tickerid, 'D', high , lookahead=barmerge.lookahead_on)
var line pdHighLine = na
var label pdHighLabel = na
if showpdHigh
pdHighLine := line.new(x1=x1, y1=pdHigh, x2=D_x2, y2=pdHigh, xloc=xloc.bar_index, width=1, color=DailyInputColor, style=line.style_dashed, extend=extend)
pdHighLabel := label.new(D_x2loc, pdHigh, text=DailySpaces + 'pdHigh', color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(pdHighLine )
label.delete(pdHighLabel )
var label pdHighLabelPrice = na
if showpdHigh and showPrice
pdHighLabelPrice := label.new(D_x2loc, pdHigh, text=DailyPSpaces + str.tostring(f_round_up_to_tick(pdHigh, syminfo.mintick)), color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(pdHighLabelPrice )
// Previous Day Low
// showpdLow = input(true, title="- pdLow", group="pd Values", inline = "Daily")
pdLow = request.security(syminfo.tickerid, 'D', low , lookahead=barmerge.lookahead_on)
var line pdLowLine = na
var label pdLowLabel = na
if showpdLow
pdLowLine := line.new(x1=x1, y1=pdLow, x2=D_x2, y2=pdLow, xloc=xloc.bar_index, width=1, color=DailyInputColor, style=line.style_dashed, extend=extend)
pdLowLabel := label.new(D_x2loc, pdLow, text=DailySpaces + 'pdLow', color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(pdLowLine )
label.delete(pdLowLabel )
var label pdLowLabelPrice = na
if showpdLow and showPrice
pdLowLabelPrice := label.new(D_x2loc, pdLow, text=DailyPSpaces + str.tostring(f_round_up_to_tick(pdLow, syminfo.mintick)), color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(pdLowLabelPrice )
// Previous Day EQ
// showpdEQ = input(true, title="- pdEQ", group="pd Values", inline = "Daily")
pdEQ = (pdHigh + pdLow) / 2
var line pdEQLine = na
var label pdEQLabel = na
if showpdEQ
pdEQLine := line.new(x1=x1, y1=pdEQ, x2=D_x2, y2=pdEQ, xloc=xloc.bar_index, width=1, color=DailyInputColor, style=line.style_dashed, extend=extend)
pdEQLabel := label.new(D_x2loc, pdEQ, text=DailySpaces + 'pdEQ', color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(pdEQLine )
label.delete(pdEQLabel )
var label pdEQLabelPrice = na
if showpdEQ and showPrice
pdEQLabelPrice := label.new(D_x2loc, pdEQ, text=DailyPSpaces + str.tostring(f_round_up_to_tick(pdEQ, syminfo.mintick)), color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(pdEQLabelPrice )
//////////////////////////////////////
/////Previous Week Values//////////////
//////////////////////////////////////
// Previous Week Open
// showpwOpen = input(true, title="- pwOpen", group="pw Values", inline = "Weekly")
pwOpen = request.security(syminfo.tickerid, 'W', open , lookahead=barmerge.lookahead_on)
var line pwOpenLine = na
var label pwOpenLabel = na
if showpwOpen
pwOpenLine := line.new(x1=x1, y1=pwOpen, x2=W_x2, y2=pwOpen, xloc=xloc.bar_index, width=1, color=WeeklyInputColor, style=line.style_dashed, extend=extend)
pwOpenLabel := label.new(W_x2loc, pwOpen, text=WeeklySpaces + 'pwOpen', color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(pwOpenLine )
label.delete(pwOpenLabel )
var label pwOpenLabelPrice = na
if showpwOpen and showPrice
pwOpenLabelPrice := label.new(W_x2loc, pwOpen, text=WeeklyPSpaces + str.tostring(f_round_up_to_tick(pwOpen, syminfo.mintick)), color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(pwOpenLabelPrice )
// Previous Week High
// showpwHigh = input(true, title="- pwHigh", group="pw Values", inline = "Weekly")
pwHigh = request.security(syminfo.tickerid, 'W', high , lookahead=barmerge.lookahead_on)
var line pwHighLine = na
var label pwHighLabel = na
if showpwHigh
pwHighLine := line.new(x1=x1, y1=pwHigh, x2=W_x2, y2=pwHigh, xloc=xloc.bar_index, width=1, color=WeeklyInputColor, style=line.style_dashed, extend=extend)
pwHighLabel := label.new(W_x2loc, pwHigh, text=WeeklySpaces + 'pwHigh', color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(pwHighLine )
label.delete(pwHighLabel )
var label pwHighLabelPrice = na
if showpwHigh and showPrice
pwHighLabelPrice := label.new(W_x2loc, pwHigh, text=WeeklyPSpaces + str.tostring(f_round_up_to_tick(pwHigh, syminfo.mintick)), color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(pwHighLabelPrice )
// Previous Week Low
// showpwLow = input(true, title="- pwLow", group="pw Values", inline = "Weekly")
pwLow = request.security(syminfo.tickerid, 'W', low , lookahead=barmerge.lookahead_on)
var line pwLowLine = na
var label pwLowLabel = na
if showpwLow
pwLowLine := line.new(x1=x1, y1=pwLow, x2=W_x2, y2=pwLow, xloc=xloc.bar_index, width=1, color=WeeklyInputColor, style=line.style_dashed, extend=extend)
pwLowLabel := label.new(W_x2loc, pwLow, text=WeeklySpaces + 'pwLow', color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(pwLowLine )
label.delete(pwLowLabel )
var label pwLowLabelPrice = na
if showpwLow and showPrice
pwLowLabelPrice := label.new(W_x2loc, pwLow, text=WeeklyPSpaces + str.tostring(f_round_up_to_tick(pwLow, syminfo.mintick)), color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(pwLowLabelPrice )
// Previous Week EQ
// showpwEQ = input(true, title="- pwEQ", group="pw Values", inline = "Weekly")a
pwEQ = (pwHigh + pwLow) / 2
var line pwEQLine = na
var label pwEQLabel = na
if showpwEQ
pwEQLine := line.new(x1=x1, y1=pwEQ, x2=W_x2, y2=pwEQ, xloc=xloc.bar_index, width=1, color=WeeklyInputColor, style=line.style_dashed, extend=extend)
pwEQLabel := label.new(W_x2loc, pwEQ, text=WeeklySpaces + 'pwEQ', color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(pwEQLine )
label.delete(pwEQLabel )
var label pwEQLabelPrice = na
if showpwEQ and showPrice
pwEQLabelPrice := label.new(W_x2loc, pwEQ, text=WeeklyPSpaces + str.tostring(f_round_up_to_tick(pwEQ, syminfo.mintick)), color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(pwEQLabelPrice )
///////////////////////////////////////
/////Weekly Open-High-Low/////////////
//////////////////////////////////////
// Current Monthly Open
// showwOpen = input(true, title=". wOpen", group="Weekly Levels", inline = "1")
wOpen = request.security(syminfo.tickerid, 'W', open, lookahead=barmerge.lookahead_on)
var line wOpenLine = na
var label wOpenLabel = na
if showwOpen
wOpenLine := line.new(x1=x1, y1=wOpen, x2=W_x2, y2=wOpen, xloc=xloc.bar_index, width=1, color=WeeklyInputColor, style=line.style_dashed, extend=extend)
wOpenLabel := label.new(W_x2loc, wOpen, text=WeeklySpaces + 'wOpen', color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(wOpenLine )
label.delete(wOpenLabel )
var label wOpenLabelPrice = na
if showwOpen and showPrice
wOpenLabelPrice := label.new(W_x2loc, wOpen, text=WeeklyPSpaces + str.tostring(f_round_up_to_tick(wOpen, syminfo.mintick)), color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(wOpenLabelPrice )
// Weekly Low High Levels
var LastWeek = 0
var WeeklyHigh = 0.0
var WeeklyLow = 0.0
ThisWeek = time('W')
CheckWeek = ThisWeek != LastWeek
LastWeek := ThisWeek
WeeklyHigh := CheckWeek or high > WeeklyHigh ? high : WeeklyHigh
WeeklyLow := CheckWeek or low < WeeklyLow ? low : WeeklyLow
var line wLowLine = na
var label wLowLabel = na
// showwLow = input(true, title=". wLow", group="Weekly Levels", inline = "1")
if showwLow
wLowLine := line.new(x1=x1, y1=WeeklyLow, x2=W_x2, y2=WeeklyLow, xloc=xloc.bar_index, width=1, color=WeeklyInputColor, style=line.style_solid, extend=extend)
wLowLabel := label.new(W_x2loc, WeeklyLow, text=MonthlySpaces + 'wLow', color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(wLowLine )
label.delete(wLowLabel )
var label wLowLabelPrice = na
if showwLow and showPrice
wLowLabelPrice := label.new(W_x2loc, WeeklyLow, text=WeeklyPSpaces + str.tostring(f_round_up_to_tick(WeeklyLow, syminfo.mintick)), color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(wLowLabelPrice )
var line wHighLine = na
var label wHighLabel = na
// showwHigh = input(true, title=". wHigh", group="Weekly Levels", inline = "1")
if showwHigh
wHighLine := line.new(x1=x1, y1=WeeklyHigh, x2=W_x2, y2=WeeklyHigh, xloc=xloc.bar_index, width=1, color=WeeklyInputColor, style=line.style_solid, extend=extend)
wHighLabel := label.new(W_x2loc, WeeklyHigh, text=WeeklySpaces + 'wHigh', color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(wHighLine )
label.delete(wHighLabel )
var label wHighLabelPrice = na
if showwHigh and showPrice
wHighLabelPrice := label.new(W_x2loc, WeeklyHigh, text=WeeklyPSpaces + str.tostring(f_round_up_to_tick(WeeklyHigh, syminfo.mintick)), color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(wHighLabelPrice )
//////////////////////////////////////
/////Previous Month Values////////////
//////////////////////////////////////
// Previous Month Open
// showpmOpen = input(true, title="- pmOpen", group="pm Values", inline = "Monthly")
pmOpen = request.security(syminfo.tickerid, 'M', open , lookahead=barmerge.lookahead_on)
var line pmOpenLine = na
var label pmOpenLabel = na
if showpmOpen
pmOpenLine := line.new(x1=x1, y1=pmOpen, x2=M_x2, y2=pmOpen, xloc=xloc.bar_index, width=1, color=MonthlyInputColor, style=line.style_dashed, extend=extend)
pmOpenLabel := label.new(M_x2loc, pmOpen, text=MonthlySpaces + 'pmOpen', color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(pmOpenLine )
label.delete(pmOpenLabel )
var label pmOpenLabelPrice = na
if showpmOpen and showPrice
pmOpenLabelPrice := label.new(M_x2loc, pmOpen, text=MonthlyPSpaces + str.tostring(f_round_up_to_tick(pmOpen, syminfo.mintick)), color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(pmOpenLabelPrice )
// Previous Month High
// showpmHigh = input(true, title="- pmHigh", group="pm Values", inline = "Monthly")
pmHigh = request.security(syminfo.tickerid, 'M', high , lookahead=barmerge.lookahead_on)
var line pmHighLine = na
var label pmHighLabel = na
if showpmHigh
pmHighLine := line.new(x1=x1, y1=pmHigh, x2=M_x2, y2=pmHigh, xloc=xloc.bar_index, width=1, color=MonthlyInputColor, style=line.style_dashed, extend=extend)
pmHighLabel := label.new(M_x2loc, pmHigh, text=MonthlySpaces + 'pmHigh', color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(pmHighLine )
label.delete(pmHighLabel )
var label pmHighLabelPrice = na
if showpmHigh and showPrice
pmHighLabelPrice := label.new(M_x2loc, pmHigh, text=MonthlyPSpaces + str.tostring(f_round_up_to_tick(pmHigh, syminfo.mintick)), color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(pmHighLabelPrice )
// Previous Month Low
// showpmLow = input(true, title="- pmLow", group="pm Values", inline = "Monthly")
pmLow = request.security(syminfo.tickerid, 'M', low , lookahead=barmerge.lookahead_on)
var line pmLowLine = na
var label pmLowLabel = na
if showpmLow
pmLowLine := line.new(x1=x1, y1=pmLow, x2=M_x2, y2=pmLow, xloc=xloc.bar_index, width=1, color=MonthlyInputColor, style=line.style_dashed, extend=extend)
pmLowLabel := label.new(M_x2loc, pmLow, text=MonthlySpaces + 'pmLow', color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(pmLowLine )
label.delete(pmLowLabel )
var label pmLowLabelPrice = na
if showpmLow and showPrice
pmLowLabelPrice := label.new(M_x2loc, pmLow, text=MonthlyPSpaces + str.tostring(f_round_up_to_tick(pmLow, syminfo.mintick)), color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(pmLowLabelPrice )
//////////////////////////////////////
/////Daily Open///////////////////////
//////////////////////////////////////
// showdOpen = input(true, title="- dOpen", group="Current Daily", inline = "Daily")
dOpen = request.security(syminfo.tickerid, 'D', open, lookahead=barmerge.lookahead_on)
var line dOpenLine = na
var label dOpenLabel = na
if showdOpen
dOpenLine := line.new(x1=x1, y1=dOpen, x2=D_x2, y2=dOpen, xloc=xloc.bar_index, width=1, color=DailyInputColor, style=line.style_dashed, extend=extend)
dOpenLabel := label.new(D_x2loc, dOpen, text=DailySpaces + 'dOpen', color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(dOpenLine )
label.delete(dOpenLabel )
var label dOpenLabelPrice = na
if showdOpen and showPrice
dOpenLabelPrice := label.new(D_x2loc, dOpen, text=DailyPSpaces + str.tostring(f_round_up_to_tick(dOpen, syminfo.mintick)), color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(dOpenLabelPrice )
// Daily Low High Levels
var LastDay = 0
var DailyHigh = 0.0
var DailyLow = 0.0
ThisDay = time('D')
CheckDay = ThisDay != LastDay
LastDay := ThisDay
DailyHigh := CheckDay or high > DailyHigh ? high : DailyHigh
DailyLow := CheckDay or low < DailyLow ? low : DailyLow
// Daily Low and High
var line dLowLine = na
var label dLowLabel = na
// showdLow = input(true, title=". dLow", group="Daily Levels", inline = "1")
if showdLow
dLowLine := line.new(x1=x1, y1=DailyLow, x2=D_x2, y2=DailyLow, xloc=xloc.bar_index, width=1, color=DailyInputColor, style=line.style_solid, extend=extend)
dLowLabel := label.new(D_x2loc, DailyLow, text=DailySpaces + 'dLow', color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(dLowLine )
label.delete(dLowLabel )
var label dLowLabelPrice = na
if showdLow and showPrice
dLowLabelPrice := label.new(D_x2loc, DailyLow, text=DailyPSpaces + str.tostring(f_round_up_to_tick(DailyLow, syminfo.mintick)), color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(dLowLabelPrice )
var line dHighLine = na
var label dHighLabel = na
// showdHigh = input(true, title=". dHigh", group="Daily Levels", inline = "1")
if showdHigh
dHighLine := line.new(x1=x1, y1=DailyHigh, x2=D_x2, y2=DailyHigh, xloc=xloc.bar_index, width=1, color=DailyInputColor, style=line.style_solid, extend=extend)
dHighLabel := label.new(D_x2loc, DailyHigh, text=DailySpaces + 'dHigh', color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(dHighLine )
label.delete(dHighLabel )
var label dHighLabelPrice = na
if showdHigh and showPrice
dHighLabelPrice := label.new(D_x2loc, DailyHigh, text=DailyPSpaces + str.tostring(f_round_up_to_tick(DailyHigh, syminfo.mintick)), color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(dHighLabelPrice )
///////////////////////////////////////
/////Monthly Open-High-Low/////////////
//////////////////////////////////////
// Current Monthly Open
// showmOpen = input(true, title="- mOpen", group="Current Monthly", inline = "Monthly")
mOpen = request.security(syminfo.tickerid, 'M', open, lookahead=barmerge.lookahead_on)
var line mOpenLine = na
var label mOpenLabel = na
if showmOpen
mOpenLine := line.new(x1=x1, y1=mOpen, x2=M_x2, y2=mOpen, xloc=xloc.bar_index, width=1, color=MonthlyInputColor, style=line.style_dashed, extend=extend)
mOpenLabel := label.new(M_x2loc, mOpen, text=MonthlySpaces + 'mOpen', color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(mOpenLine )
label.delete(mOpenLabel )
var label mOpenLabelPrice = na
if showmOpen and showPrice
mOpenLabelPrice := label.new(M_x2loc, mOpen, text=MonthlyPSpaces + str.tostring(f_round_up_to_tick(mOpen, syminfo.mintick)), color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(mOpenLabelPrice )
// Current Monthly High
//Current Day High Low
var LastMonth = 0
var MonthlyHigh = 0.0
var MonthlyLow = 0.0
ThisMonth = time('M')
CheckMonth = ThisMonth != LastMonth
LastMonth := ThisMonth
MonthlyHigh := CheckMonth or high > MonthlyHigh ? high : MonthlyHigh
MonthlyLow := CheckMonth or low < MonthlyLow ? low : MonthlyLow
var line mLowLine = na
var label mLowLabel = na
// showmLow = input(true, title="- mLow", group="Current Monthly", inline = "Monthly")
if showmLow
mLowLine := line.new(x1=x1, y1=MonthlyLow, x2=M_x2, y2=MonthlyLow, xloc=xloc.bar_index, width=1, color=MonthlyInputColor, style=line.style_solid, extend=extend)
mLowLabel := label.new(M_x2loc, MonthlyLow, text=MonthlySpaces + 'mLow', color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(mLowLine )
label.delete(mLowLabel )
var label mLowLabelPrice = na
if showmLow and showPrice
mLowLabelPrice := label.new(M_x2loc, MonthlyLow, text=MonthlyPSpaces + str.tostring(f_round_up_to_tick(MonthlyLow, syminfo.mintick)), color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(mLowLabelPrice )
var line mHighLine = na
var label mHighLabel = na
// showmHigh = input(true, title="- mHigh", group="Current Monthly", inline = "Monthly")
if showmHigh
mHighLine := line.new(x1=x1, y1=MonthlyHigh, x2=M_x2, y2=MonthlyHigh, xloc=xloc.bar_index, width=1, color=MonthlyInputColor, style=line.style_solid, extend=extend)
mHighLabel := label.new(M_x2loc, MonthlyHigh, text=MonthlySpaces + 'mHigh', color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(mHighLine )
label.delete(mHighLabel )
var label mHighLabelPrice = na
if showmHigh and showPrice
mHighLabelPrice := label.new(M_x2loc, MonthlyHigh, text=MonthlyPSpaces + str.tostring(f_round_up_to_tick(MonthlyHigh, syminfo.mintick)), color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(mHighLabelPrice )
i_tableYpos = 'bottom'
///////////////////////////////////////
/////Yearly Open-High-Low/////////////
//////////////////////////////////////
// Current Yearly Open
// showyOpen = input(true, title="- yOpen", group="Current Yearly", inline = "Yearly")
yOpen = request.security(syminfo.tickerid, '12M', open, lookahead=barmerge.lookahead_on)
var line yOpenLine = na
var label yOpenLabel = na
if showyOpen
yOpenLine := line.new(x1=x1, y1=yOpen, x2=Y_x2, y2=yOpen, xloc=xloc.bar_index, width=1, color=YearlyInputColor, style=line.style_dashed, extend=extend)
yOpenLabel := label.new(Y_x2loc, yOpen, text=YearlySpaces + 'yOpen', color=YearlyInputColor, textcolor=YearlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(yOpenLine )
label.delete(yOpenLabel )
var label yOpenLabelPrice = na
if showyOpen and showPrice
yOpenLabelPrice := label.new(Y_x2loc, yOpen, text=YearlyPSpaces + str.tostring(f_round_up_to_tick(yOpen, syminfo.mintick)), color=YearlyInputColor, textcolor=YearlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(yOpenLabelPrice )
// Current Yearly High Low
var LastYear = 0
var YearlyHigh = 0.0
var YearlyLow = 0.0
ThisYear = time('12M')
CheckYear = ThisYear != LastYear
LastYear := ThisYear
YearlyHigh := CheckYear or high > YearlyHigh ? high : YearlyHigh
YearlyLow := CheckYear or low < YearlyLow ? low : YearlyLow
i_tableXpos = 'right'
var line yLowLine = na
var label yLowLabel = na
if showyLow
yLowLine := line.new(x1=x1, y1=YearlyLow, x2=Y_x2, y2=YearlyLow, xloc=xloc.bar_index, width=1, color=YearlyInputColor, style=line.style_solid, extend=extend)
yLowLabel := label.new(Y_x2loc, YearlyLow, text=YearlySpaces + 'yLow', color=YearlyInputColor, textcolor=YearlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(yLowLine )
label.delete(yLowLabel )
var label yLowLabelPrice = na
if showyLow and showPrice
yLowLabelPrice := label.new(Y_x2loc, YearlyLow, text=YearlyPSpaces + str.tostring(f_round_up_to_tick(YearlyLow, syminfo.mintick)), color=YearlyInputColor, textcolor=YearlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(yLowLabelPrice )
var line yHighLine = na
var label yHighLabel = na
if showyHigh
yHighLine := line.new(x1=x1, y1=YearlyHigh, x2=Y_x2, y2=YearlyHigh, xloc=xloc.bar_index, width=1, color=YearlyInputColor, style=line.style_solid, extend=extend)
yHighLabel := label.new(Y_x2loc, YearlyHigh, text=YearlySpaces + 'yHigh', color=YearlyInputColor, textcolor=YearlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
line.delete(yHighLine )
label.delete(yHighLabel )
var label yHighLabelPrice = na
if showyHigh and showPrice
yHighLabelPrice := label.new(Y_x2loc, YearlyHigh, text=YearlyPSpaces + str.tostring(f_round_up_to_tick(YearlyHigh, syminfo.mintick)), color=YearlyInputColor, textcolor=YearlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(yHighLabelPrice )
i_height = 7
i_width = 15
i_c_text = color.new(color.white, 50)
//Daily VWAP
is_today = year == year(timenow) and month == month(timenow) and dayofmonth == dayofmonth(timenow)
roundedVWAP = f_round_up_to_tick(ta.vwap, syminfo.mintick)
VWAP = roundedVWAP
plot(VWAP, 'D-VWAP', is_today ? show_DVWAPs_color : na, offset=0)
var label VWAPLabel = na
if VWAP
VWAPLabel := label.new(bar_index, VWAP, text=' D-VWAP', color=show_DVWAPs_color, textcolor=show_DVWAPs_color, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(VWAPLabel )
var label VWAPPLabel = na
if VWAP and showVPrice
VWAPPLabel := label.new(bar_index, VWAP, text=' ' + str.tostring(VWAP), color=show_DVWAPs_color, textcolor=show_DVWAPs_color, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(VWAPPLabel )
//Weeekly VWAP
src = hlc3
wt = time('W')
wstart = na(wt ) or wt > wt
wsumSrc = src * volume
wsumVol = volume
wsumSrc := wstart ? wsumSrc : wsumSrc + wsumSrc
wsumVol := wstart ? wsumVol : wsumVol + wsumVol
WVWAP = wsumSrc / wsumVol
wvw = f_round_up_to_tick(WVWAP, syminfo.mintick)
plot(timeframe.isintraday ? wvw : na, title='W-VWAP', color=show_WVWAPs_color)
var label wVWAPLabel = na
if wvw
wVWAPLabel := label.new(bar_index, wvw, text=' W-VWAP', color=show_WVWAPs_color, textcolor=show_WVWAPs_color, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(wVWAPLabel )
var label wVWAPPLabel = na
if wvw and showVPrice
wVWAPPLabel := label.new(bar_index, wvw, text=' ' + str.tostring(wvw), color=show_WVWAPs_color, textcolor=show_WVWAPs_color, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(wVWAPPLabel )
i_textSize = 'normal'
i_c_bg = color.new(color.blue, 80)
//Monthly VWAP
var float vwapsum = na
var float volumesum = na
newSession = ta.change(time('M'))
vwapsum := newSession ? hl2 * volume : hl2 * volume + vwapsum
volumesum := newSession ? volume : volume + volumesum
MVWAP = vwapsum / volumesum
mvw = f_round_up_to_tick(MVWAP, syminfo.mintick)
plot(newSession ? na : mvw, title='M-VWAP', color=show_MVWAPs_color, style=plot.style_linebr)
var label mVWAPLabel = na
if mvw
mVWAPLabel := label.new(bar_index, mvw, text=' M-VWAP', color=show_MVWAPs_color, textcolor=show_MVWAPs_color, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(mVWAPLabel )
var label mVWAPPLabel = na
if mvw and showVPrice
mVWAPPLabel := label.new(bar_index, mvw, text=' ' + str.tostring(mvw), color=show_MVWAPs_color, textcolor=show_MVWAPs_color, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(mVWAPPLabel )
var table watermark = table.new(i_tableYpos + '_' + i_tableXpos, 1, 1)
//Yearly VWAP
var float yvwapsum = na
var float yvolumesum = na
ynewSession = ta.change(time('12M'))
yvwapsum := ynewSession ? hl2 * volume : hl2 * volume + yvwapsum
yvolumesum := ynewSession ? volume : volume + yvolumesum
YVWAP = yvwapsum / yvolumesum
yvw = f_round_up_to_tick(YVWAP, syminfo.mintick)
table.cell(watermark, 0, 0, i_text1, i_width, i_height, i_c_text, text_size=i_textSize, bgcolor=i_c_bg)
plot(newSession ? na : yvw, title='Y-VWAP', color=show_YVWAPs_color, style=plot.style_linebr)
var label yVWAPLabel = na
if yvw
yVWAPLabel := label.new(bar_index, yvw, text=' Y-VWAP', color=show_YVWAPs_color, textcolor=show_YVWAPs_color, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(yVWAPLabel )
var label yVWAPPLabel = na
if yvw and showVPrice
yVWAPPLabel := label.new(bar_index, yvw, text='' + str.tostring(yvw), color=show_YVWAPs_color, textcolor=show_YVWAPs_color, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
label.delete(yVWAPPLabel )
/////////////////////Volaility & Fibbonacci//////////
showVF = input(title='Show VF', defval=true, group = '===== Volatility & Fibbonacci =====')
//supertend
factor = input.int(3, title="SuperTrend Factor")
atrP = input.int(10, title="SuperTrend atrPeriod")
= ta.supertrend(factor, atrP)
sclr = direction > 0 ? color.red : color.green
plot(superTrend, title='SuperTrend', color=sclr)
//EMA
emaP = input.int(31, title="EMA length")
srcEma = input.source(high,"EMA source")
plot(ta.ema(srcEma,emaP))
//Volatality and Fibbonacci trade table
showTable=input(true, title="Show VF Table")
res = 'D'
test1=0
f_secureSecurity(_symbol, _res, _src) => request.security(_symbol, _res, _src, barmerge.gaps_off) // orignal code line
dc = f_secureSecurity(syminfo.tickerid, res, close )
dc1 = f_secureSecurity(syminfo.tickerid, res, close )
dc2 = f_secureSecurity(syminfo.tickerid, res, close )
dc3 = f_secureSecurity(syminfo.tickerid, res, close )
dc4 = f_secureSecurity(syminfo.tickerid, res, close )
dc5 = f_secureSecurity(syminfo.tickerid, res, close )
dc6 = f_secureSecurity(syminfo.tickerid, res, close )
dc7 = f_secureSecurity(syminfo.tickerid, res, close )
dc8 = f_secureSecurity(syminfo.tickerid, res, close )
dc9 = f_secureSecurity(syminfo.tickerid, res, close )
dc10 = f_secureSecurity(syminfo.tickerid, res, close )
dop = f_secureSecurity(syminfo.tickerid, res, open)
logg00 = math.log(dc/dc1)
logg11 = math.log(dc1/dc2)
logg22 = math.log(dc2/dc3)
logg33 = math.log(dc3/dc4)
logg44 = math.log(dc4/dc5)
logg55 = math.log(dc5/dc6)
logg66 = math.log(dc6/dc7)
logg77 = math.log(dc7/dc8)
logg88 = math.log(dc8/dc9)
logg99 = math.log(dc9/dc10)
squrr00 = logg00*logg00
squrr11 = logg11*logg11
squrr22 = logg22*logg22
squrr33 = logg33*logg33
squrr44 = logg44*logg44
squrr55 = logg55*logg55
squrr66 = logg66*logg66
squrr77 = logg77*logg77
squrr88 = logg88*logg88
squrr99 = logg99*logg99
avg_logg0 = (logg00+logg11+logg22+logg33+logg44+logg55+logg66+logg77+logg88+logg99)/10
avg_squrr0 = (squrr00+squrr11+squrr22+squrr33+squrr44+squrr55+squrr66+squrr77+squrr88+squrr99)/10
variancee0 = avg_squrr0 - (avg_logg0*avg_logg0)
volatility0 = math.sqrt(variancee0)
round_preci=input.int(title="VF Decimal Scale", options= , defval=0)
range11=math.round(dc*volatility0,round_preci)
doKdc= math.abs(dop-dc)>(0.382*range11)? dop : dc
//re-do calc
logg = math.log(doKdc/dc1)
logg1 = math.log(dc1/dc2)
logg2 = math.log(dc2/dc3)
logg3 = math.log(dc3/dc4)
logg4 = math.log(dc4/dc5)
logg5 = math.log(dc5/dc6)
logg6 = math.log(dc6/dc7)
logg7 = math.log(dc7/dc8)
logg8 = math.log(dc8/dc9)
logg9 = math.log(dc9/dc10)
squrr = logg*logg
squrr1 = logg1*logg1
squrr2 = logg2*logg2
squrr3 = logg3*logg3
squrr4 = logg4*logg4
squrr5 = logg5*logg5
squrr6 = logg6*logg6
squrr7 = logg7*logg7
squrr8 = logg8*logg8
squrr9 = logg9*logg9
avg_logg = (logg+logg1+logg2+logg3+logg4+logg5+logg6+logg7+logg8+logg9)/10
avg_squrr = (squrr+squrr1+squrr2+squrr3+squrr4+squrr5+squrr6+squrr7+squrr8+squrr9)/10
variancee = avg_squrr - (avg_logg*avg_logg)
volatility = math.sqrt(variancee)
range1=math.round(doKdc*volatility,round_preci)
//doKdc=dc
buy_above=math.round(doKdc+(range1 * 0.236),round_preci)
buy_conf=math.round(doKdc+(range1 * 0.382),round_preci)
b_t1=math.round(doKdc+(range1 * 0.5),round_preci)
b_t2=math.round(doKdc+(range1 * 0.618),round_preci)
b_t3=math.round(doKdc+(range1 * 0.786),round_preci)
b_t4=math.round(doKdc+(range1 * 0.888),round_preci)
b_t5=math.round(doKdc+(range1 * 1.236),round_preci)
b_t6=math.round(doKdc+(range1 * 1.618),round_preci)
sell_below=math.round(doKdc-(range1 * 0.236),round_preci)
sell_conf=math.round(doKdc-(range1 * 0.382),round_preci)
s_t1=math.round(doKdc-(range1 * 0.5),round_preci)
s_t2=math.round(doKdc-(range1 * 0.618),round_preci)
s_t3=math.round(doKdc-(range1 * 0.786),round_preci)
s_t4=math.round(doKdc-(range1 * 0.888),round_preci)
s_t5=math.round(doKdc-(range1 * 1.236),round_preci)
s_t6=math.round(doKdc-(range1 * 1.618),round_preci)
sizeOption = input.string(title="VF Text Size",
options= ,
defval="Normal")
txtSize= (sizeOption == "Normal") ? size.small : size.normal
//BUY/Sell confirmation line
// Today's Session Start timestamp
y = year(timenow)
m = month(timenow)
d = dayofmonth(timenow)
// Start & End time for
showLineOnSameDay=input(true, title="Show VF Lines on same Day")
dd=showLineOnSameDay?d:d+1
start = timestamp(y, m, dd, 09, 15)
end = start + 86400000
tom_start = start
tom_end = end
colorLabl=input.color(color.white,"VF Label Text color")
var lbl1 = label.new(na, na, "Buy Conf", color = color(na), style = label.style_label_left,size = txtSize, textcolor = colorLabl )
var lbl2 = label.new(na, na, "Sell Conf", color = color(na), style = label.style_label_left,size = txtSize, textcolor = colorLabl)
var lbl3 = label.new(na, na, "T1", color = color(na), style = label.style_label_left,size = txtSize, textcolor = colorLabl)
var lbl4 = label.new(na, na, "T2", color = color(na), style = label.style_label_left,size = txtSize, textcolor = colorLabl)
var lbl5 = label.new(na, na, "T3", color = color(na), style = label.style_label_left,size = txtSize, textcolor = colorLabl)
var lbl6 = label.new(na, na, "T4", color = color(na), style = label.style_label_left,size = txtSize, textcolor = colorLabl)
var lbl7 = label.new(na, na, "T5", color = color(na), style = label.style_label_left,size = txtSize, textcolor = colorLabl)
var lbl8 = label.new(na, na, "T6", color = color(na), style = label.style_label_left,size = txtSize, textcolor = colorLabl)
var lbl9 = label.new(na, na, "T1", color = color(na), style = label.style_label_left,size = txtSize, textcolor = colorLabl)
var lbl10 = label.new(na, na, "T2", color = color(na), style = label.style_label_left,size = txtSize, textcolor = colorLabl)
var lbl11 = label.new(na, na, "T3", color = color(na), style = label.style_label_left,size = txtSize, textcolor = colorLabl)
var lbl12 = label.new(na, na, "T4", color = color(na), style = label.style_label_left,size = txtSize, textcolor = colorLabl)
var lbl13 = label.new(na, na, "T5", color = color(na), style = label.style_label_left,size = txtSize, textcolor = colorLabl)
var lbl14 = label.new(na, na, "T6", color = color(na), style = label.style_label_left,size = txtSize, textcolor = colorLabl)
var lbl15 = label.new(na, na, "Buy Above", color = color(na), style = label.style_label_left,size = txtSize, textcolor = colorLabl)
var lbl16 = label.new(na, na, "Sell below", color = color(na), style = label.style_label_left,size = txtSize, textcolor = colorLabl)
colorBuy=input.color(color.green,"Buy Above Lines color")
colorSell=input.color(color.red,"Sell Below Lines color")
var lin1 = line.new(na, na, na, na, xloc = xloc.bar_time, style = line.style_solid,color=colorBuy, width = 2)
var lin2 = line.new(na, na, na, na, xloc = xloc.bar_time, style = line.style_solid,color=colorSell, width = 2)
var lin3 = line.new(na, na, na, na, xloc = xloc.bar_time, style = line.style_solid,color=colorBuy)
var lin4 = line.new(na, na, na, na, xloc = xloc.bar_time, style = line.style_solid,color=colorBuy)
var lin5 = line.new(na, na, na, na, xloc = xloc.bar_time, style = line.style_solid,color=colorBuy)
var lin6 = line.new(na, na, na, na, xloc = xloc.bar_time, style = line.style_solid,color=colorBuy)
var lin7 = line.new(na, na, na, na, xloc = xloc.bar_time, style = line.style_solid,color=colorBuy)
var lin8 = line.new(na, na, na, na, xloc = xloc.bar_time, style = line.style_solid,color=colorBuy)
var lin9 = line.new(na, na, na, na, xloc = xloc.bar_time, style = line.style_solid,color=colorSell)
var lin10 = line.new(na, na, na, na, xloc = xloc.bar_time, style = line.style_solid,color=colorSell)
var lin11 = line.new(na, na, na, na, xloc = xloc.bar_time, style = line.style_solid,color=colorSell)
var lin12 = line.new(na, na, na, na, xloc = xloc.bar_time, style = line.style_solid,color=colorSell)
var lin13 = line.new(na, na, na, na, xloc = xloc.bar_time, style = line.style_solid,color=colorSell)
var lin14 = line.new(na, na, na, na, xloc = xloc.bar_time, style = line.style_solid,color=colorSell)
var lin15 = line.new(na, na, na, na, xloc = xloc.bar_time, style = line.style_solid,color=colorBuy)
var lin16 = line.new(na, na, na, na, xloc = xloc.bar_time, style = line.style_solid,color=colorSell)
//Buy_Conf_lvl
line.set_xy1(lin1, tom_start, buy_conf)
line.set_xy2(lin1, tom_end,buy_conf)
label.set_xy(lbl1, bar_index, buy_conf)
//Sell_Conf_lvl
line.set_xy1(lin2, tom_start, sell_conf)
line.set_xy2(lin2, tom_end,sell_conf)
label.set_xy(lbl2, bar_index, sell_conf)
//T1
line.set_xy1(lin3, tom_start, b_t1)
line.set_xy2(lin3, tom_end,b_t1)
label.set_xy(lbl3, bar_index, b_t1)
//T2
line.set_xy1(lin4, tom_start, b_t2)
line.set_xy2(lin4, tom_end,b_t2)
label.set_xy(lbl4, bar_index, b_t2)
//T3
line.set_xy1(lin5, tom_start, b_t3)
line.set_xy2(lin5, tom_end,b_t3)
label.set_xy(lbl5, bar_index, b_t3)
//T4
line.set_xy1(lin6, tom_start, b_t4)
line.set_xy2(lin6, tom_end,b_t4)
label.set_xy(lbl6, bar_index, b_t4)
//T5
line.set_xy1(lin7, tom_start, b_t5)
line.set_xy2(lin7, tom_end,b_t5)
label.set_xy(lbl7, bar_index, b_t5)
//T6
line.set_xy1(lin8, tom_start, b_t6)
line.set_xy2(lin8, tom_end,b_t6)
label.set_xy(lbl8, bar_index, b_t6)
//S1
line.set_xy1(lin9, tom_start, s_t1)
line.set_xy2(lin9, tom_end,s_t1)
label.set_xy(lbl9, bar_index, s_t1)
//S2
line.set_xy1(lin10, tom_start, s_t2)
line.set_xy2(lin10, tom_end,s_t2)
label.set_xy(lbl10, bar_index, s_t2)
//S3
line.set_xy1(lin11, tom_start, s_t3)
line.set_xy2(lin11, tom_end,s_t3)
label.set_xy(lbl11, bar_index, s_t3)
//S4
line.set_xy1(lin12, tom_start, s_t4)
line.set_xy2(lin12, tom_end,s_t4)
label.set_xy(lbl12, bar_index, s_t4)
//S5
line.set_xy1(lin13, tom_start, s_t5)
line.set_xy2(lin13, tom_end,s_t5)
label.set_xy(lbl13, bar_index, s_t5)
//S6
line.set_xy1(lin14, tom_start, s_t6)
line.set_xy2(lin14, tom_end,s_t6)
label.set_xy(lbl14, bar_index, s_t6)
//Buy Above
line.set_xy1(lin15, tom_start, buy_above)
line.set_xy2(lin15, tom_end,buy_above)
label.set_xy(lbl15, bar_index, buy_above)
//Sell Below
line.set_xy1(lin16, tom_start, sell_below)
line.set_xy2(lin16, tom_end,sell_below)
label.set_xy(lbl16, bar_index, sell_below)
color_g=#e6fce8
coor_r=#fce6ea
color_n=#bab8b8
color_rg=#ebe6ea
color_wh=color.white
txt_color_r=#f50a19
txt_color_g=#039458
plotVF = timeframe.period == 'D' or timeframe.period == '120'or timeframe.period == '120' or timeframe.period == '60' or timeframe.period == '15' or timeframe.period == '30'
or timeframe.period == '5' or timeframe.period == '3' or timeframe.period == '180'or timeframe.period == '240'or timeframe.period == '2'
trendingTimes="T4,T5,T6: On trending Times"
NormalTargets="T2,T3: Normal Targets"
tableToolTip="This table works well in a Trending Markets; in sideways market use it as Support and Resistance"
var testTable = table.new(position = position.bottom_right, columns = 9, rows = 3, bgcolor = color.yellow, border_width = 1, border_color=color.white)
if barstate.islast and plotVF and showTable
table.cell(table_id = testTable, column = 1, row = 0, text = "^/v " ,text_size=txtSize,tooltip="Above/Below")
table.cell(table_id = testTable, column = 2, row = 0, text = "Conf ", bgcolor=color.green,text_size=txtSize,tooltip="Confirmation")
table.cell(table_id = testTable, column = 3, row = 0, text = "T1 ", bgcolor=color_wh,text_size=txtSize)
table.cell(table_id = testTable, column = 4, row = 0, text = "T2 ", bgcolor=color.gray,text_size=txtSize,tooltip=NormalTargets)
table.cell(table_id = testTable, column = 5, row = 0, text = "T3 ", bgcolor=color.gray,text_size=txtSize,tooltip=NormalTargets)
table.cell(table_id = testTable, column = 6, row = 0, text = "T4 ", bgcolor=color.green,text_size=txtSize,tooltip=trendingTimes)
table.cell(table_id = testTable, column = 7, row = 0, text = "T5 ", bgcolor=color.green,text_size=txtSize,tooltip=trendingTimes)
table.cell(table_id = testTable, column = 8, row = 0, text = "T6 ", bgcolor=color.green,text_size=txtSize,tooltip=trendingTimes)
table.cell(table_id = testTable, column = 0, row = 0, text = "VF Table", bgcolor=color.white, text_size=txtSize,tooltip=tableToolTip)
table.cell(table_id = testTable, column = 0, row = 1, text = "For Buy Above ", bgcolor=color.green ,text_size=txtSize)
table.cell(table_id = testTable, column = 0, row = 2, text = "For Sell Below ", bgcolor=color.orange ,text_size=txtSize)
table.cell(table_id = testTable, column = 1, row = 1, text = str.tostring(buy_above), bgcolor=color_g ,text_size=txtSize, text_color=txt_color_r)
table.cell(table_id = testTable, column = 2, row = 1, text = str.tostring(buy_conf), bgcolor=color_g,text_size=txtSize, text_color=txt_color_r)
table.cell(table_id = testTable, column = 3, row = 1, text = str.tostring(b_t1), bgcolor=color_wh,text_size=txtSize, text_color=txt_color_r)
table.cell(table_id = testTable, column = 4, row = 1, text = str.tostring(b_t2), bgcolor=color_n,text_size=txtSize, text_color=txt_color_r)
table.cell(table_id = testTable, column = 5, row = 1, text = str.tostring(b_t3), bgcolor=color_n,text_size=txtSize, text_color=txt_color_r)
table.cell(table_id = testTable, column = 6, row = 1, text = str.tostring(b_t4), bgcolor=color_g,text_size=txtSize, text_color=txt_color_r)
table.cell(table_id = testTable, column = 7, row = 1, text = str.tostring(b_t5), bgcolor=color_g,text_size=txtSize, text_color=txt_color_r)
table.cell(table_id = testTable, column = 8, row = 1, text = str.tostring(b_t6), bgcolor=color_g,text_size=txtSize, text_color=txt_color_r)
table.cell(table_id = testTable, column = 1, row = 2, text = str.tostring(sell_below) , bgcolor=coor_r,text_size=txtSize,text_color=txt_color_g)
table.cell(table_id = testTable, column = 2, row = 2, text = str.tostring(sell_conf), bgcolor=coor_r,text_size=txtSize,text_color=txt_color_g)
table.cell(table_id = testTable, column = 3, row = 2, text = str.tostring(s_t1), bgcolor=color_wh,text_size=txtSize,text_color=txt_color_g)
table.cell(table_id = testTable, column = 4, row = 2, text = str.tostring(s_t2), bgcolor=color_rg,text_size=txtSize,text_color=txt_color_g)
table.cell(table_id = testTable, column = 5, row = 2, text = str.tostring(s_t3), bgcolor=color_rg,text_size=txtSize,text_color=txt_color_g)
table.cell(table_id = testTable, column = 6, row = 2, text = str.tostring(s_t4), bgcolor=coor_r,text_size=txtSize,text_color=txt_color_g)
table.cell(table_id = testTable, column = 7, row = 2, text = str.tostring(s_t5), bgcolor=coor_r,text_size=txtSize,text_color=txt_color_g)
table.cell(table_id = testTable, column = 8, row = 2, text = str.tostring(s_t6), bgcolor=coor_r,text_size=txtSize,text_color=txt_color_g)
tf = timeframe.isintraday ? "D" : "W"
d_high = f_secureSecurity(syminfo.tickerid, tf, high )
d_low = f_secureSecurity(syminfo.tickerid, tf, low )
d_close = f_secureSecurity(syminfo.tickerid, tf, close )
pivot = (d_high + d_low + d_close)/3
BC = (d_high + d_low)/2
TC = (pivot - BC) + pivot
R1 = (pivot * 2) - d_low
R2 = pivot + (d_high-d_low)
S1 = (pivot * 2) - d_high
S2 = pivot - (d_high-d_low)
var testPTable = table.new(position = position.top_right, columns = 8, rows = 2, bgcolor = color.yellow, border_width = 1, border_color=color.white)
table.cell(table_id = testPTable, column = 0, row = 0, text = "S2 ",text_size=txtSize )
table.cell(table_id = testPTable, column = 1, row = 0, text = "S1 ",text_size=txtSize )
table.cell(table_id = testPTable, column = 2, row = 0, text = "Pivot" ,text_size=txtSize)
table.cell(table_id = testPTable, column = 3, row = 0, text = "R1 ",text_size=txtSize )
table.cell(table_id = testPTable, column = 4, row = 0, text = "R2",text_size=txtSize )
table.cell(table_id = testPTable, column = 5, row = 0, text = "BC",text_size=txtSize )
table.cell(table_id = testPTable, column = 6, row = 0, text = "TC",text_size=txtSize )
table.cell(table_id = testPTable, column = 7, row = 0, text = "Range",text_size=txtSize )
table.cell(table_id = testPTable, column = 0, row = 1, text = str.tostring(math.round(S2,round_preci)) ,bgcolor=color.green,text_size=txtSize)
table.cell(table_id = testPTable, column = 1, row = 1, text = str.tostring(math.round(S1,round_preci)), bgcolor=color.green,text_size=txtSize )
table.cell(table_id = testPTable, column = 2, row = 1, text = str.tostring(math.round(pivot,round_preci)) ,text_size=txtSize)
table.cell(table_id = testPTable, column = 3, row = 1, text = str.tostring(math.round(R1,round_preci)) , bgcolor=color.orange,text_size=txtSize )
table.cell(table_id = testPTable, column = 4, row = 1, text = str.tostring(math.round(R2,round_preci)) , bgcolor=color.orange,text_size=txtSize )
table.cell(table_id = testPTable, column = 5, row = 1, text = str.tostring(math.round(BC,round_preci)) , bgcolor=color.green,text_size=txtSize )
table.cell(table_id = testPTable, column = 6, row = 1, text = str.tostring(math.round(TC,round_preci)) , bgcolor=color.green,text_size=txtSize )
table.cell(table_id = testPTable, column = 7, row = 1, text = str.tostring(math.round((TC-BC),round_preci+1)) , bgcolor=color.orange,text_size=txtSize )
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Auto trendlines
// Input:
var string GROUP_ATL = "===== Auto trendlines ====="
var int n = input.int(10, title="Fractal Periods", minval=2)
bool upflagDown = true, bool upflagUp0 = true, bool upflagUp1 = true
bool upflagUp2 = true, bool upflagUp3 = true, bool upflagUp4 = true
for i = 1 to n
upflagDown := upflagDown and (high < high )
upflagUp0 := upflagUp0 and (high < high )
upflagUp1 := upflagUp1 and (high <= high and high < high )
upflagUp2 := upflagUp2 and (high <= high and high <= high and high < high )
upflagUp3 := upflagUp3 and (high <= high and high <= high and high <= high and high < high )
upflagUp4 := upflagUp4 and (high <= high and high <= high and high <= high and high <= high and high < high )
flagUp = upflagUp0 or upflagUp1 or upflagUp2 or upflagUp3 or upflagUp4
bool downflagDown = true, bool downflagUp0 = true, bool downflagUp1 = true
bool downflagUp2 = true, bool downflagUp3 = true, bool downflagUp4 = true
for i = 1 to n
downflagDown := downflagDown and (low > low )
downflagUp0 := downflagUp0 and (low > low )
downflagUp1 := downflagUp1 and (low >= low and low > low )
downflagUp2 := downflagUp2 and (low >= low and low >= low and low > low )
downflagUp3 := downflagUp3 and (low >= low and low >= low and low >= low and low > low )
downflagUp4 := downflagUp4 and (low >= low and low >= low and low >= low and low >= low and low > low )
flagDown = downflagUp0 or downflagUp1 or downflagUp2 or downflagUp3 or downflagUp4
bool upfract = upflagDown and flagUp
bool downfract = downflagDown and flagDown
// Input:
var int LINE_WIDTH1 = 2, var string LINE_WIDTH1_STR = "Width 1"
var int LINE_WIDTH2 = 2, var string LINE_WIDTH2_STR = "Width 2"
var string subgroup1 = "recent line"
var color ln_col_recent = input.color(color.new(color.yellow, 0), title="Recent Line", group=GROUP_ATL, inline=subgroup1)
int _lnwidth_recent = switch input.string(LINE_WIDTH1_STR, options= , title="", inline=subgroup1, group=GROUP_ATL)
LINE_WIDTH1_STR => LINE_WIDTH1
LINE_WIDTH2_STR => LINE_WIDTH2
var int lnwidth_recent = _lnwidth_recent
var string subgroup2 = "historical line"
var color ln_col_prev = input.color(color.new(#dee2f1, 50), title="Historical Line", group=GROUP_ATL, inline=subgroup2)
int _lnwidth_prev = switch input.string(LINE_WIDTH1_STR, options= , title="", inline=subgroup2, group=GROUP_ATL)
LINE_WIDTH1_STR => LINE_WIDTH1
LINE_WIDTH2_STR => LINE_WIDTH2
var int lnwidth_prev = _lnwidth_prev
var int max_tl = input.int(1, title="Max pair of lines", maxval=250, minval=1, group=GROUP_ATL)*2
var string _str_extend = input.string("Right", options= , title="Which way to extend lines", group=GROUP_ATL)
var string str_extend = _str_extend == "Both ways" ? extend.both : extend.right
var bool show_crosses = input.bool(false, title="Show crosses", tooltip="Instances when closing price of a bar has crossed lower/upper trendlines", group=GROUP_ATL)
//
// Recent fractals.
var float recent_dn1 = low, var int i_recent_dn1 = bar_index
var float recent_up1 = high, var int i_recent_up1 = bar_index
var float recent_dn2 = low, var int i_recent_dn2 = bar_index
var float recent_up2 = high, var int i_recent_up2 = bar_index
// Array of lines, newest elements inserted to front.
var line arr_ln_up = array.new_line()
var line arr_ln_dn = array.new_line()
// @function : Clean up
// @param arr : either arr_ln_up/arr_ln_dn should be passed into it.
// @returns void : To delete excess lines and assign new color to historical lines.
cleanup(line arr) =>
if array.size(arr) > 1
line.set_color(array.get(arr, 1), ln_col_prev)
line.set_width(array.get(arr, 1), lnwidth_prev)
while array.size(arr) > math.floor(max_tl/2)
line.delete(array.pop(arr))
// Checking for fractals & Drawing trendlines
if downfract
recent_dn2:=recent_dn1
i_recent_dn2:=i_recent_dn1
recent_dn1:=low
i_recent_dn1 := bar_index-n-1
ln_dn = line.new(i_recent_dn2, recent_dn2, i_recent_dn1, recent_dn1, xloc.bar_index, str_extend, color=ln_col_recent, style=line.style_dashed, width=lnwidth_recent)
array.unshift(arr_ln_dn, ln_dn)
cleanup(arr_ln_dn)
if upfract
recent_up2:=recent_up1
i_recent_up2:=i_recent_up1
recent_up1:=high
i_recent_up1 := bar_index-n-1
ln_up = line.new(i_recent_up2, recent_up2, i_recent_up1, recent_up1, xloc.bar_index, str_extend, color=ln_col_recent, style=line.style_dashed, width=lnwidth_recent)
array.unshift(arr_ln_up, ln_up)
cleanup(arr_ln_up)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Finding crosses
// @function : Get slope
// @param int xA , xB: x values of known points A and B
// @param float yA, yB : y values of known points A and B
// @returns float m : Slope value, commonly expressed as rise over run.
get_slope(xA, yA, xB, yB) =>
(yB - yA) / (xB - xA)
// Linear extrapolation
// Solving for price at current x (bar_index), given two pairs of fractals with x values < bar_index.
float m_dn = get_slope(i_recent_dn1, recent_dn1, i_recent_dn2, recent_dn2)
float y_dn = (m_dn * bar_index) + recent_dn1 - (m_dn * i_recent_dn1)
float m_up = get_slope(i_recent_up1, recent_up1, i_recent_up2, recent_up2)
float y_up = (m_up * bar_index) + recent_up1 - (m_up * i_recent_up1)
//
bool crossed_top = ta.cross(close, y_up)
bool crossed_bottom = ta.cross(close, y_dn)
plotshape(show_crosses and crossed_top, title = "Crossed upper trendline", style = shape.xcross, location = location.belowbar, color = color.new(color = color.green, transp = 50), size = size.small)
plotshape(show_crosses and crossed_bottom, title = "Crossed lower trendline", style = shape.xcross, location = location.abovebar, color = color.new(color = color.red, transp = 50), size = size.small)
alertcondition(crossed_top or crossed_bottom, title="Upper/lower trendline crossed", message="Upper/lower trendline crossed")
// Alerts --------------------------------------------------------------------------------------- //
// ---------------------------------------------------------------------------------------------- //
showPSAR = input(title='Show PSAR', defval=false, group = '===== PSAR =====')
showPSAR2 = input(title='Show PSAR2', defval=false, group = '===== PSAR2 =====')
showPSAR3 = input(title='Show PSAR3', defval=false, group = '===== PSAR3 =====')
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////// PARABOLIC SAR //////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
start1 = input.float(0.01,"Start",minval=0.001, group = '===== PSAR =====')
increment = input.float(0.01,"Increament",minval=0.001, group = '===== PSAR =====')
maximum = 0.1
psar_out = ta.sar(start1, increment, maximum)
plot(showPSAR ? psar_out : na, 'ParabolicSAR', style=plot.style_cross, color=color.new(#f32121, 0))
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////// PARABOLIC SAR2 //////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
start2 = input.float(0.02,"Start",minval=0.001, group = '===== PSAR2 =====')
increment2 = input.float(0.02,"Increament",minval=0.001, group = '===== PSAR2 =====')
maximum2 = 0.2
psar_out2 = ta.sar(start2, increment2, maximum2)
plot(showPSAR2 ? psar_out2 : na, 'ParabolicSAR2', style=plot.style_cross, color=color.new(#04dc41, 0))
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////// PARABOLIC SAR3 //////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
start3 = input.float(0.03,"Start",minval=0.001, group = '===== PSAR3 =====')
increment3 = input.float(0.03,"Increament",minval=0.001, group = '===== PSAR3 =====')
maximum3 = 0.3
psar_out3 = ta.sar(start3, increment3, maximum3)
plot(showPSAR3 ? psar_out3 : na, 'ParabolicSAR3', style=plot.style_cross, color=color.new(#efeff6, 0))
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Alerts --------------------------------------------------------------------------------------- //
// ---------------------------------------------------------------------------------------------- //
show3Bc = input(title='Show 3Bc', defval=false, group = '3Bc')
int length = input.int( 8, 'Moving Average Length:')
float src1 = input.source(hl2, 'Source series:')
float deviations = input.float( 2.0, 'Number of Deviations:')
float ma = ta.sma(src1, length)
float sd = ta.stdev(src1, length)
float ma_fall = ta.valuewhen(ma < ma , ma , 0)
float ma_rise = ta.valuewhen(ma > ma , ma , 0)
var float oma = src1
if ma > ma
oma := ma_fall
if ma < ma
oma := ma_rise
float upper = oma + sd * deviations
float lower = oma - sd * deviations
color col_body = ma >= upper ? #9ce0b2 : ma <= lower ? #ca9c88 : ma >= ma ? color.green : color.maroon
color col_bord = color.rgb(70, 70, 70, 40)
plotcandle(oma, upper, lower, ma, '3Bc', col_body, col_bord, bordercolor=col_body)
/////////////////////////////////////////////////////////////////////////////////////////////
showAMA = input(title='Show AMA', defval=true, group = '===== Adaptive MA(TR) =====')
length1 = input(99)
src2 = input(close)
//----
ama = 0.
hh = math.max(math.sign(ta.change(ta.highest(length1))), 0)
ll = math.max(math.sign(ta.change(ta.lowest(length1)) * -1), 0)
tc = math.pow(ta.sma(hh or ll ? 1 : 0, length1), 2)
ama := nz(ama + tc * (src - ama ), src2)
plot(ama, 'Plot2', color.new(#ff1100, 0), 2)
showSMLM= input(title='Show SMLM', defval=true, group = '===== SML Major =====')
// INDICATOR SETTINGS
swing_length = input.int(10, title = 'Swing High/Low Length', group = 'Settings', minval = 1, maxval = 50)
history_of_demand_to_keep = input.int(20, title = 'History To Keep', minval = 5, maxval = 50)
box_width = input.float(2.5, title = 'Supply/Demand Box Width', group = 'Settings', minval = 1, maxval = 10, step = 0.5)
// INDICATOR VISUAL SETTINGS
show_zigzag = input.bool(false, title = 'Show Zig Zag', group = 'Visual Settings', inline = '1')
show_price_action_labels = input.bool(false, title = 'Show Price Action Labels', group = 'Visual Settings', inline = '2')
supply_color = input.color(color.new(#EDEDED,70), title = 'Supply', group = 'Visual Settings', inline = '3')
supply_outline_color = input.color(color.new(color.white,75), title = 'Outline', group = 'Visual Settings', inline = '3')
demand_color = input.color(color.new(#00FFFF,70), title = 'Demand', group = 'Visual Settings', inline = '4')
demand_outline_color = input.color(color.new(color.white,75), title = 'Outline', group = 'Visual Settings', inline = '4')
bos_label_color = input.color(color.white, title = 'BOS Label', group = 'Visual Settings', inline = '5')
poi_label_color = input.color(color.white, title = 'POI Label', group = 'Visual Settings', inline = '7')
swing_type_color = input.color(color.black, title = 'Price Action Label', group = 'Visual Settings', inline = '8')
zigzag_color = input.color(color.new(#000000,0), title = 'Zig Zag', group = 'Visual Settings', inline = '9')
//
//END SETTINGS
//
//
//FUNCTIONS
//
// FUNCTION TO ADD NEW AND REMOVE LAST IN ARRAY
f_array_add_pop(array, new_value_to_add) =>
array.unshift(array, new_value_to_add)
array.pop(array)
// FUNCTION SWING H & L LABELS
f_sh_sl_labels(array, swing_type) =>
var string label_text = na
if swing_type == 1
if array.get(array, 0) >= array.get(array, 1)
label_text := 'HH'
else
label_text := 'LH'
label.new(bar_index - swing_length, array.get(array,0), text = label_text, style=label.style_label_down, textcolor = swing_type_color, color = color.new(swing_type_color, 100), size = size.tiny)
else if swing_type == -1
if array.get(array, 0) >= array.get(array, 1)
label_text := 'HL'
else
label_text := 'LL'
label.new(bar_index - swing_length, array.get(array,0), text = label_text, style=label.style_label_up, textcolor = swing_type_color, color = color.new(swing_type_color, 100), size = size.tiny)
// FUNCTION MAKE SURE SUPPLY ISNT OVERLAPPING
f_check_overlapping(new_poi, box_array, atr) =>
atr_threshold = atr * 2
okay_to_draw = true
for i = 0 to array.size(box_array) - 1
top = box.get_top(array.get(box_array, i))
bottom = box.get_bottom(array.get(box_array, i))
poi = (top + bottom) / 2
upper_boundary = poi + atr_threshold
lower_boundary = poi - atr_threshold
if new_poi >= lower_boundary and new_poi <= upper_boundary
okay_to_draw := false
break
else
okay_to_draw := true
okay_to_draw
// FUNCTION TO DRAW SUPPLY OR DEMAND ZONE
f_supply_demand(value_array, bn_array, box_array, label_array, box_type, atr) =>
atr_buffer = atr * (box_width / 10)
box_left = array.get(bn_array, 0)
box_right = bar_index
var float box_top = 0.00
var float box_bottom = 0.00
var float poi = 0.00
if box_type == 1
box_top := array.get(value_array, 0)
box_bottom := box_top - atr_buffer
poi := (box_top + box_bottom) / 2
else if box_type == -1
box_bottom := array.get(value_array, 0)
box_top := box_bottom + atr_buffer
poi := (box_top + box_bottom) / 2
okay_to_draw = f_check_overlapping(poi, box_array, atr)
// okay_to_draw = true
//delete oldest box, and then create a new box and add it to the array
if box_type == 1 and okay_to_draw
box.delete( array.get(box_array, array.size(box_array) - 1) )
f_array_add_pop(box_array, box.new( left = box_left, top = box_top, right = box_right, bottom = box_bottom, border_color = supply_outline_color,
bgcolor = supply_color, extend = extend.right, text = 'SUPPLY', text_halign = text.align_center, text_valign = text.align_center, text_color = poi_label_color, text_size = size.small, xloc = xloc.bar_index))
ZigZag ProZigZag Pro is a precise market structure indicator that automatically detects two independent ZigZag patterns and highlights breakouts whenever significant highs or lows are breached.
The indicator calculates two separate ZigZag structures in real time. ZigZag1 captures the broader market swings and is ideal for trend or swing trading. ZigZag2 is optional and reacts more quickly – perfect for intraday or scalping setups. Both layers are fully customizable in terms of depth, color, and line width.
What makes this tool especially useful: whenever a previous swing high (for long trades) or swing low (for short trades) is broken, the indicator draws a horizontal breakout line on the chart. This makes it easy to spot structural breakouts and take advantage of potential momentum moves.
ZigZag Pro is designed for traders who rely on clean, rule-based market structure — whether you're trading classic breakouts, smart money concepts, or simply want a clearer view of trend shifts. The visuals are minimal, responsive, and suitable for any timeframe.
Breakout Volume PROBreakout Volume PRO
Real + Projected Volume Detection
This advanced volume indicator detects breakouts based on both actual and projected volume, allowing you to anticipate strong market moves before the current candle closes.
🔹 Key Features:
Volume breakout detection based on configurable moving average and multiplier.
Early signal when projected volume exceeds threshold before candle close.
Distinct coloring for bullish, bearish, and early breakout volume.
Customizable volume threshold area and base average.
Compatible with any timeframe, including daily and intraday.
Colors:
🔵 Blue: Bullish breakout
🔴 Red: Bearish breakout
🟠 Orange: Projected breakout in progress
⚪️ Gray: Normal volume
Perfect for identifying accumulation, distribution, or high-volume events that may precede price breakouts.
OBAD [Türkçe Alarm - Optimize]OBAD indicator helps identify positive and negative trends by combining price changes with volume. It aims to guide the user with visual color support and signal points.
SD Median NUPL-Z🧠 Overview
SD Median NUPL-Z is a trend-following indicator that leverages a normalized version of Bitcoin’s Net Unrealized Profit/Loss (NUPL) metric, filtered through a median-based volatility band. Unlike traditional NUPL which is often used to spot extremes, this indicator is designed to identify sustained directional trends — entering only when both on-chain momentum and price structure align.
🧩 Key Features
Z-Scored NUPL Trend Engine: Normalizes NUPL using rolling mean and standard deviation to create a smoothed trend signal.
Price Structure Filter: Implements a median-based price band to avoid false entries during short-term volatility.
Custom Thresholds: User-defined thresholds determine when the trend signal is strong enough to justify a long or short directional bias.
Directional Candle Coloring: Reinforces current trend regime visually with aqua (bullish) and red (bearish) plots and candles.
Optimized for BTC: Uses Bitcoin’s Market Cap and Realized Cap to construct the NUPL input.
🔍 How It Works
On-Chain Core: NUPL is calculated as the percentage of unrealized profit in the market: (Market Cap - Realized Cap) / Market Cap * 100.
Z-Score Transformation: The raw NUPL value is normalized using a rolling average and standard deviation over a set window (default 134 days), producing the NUPL-Z series.
Median-Based Price Filter: A rolling 50th percentile (median) of price is used alongside its own standard deviation to create upper and lower bounds.
These bounds define a "volatility corridor" around price; the trend signal is only acted upon if price confirms by staying outside these bands.
Signal Logic:
A Long signal is triggered when NUPL-Z rises above the long threshold and price is not below the lower band.
A Short signal is triggered when NUPL-Z falls below the short threshold.
State Variable (CD): Tracks the current market regime, used to control plotting and color changes.
🔁 Use Cases & Applications
Momentum-Based Trend Following: Helps traders align with directional moves backed by both on-chain sentiment and supportive price structure.
Filtered Entry Timing: Reduces premature or noise-based entries by requiring price confirmation before committing to NUPL-based signals.
Best Suited for BTC: This tool is designed specifically around Bitcoin’s on-chain metrics and is not intended for altcoins or low-volume assets.
✅ Conclusion
SD Median NUPL-Z repurposes a traditionally cyclical valuation tool into a modern trend-following signal by combining statistical normalization with dynamic price structure filtering. It offers a more robust way to participate in high-conviction directional trends, reducing the likelihood of entering during short-lived counter moves.
⚠️ Disclaimer
The content provided by this indicator is for educational and informational purposes only. Nothing herein constitutes financial or investment advice. Trading and investing involve risk, including the potential loss of capital. Always backtest and apply risk management suited to your strategy.
[CUSTOM] Valid Pullbacks with pendingTrendFollow the approach of Valid Pullback & Trend indicator, but I have customized to have a pending line waiting for confirmation of the root source code
Draws the pending line to the developing internal high/low
Once a new pivot is confirmed:
- The pendingTrend line is cleared
- The direction is remembered
- No additional blue lines are drawn until the next internal pivot forms in the opposite direction
SNIPER-AVTRADINGPROSNIPER-AVTRADINGPRO Indicator Analysis
This Pine Script indicator combines CCI (Commodity Channel Index) and ADX (Average Directional Index) to identify strong trends and potential reversals through divergences.
Key Components:
CCI Calculation:
Default period: 20
Plotted as colored columns (green above 0, red below 0)
Key levels marked at +200 and -200
ADX Calculation:
Default period: 14
Threshold for strong trend: 20 (configurable)
Divergence Detection:
Uses pivot points to identify potential divergences between price and CCI
Bullish divergence: Lower price lows with higher CCI lows
Bearish divergence: Higher price highs with lower CCI highs
Visual Features:
Background coloring for strong bullish (green) and bearish (red) conditions
Lines drawn to highlight divergences
ADX plotted as a white line
Alert Conditions:
Strong bullish - When CCI > 100 and ADX > threshold
Strong bearish - When CCI < -100 and ADX > threshold
Bullish divergence - When price makes lower low but CCI makes higher low
Bearish divergence - When price makes higher high but CCI makes lower high
The indicator is designed to help spot high-probability trading opportunities by combining momentum (CCI) with trend strength (ADX) and divergence patterns.
Best EMA FinderThis script, Best EMA Finder, is based on the same original logic as the Best SMA Finder I published previously. Although it was not the initial goal of the project, several users asked for an EMA version, so here it is.
The script scans a wide range of Exponential Moving Average (EMA) lengths, from 10 to 500, and identifies the one that historically delivered the most robust performance on the current chart. The choice to stop at 500 is deliberate: beyond that point, EMA curves tend to flatten and converge, adding processing time without meaningful differences in signals or outcomes.
Each EMA is evaluated using a custom robustness score:
Profit Factor × log(Number of Trades) × sqrt(Win Rate)
Only EMA lengths that exceed a user-defined minimum number of trades are considered valid. Among these, the one with the highest robustness score is selected and displayed on the chart.
A table summarizes the results:
- Best EMA length
- Total number of trades
- Profit Factor
- Win Rate
- Robustness Score
You can adjust:
- Strategy type: Long Only or Buy & Sell
- Minimum number of trades required
- Table visibility
This script is designed for analysis and optimization only. It does not execute trades or handle position sizing. Only one open trade per direction is considered at a time.
AMD Setup - Full (Long + Short) ICT ModelICTSNIPERKILLS!
Accumulation, Manipulation, Distribution (AMD) Script!
1. Clarifies Structure: Accumulation, Manipulation, Distribution (AMD)
The script visualizes the AMD framework:
Accumulation → Price ranges inside Initial Balance (IB).
Manipulation → Liquidity sweep above IB High or below IB Low.
Distribution → Market Structure Shift (MSS) confirms a directional move.
This gives you a narrative structure for each session, helping you avoid random trades.
🧠 2. Filters Out Noise with MSS Confirmation
It waits for:
A liquidity sweep (manipulation),
Followed by a market structure shift (MSS),
And then confirms an entry only after a candle closes beyond structure.
This structure:
Reduces false signals,
Improves trade timing,
Helps you align with smart money delivery.
🕘 3. Focuses on the Right Time Window (Initial Balance)
You only engage after the 10:30 AM EST close, once the Initial Balance is formed.This aligns with ICT's focus on:
Killzones (like 9:30–11:00),
Avoiding early overtrading,
Letting the market tip its hand first (through sweeps + MSS).
This timing logic supports discipline and consistency.
🟢🔴 4. Marks Entries with Risk/Reward Guidance
It plots:
AMD SHORT / LONG entries after MSS + candle confirmation,
Basic TP and SL visual markers using a static risk-reward (2:1),
Optional Fair Value Gaps (FVGs) for refinement zones.
While static, these help plan trades visually and frame targets quickly, especially if you're scalping or trading micro futures like MNQ.
📈 5. Alerts You in Real Time
Instead of manually watching:
You'll get alerts when sweeps or MSS setups appear.
You can stay focused during the killzone or walk away and return when signals trigger.
This supports patience and alert-based discipline.
💡
You already:
Use 15M/1M execution,
Wait for ERL or HOD/LOD sweeps,
Look for MSS + CISD,
Trade in killzones only,
Target 50–62–70% Fibs with SMT/FVG confluence.
This script:✅ Automates sweep + MSS detection✅ Plots AMD-based entries visually✅ Simplifies your killzone execution✅ Helps avoid FOMO by filtering setups✅ Keeps your journal entries clean with structure
SMC EASY MONEY//@version=5
indicator("SMC EASY MONEY",overlay = true, max_bars_back = 5000, max_lines_count = 500, max_boxes_count = 500, max_labels_count = 500)
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------- Input Settings
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//----------------------------------------}
//Order Blocks
//----------------------------------------{
show_order_blocks=input.bool(true,"Order Blocks",group = 'Order Blocks', inline = "ob1")
ibull_ob_css = input.color(#5d606b19, '', inline = 'ob1', group = 'Order Blocks')
ibear_ob_css = input.color(#5d606b19, '', inline = 'ob1', group = 'Order Blocks')
ob_type__= input.string('All', '',options = , group = 'Order Blocks',inline = 'ob1')
i_tf_ob = input.timeframe("", "Timeframe", group = 'Order Blocks', inline = "ob2")
mittigation_filt= input.string('Wicks', "Mitigation Method",options = , group = 'Order Blocks',inline = 'ob3')
overlapping_filt= input(true, 'Hide Overlap', inline = 'ob3', group = 'Order Blocks')
max_obs = input.int(4, 'Max OBs', minval = 3, group = 'Order Blocks', inline = 'ob4')
length_extend_ob = input.int(defval = 20,title = "Length", minval = 0, maxval = 500 ,group = 'Order Blocks', inline = "ob4")
ob_extend = input.bool(false,"Extend",group = 'Order Blocks', inline = "ob4")
text_size_ob =input.string("Large", options= , title="Text Size",inline="ob1_t", group="Order Blocks")
text_size_ob_ = text_size_ob == "Small" ? size.tiny : text_size_ob == "Medium" ? size.small : text_size_ob == "Large" ? size.normal : text_size_ob == "Medium2" ? size.normal : text_size_ob == "Large2" ? size.large : size.huge
ob_text_color_1 = input.color(#787b86 , '', inline = 'ob1_t', group = 'Order Blocks')
volume_text = input.bool(true, 'Volume', group='Order Blocks',inline = 'ob1_t')
percent_text = input.bool(true, 'Percentage', group='Order Blocks',inline = 'ob1_t')
show_line_ob = input.string("On", title = "Mid Line", options= , group='Order Blocks',inline='ob1_l')
show_line_ob_1=show_line_ob=="On"?true:false
line_style_ob = input.string("Solid", title = "Line Style", options= , group='Order Blocks',inline='ob1_l')
line_style_ob_1 = line_style_ob=="Solid" ? line.style_solid : line_style_ob=="Dashed" ? line.style_dashed : line.style_dotted
show_order_blocks_mtf=input.bool(false,"MTF Order Blocks",group = 'Order Blocks', inline = "m_ob1")
ibull_ob_css_2 = input.color(#5d606b19, '', inline = 'm_ob1', group = 'Order Blocks')
ibear_ob_css_2 = input.color(#5d606b19, '', inline = 'm_ob1', group = 'Order Blocks')
ob_type__mtf= input.string('All', '',options = , group = 'Order Blocks',inline = 'm_ob1')
i_tf_ob_mtf = input.timeframe("240", "Timeframe", group = 'Order Blocks', inline = "mob2")
mittigation_filt_mtf= input.string('Wicks', "Mitigation Method",options = , group = 'Order Blocks',inline = 'mob3')
overlapping_filt_mtf= input(true, 'Hide Overlap', inline = 'mob3', group = 'Order Blocks')
max_obs_mtf = input.int(4, 'Max OBs', minval = 3, group = 'Order Blocks', inline = "mob4")
length_extend_ob_mtf = input.int(defval = 20,title = "Length", minval = 0, maxval = 500 ,group = 'Order Blocks', inline = "mob4")
ob_extend_mtf = input.bool(false,"Extend",group = 'Order Blocks', inline = "mob4")
v_filter = input.bool(true, 'Internal Bull/Bear Activity', group='Order Blocks',inline = 'volume')
text_size_ob2 =input.string("Medium", options= , title="Text Size",inline="ob2_t", group="Order Blocks")
text_size_ob_2 = text_size_ob2 == "Small" ? size.tiny : text_size_ob2 == "Medium" ? size.small : text_size_ob2== "Large" ? size.normal : text_size_ob2 == "Medium2" ? size.normal : text_size_ob2 == "Large2" ? size.large : size.huge
ob_text_color_2 = input.color(#787b86 , '', inline = 'ob2_t', group = 'Order Blocks')
volume_text_2 = input.bool(true, 'Volume', group='Order Blocks',inline = 'ob2_t')
percent_text_2 = input.bool(true, 'Percentage', group='Order Blocks',inline = 'ob2_t')
show_line_ob2 = input.string("On", title = "Mid Line", options= , group='Order Blocks',inline='ob2_l')
show_line_ob_2=show_line_ob2=="On"?true:false
line_style_ob2 = input.string("Solid", title = "Line Style", options= , group='Order Blocks',inline='ob2_l')
line_style_ob_2 = line_style_ob2=="Solid" ? line.style_solid : line_style_ob2=="Dashed" ? line.style_dashed : line.style_dotted
v_buy = #00dbff4d
v_sell = #e91e634d
tf_s1=i_tf_ob_mtf==''?timeframe.period:i_tf_ob_mtf
timeframe_st=not(str.contains(tf_s1,'S')) and not(str.contains(tf_s1,'D')) and not(str.contains(tf_s1,'W')) and not(str.contains(tf_s1,'M')) ? str.tonumber(tf_s1)>=60? str.tostring(str.tonumber(tf_s1)/60) +"H": tf_s1 +"M" : tf_s1
timeframe1=timeframe_st + ' : '
show_iob = ob_type__=='All' or ob_type__=='Internal' //input(true, 'Internal', inline = 'ob', group = 'Order Blocks')
show_ob = ob_type__=='All' or ob_type__=='External' //input(false, 'External', inline = 'ob', group = 'Order Blocks')
show_iob_mtf = ob_type__mtf=='All' or ob_type__mtf=='Internal' //input(true, 'Internal', inline = 'ob', group = 'Order Blocks')
show_ob_mtf = ob_type__mtf=='All' or ob_type__mtf=='External' //input(false, 'External', inline = 'ob', group = 'Order Blocks')
ob_showlast = 5//input.int(10, 'LookBack', minval = 1, inline = 'ob', group = 'Order Blocks')
iob_showlast = 5//input.int(5, 'LookBack', minval = 1, inline = 'iob', group = 'Order Blocks')
max_width_ob = 3//input.float(3, 'Max OB Width', minval = 0.1,maxval = 3, inline = 'close', group = 'Order Blocks')
max_width_ob:=max_width_ob==3?20:max_width_ob
style = 'Colored'
v_lookback= 10
ob_loockback=10
timediff=(time -time )/100
//----------------------------------------}
//BOS and MSS
//----------------------------------------{
// Constants
color CLEAR = color.rgb(0,0,0,100)
// Inputs
showms=input(true,title="Market Structure ",inline="0",group = "Market Structure")
bosColor1 = input.color(#787b86 , '', group="Market Structure",inline="0")
bosColor2 = input.color(#787b86 , '', group="Market Structure",inline="0")
ms_type =input.string("All", options= , title="", group="Market Structure",inline="0")
show_equal_highlow = input(false, 'Equal Highs & Lows', group = 'Market Structure',inline = 'equilibrium_zone')
eq_bear_color = input.color(#787b86 , '', group="Market Structure",inline="equilibrium_zone")
eq_bull_color = input.color(#787b86 , '', group="Market Structure",inline="equilibrium_zone")
eq_threshold = input.float(0.3, '', minval = 0, maxval = 0.5, step = 0.1, group = 'Market Structure',inline = 'equilibrium_zone')
showSwing = input.bool(false, 'Swing Points', group="Market Structure",inline="3")
swingSize_swing = input.int(10, "Swing Point Period",inline="4", group="Market Structure")
label_sizes_s =input.string("Medium", options= , title="Label Size",inline="4", group="Market Structure")
label_size_buysell_s = label_sizes_s == "Small" ? size.tiny : label_sizes_s == "Medium" ? size.small : label_sizes_s == "Large" ? size.normal : label_sizes_s == "Medium2" ? size.normal : label_sizes_s == "Large2" ? size.large : size.huge
label_size_buysell = label_sizes_s == "Small" ? size.tiny : label_sizes_s == "Medium" ? size.small : label_sizes_s == "Large" ? size.normal : label_sizes_s == "Medium2" ? size.normal : label_sizes_s == "Large2" ? size.large : size.huge
swingColor = input.color(#787b86 , '', group="Market Structure",inline="3")
swingSize = 3
length_eqh = 3
//----------------------------------------}
//Fair Value Gaps (FVG
//----------------------------------------{
show_fvg = input(true, 'Fair Value Gaps (FVG)', group = 'Fair Value Gaps', inline = 'fvg_css')
i_tf = input.timeframe("", "Timeframe", group = 'Fair Value Gaps',inline = 'tf')
max_width_fvg = input.float(1.5, 'Max Width', minval = 0, maxval = 5.0, step = 0.1, group = 'Fair Value Gaps',inline = 'width')
remove_small = input.bool(true,"Filter FVG",group = 'Fair Value Gaps', inline = "width")
mittigation_filt_fvg= input.string('Touch', 'Mitigation Method',options = , group = 'Fair Value Gaps', inline = "mt")
fvg_color_fill = input.bool(true,"Fill",group = 'Fair Value Gaps', inline = "mt")
fvg_shade_fill = input.bool(false,"Shade",group = 'Fair Value Gaps', inline = "mt")
max_fvg = input.int(defval = 4,title = "Max FVG", minval = 0, maxval = 50 ,group = 'Fair Value Gaps', inline = "OS")
length_extend = input.int(defval = 20,title = "Length", minval = 0, maxval = 100 ,group = 'Fair Value Gaps', inline = "OS")
fvg_extend = input.bool(false,"Extend",group = 'Fair Value Gaps', inline = "OS")
i_mtfbearishfvgcolor = input.color(#2962ff , "", group = 'Fair Value Gaps', inline = "fvg_css")
i_mtfbullishfvgcolor = input.color(#c2185b, "", group = 'Fair Value Gaps', inline = "fvg_css")
mid_style = input.string('Solid', ' Style', , group="Fair Value Gaps",inline="mid")
i_midPointColor = input.color(#787b86, "", group = 'Fair Value Gaps',inline="mid")
fvg_extend_B = input.bool(true,"Extend (Current)",group = 'Fair Value Gaps', inline = "mid")
i_bullishfvgcolor = color.new(color.green,100)
i_bearishfvgcolor = color.new(color.green,90)
i_fillByMid = true
i_deleteonfill = true
i_textColor = color.white
i_mtf = "HTF"
i_tfos = 10
i_mtfos = 50
//----------------------------------------}
//Liquidity Levels
//----------------------------------------{
liquidity_level_group = "Liquidity Levels"
currentTF = input.bool(true, title = "Liquidity Levels", group=liquidity_level_group, inline="1")
htfTF = input.timeframe("", title = "Timeframe", inline="1_",group=liquidity_level_group)
leftBars = input.int(8, title = "Pivot Length", group=liquidity_level_group, inline="2")
mitiOptions = input.string("Remove", title = "Mitigated", inline="3", options= , group=liquidity_level_group)
_candleType = input.string("Close", title = "Method", options= , group=liquidity_level_group,inline = '3')
displayLimit = input.int(6, title = "Max Levels", group=liquidity_level_group, inline="4")
length_extend_liq = input.int(defval = 20,title = "Length", minval = 0, maxval = 500 ,group = liquidity_level_group, inline = "4")
extentionMax = input.bool(false, title = "Extend", group=liquidity_level_group, inline="4")
_highLineStyleHTF = "Solid"//input.string("Solid", title = "Line Style", options= , group=liquidity_level_group,inline='5')
highLineStyleHTF = _highLineStyleHTF=="Solid" ? line.style_solid : _highLineStyleHTF=="Dashed" ? line.style_dashed : line.style_dotted
box_width = 2.5//input.float(3.0, title = "Width", group=liquidity_level_group,inline='5', minval = 1, maxval = 10, step = 0.5)
lineWidthHTF=2
lowLineColorHTF = input.color(#00bbf94d, "", group = liquidity_level_group, inline = "1")
highLineColorHTF = input.color(#e91e624d, "", group = liquidity_level_group, inline = "1")
liquidity_text_color = input.color(#ffffff , 'Text Color', inline = '5', group = liquidity_level_group)
highBoxBorderColorHTF = color.new(highLineColorHTF,90)
lowBoxBorderColorHTF = color.new(lowLineColorHTF,90)
displayStyle_liq = "Boxes"//'Lines'
//----------------------------------------}
//Key Levels
//----------------------------------------{
var Show_4H_Levels = input.bool(defval=false, title='4H', group='Key Levels', inline='4H')
Color_4H_Levels = input.color(title='', defval=color.orange, group='Key Levels', inline='4H')
Style_4H_Levels = input.string('Dotted', ' Style', , group="Key Levels",inline="4H")
Text_4H_Levels = input.bool(defval=false, title='Shorten', group='Key Levels', inline='4H')
var Show_Daily_Levels = input.bool(defval=false, title='Daily', group='Key Levels', inline='Daily')
Color_Daily_Levels = input.color(title='', defval=#08bcd4, group='Key Levels', inline='Daily')
Style_Daily_Levels = input.string('Dotted', ' Style', , group="Key Levels",inline="Daily")
Text_Daily_Levels = input.bool(defval=false, title='Shorten', group='Key Levels', inline='Daily')
var Show_Monday_Levels = input.bool(defval=false, title='Monday', group='Key Levels', inline='Monday')
Color_Monday_Levels = input.color(title='', defval=color.white, group='Key Levels', inline='Monday')
Style_Monday_Levels = input.string('Dotted', ' Style', , group="Key Levels",inline="Monday")
Text_Monday_Levels = input.bool(defval=false, title='Shorten', group='Key Levels', inline='Monday')
var Show_Weekly_Levels = input.bool(defval=false, title='Weekly', group='Key Levels', inline='Weekly')
WeeklyColor = input.color(title='', defval=#fffcbc, group='Key Levels', inline='Weekly')
Weekly_style = input.string('Dotted', ' Style', , group="Key Levels",inline="Weekly")
WeeklyTextType = input.bool(defval=false, title='Shorten', group='Key Levels', inline='Weekly')
var Show_Monthly_Levels = input.bool(defval=false, title='Monthly', group='Key Levels', inline='Monthly')
MonthlyColor = input.color(title='', defval=#098c30, group='Key Levels', inline='Monthly')
Monthly_style = input.string('Dotted', ' Style', , group="Key Levels",inline="Monthly")
MonthlyTextType = input.bool(defval=false, title='Shorten', group='Key Levels', inline='Monthly')
var Show_Quaterly_Levels = input.bool(defval=false, title='Quarterly', group='Key Levels', inline='Quarterly')
quarterlyColor = input.color(title='', defval=#bcffd0, group='Key Levels', inline='Quarterly')
Quaterly_style = input.string('Dotted', ' Style', , group="Key Levels",inline="Quarterly")
QuarterlyTextType = input.bool(defval=false, title='Shorten', group='Key Levels', inline='Quarterly')
var Show_Yearly_Levels = input.bool(defval=false, title='Yearly', group='Key Levels', inline='Yearly')
YearlyColor = input.color(title='', defval=#ffbcdb, group='Key Levels', inline='Yearly')
Yearly_style = input.string('Dotted', ' Style', , group="Key Levels",inline="Yearly")
YearlyTextType = input.bool(defval=false, title='Shorten', group='Key Levels', inline='Yearly')
labelsize = input.string(defval='Medium', title='Text Size', options= ,group = "Key Levels", inline='H')
var pdhtext = Text_Daily_Levels ? 'PDH' : 'Prev Day High'
var pdltext = Text_Daily_Levels ? 'PDL' : 'Prev Day Low'
var dotext = Text_Daily_Levels ? 'DO' : 'Daily Open'
var pdmtext = Text_Daily_Levels ? 'PDM' : 'Prev Day Mid'
var pwhtext = WeeklyTextType ? 'PWH' : 'Prev Week High'
var pwltext = WeeklyTextType ? 'PWL' : 'Prev Week Low'
var wotext = WeeklyTextType ? 'WO' : 'Weekly Open'
var pwmtext = WeeklyTextType ? 'PWM' : 'Prev Week Mid'
var pmhtext = MonthlyTextType ? 'PMH' : 'Prev Month High'
var pmltext = MonthlyTextType ? 'PML' : 'Prev Month Low'
var motext = MonthlyTextType ? 'MO' : 'Monthly Open'
var pmmtext = MonthlyTextType ? 'PMM' : 'Prev Month Mid'
var pqhtext = QuarterlyTextType ? 'PQH' : 'Prev Quarter High'
var pqltext = QuarterlyTextType ? 'PQL' : 'Prev Quarter Low'
var qotext = QuarterlyTextType ? 'QO' : 'Quarterly Open'
var pqmtext = QuarterlyTextType ? 'PQM' : 'Prev Quarter Mid'
var cyhtext = YearlyTextType ? 'CYH' : 'Current Year High'
var cyltext = YearlyTextType ? 'CYL' : 'Current Year Low'
var yotext = YearlyTextType ? 'YO' : 'Yearly Open'
var cymtext = YearlyTextType ? 'CYM' : 'Current Year Mid'
var pihtext = Text_4H_Levels ? 'P-4H-H' : 'Prev 4H High'
var piltext = Text_4H_Levels ? 'P-4H-L' : 'Prev 4H Low'
var iotext = Text_4H_Levels ? '4H-O' : '4H Open'
var pimtext = Text_4H_Levels ? 'P-4H-M' : 'Prev 4H Mid'
var pmonhtext = Text_Monday_Levels ? 'MDAY-H' : 'Monday High'
var pmonltext = Text_Monday_Levels ? 'MDAY-L' : 'Monday Low'
var pmonmtext = Text_Monday_Levels ? 'MDAY-M' : 'Monday Mid'
displayStyle = 'Standard'
distanceright = 25
radistance = 250
linesize = 'Small'
linestyle = 'Solid'
var untested_monday = false
//----------------------------------------}
//Session Levels
//----------------------------------------{
var is_londonrange_enabled = input.bool(defval=false, title='London', group='Session Levels', inline='london')
var london_OC = input.bool(defval=true, title='O/C', group='Session Levels', inline='london')
var london_HL = input.bool(defval=true, title='H/L', group='Session Levels', inline='london')
var is_usrange_enabled = input.bool(defval=false, title='New York', group='Session Levels', inline='US')
var us_OC = input.bool(defval=true, title='O/C', group='Session Levels', inline='US')
var us_HL = input.bool(defval=true, title='H/L', group='Session Levels', inline='US')
var is_tokyorange_enabled = input.bool(defval=false, title='Tokyo', group='Session Levels', inline='asia')
var asia_OC = input.bool(defval=true, title='O/C', group='Session Levels', inline='asia')
var asia_HL = input.bool(defval=true, title='H/L', group='Session Levels', inline='asia')
SessionTextType = false//input.bool(defval=false, title='ShortHand', group='Sessions', inline='FXColor')
Londont = "0800-1600"
USt = "1400-2100"
Asiat = "0000-0900"
LondonColor = input.color(title='', defval=color.white, group='Session Levels', inline='london')
USColor = input.color(title='', defval=color.white, group='Session Levels', inline='US')
AsiaColor = input.color(title='', defval=color.white, group='Session Levels', inline='asia')
Short_text_London = input.bool(defval=false, title='Shorten', group='Session Levels', inline='london')
Short_text_NY = input.bool(defval=false, title='Shorten', group='Session Levels', inline='US')
Short_text_TKY = input.bool(defval=false, title='Shorten', group='Session Levels', inline='asia')
var London_high_text = Short_text_London ? 'Lon-H' : 'London High'
var London_low_text = Short_text_London ? 'Lon-L' : 'London Low'
var London_open_text = Short_text_London ? 'Lon-O' : 'London Open'
var NY_high_text = Short_text_NY ? 'NY-H' : 'New York High'
var NY_low_text = Short_text_NY ? 'NY-L' : 'New York Low'
var NY_open_text = Short_text_NY ? 'NY-O' : 'New York Open'
var Tokyo_high_text = Short_text_TKY ? 'TK-H' : 'Tokyo High'
var Tokyo_low_text = Short_text_TKY ? 'TK-L' : 'Tokyo Low'
var Tokyo_open_text = Short_text_TKY ? 'TK-O' : 'Tokyo Open'
//-----------------------------------------------------------------------------}
//Global variables
//-----------------------------------------------------------------------------{
color transparent = #ffffff00
length = 50
is_newbar(res) =>
t = time(res)
not na(t) and (na(t ) or t > t )
Show_MS(x, y, txt, css, dashed, down, lbl_size)=>
label.new(int(math.avg(x, bar_index)), y, txt, color = transparent, textcolor = css, style = down ? label.style_label_down : label.style_label_up, size = lbl_size)
line.new(x, y, bar_index, y, color = css, style = dashed ? line.style_dashed : line.style_solid)
f_barssince(_cond, _count) =>
_barssince = bar_index - ta.valuewhen(_cond, bar_index, _count)
_barssince
//Swings detection/measurements
calculate_swing_points(length)=>
var prev = 0
prev := high > ta.highest(length) ? 0 : low < ta.lowest(length) ? 1 : prev
t = prev == 0 and prev != 0 ? high : 0
b = prev == 1 and prev != 1 ? low : 0
var t_MS = 0, var int_t_MS = 0
var internal_y_up = 0., var internal_x_up = 0, var internal_y_dn = 0., var internal_x_dn = 0
var y_up = 0., var x_up = 0 , var y_dn = 0., var x_dn = 0
var crossed_up = true, var crossed_down = true
var internal_up_broke = true, var internal_dn_broke = true
var up_trailing = high, var down_trailing = low
var up_trailing_x = 0, var down_trailing_x = 0
var high_text = '', var low_text = ''
bullish_OB_Break = false
bearish_OB_Break = false
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------- Market Structure
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
bosConfType = 'Candle High'//input.string('Candle Close', 'BOS Confirmation', , tooltip='Choose whether candle close/wick above previous swing point counts as a BOS.')
MSS = true//input.bool(false, 'Show MSS', tooltip='Renames the first counter t_MS BOS to MSS' )
// showSwing = false//input.bool(true, 'Show Swing Points', tooltip='Show or hide HH, LH, HL, LL')
// Functions
lineStyle(x) =>
switch x
'Solid' => line.style_solid
'Dashed' => line.style_dashed
'Dotted' => line.style_dotted
pivot_high_found = ta.pivothigh(high, swingSize_swing, swingSize_swing)
pivot_low_found = ta.pivotlow(low, swingSize_swing, swingSize_swing)
var float prevHigh_s = na,var float prevLow_s = na,var int prevHighIndex_s = na,var int prevLowIndex_s = na
bool higher_highs = false, bool lower_highs = false, bool higher_lows = false, bool lower_lows = false
var int prevSwing_s = 0
if not na(pivot_high_found)
if pivot_high_found >= prevHigh_s
higher_highs := true
prevSwing_s := 2
else
lower_highs := true
prevSwing_s := 1
prevHigh_s := pivot_high_found
prevHighIndex_s := bar_index - swingSize_swing
if not na(pivot_low_found)
if pivot_low_found >= prevLow_s
higher_lows := true
prevSwing_s := -1
else
lower_lows := true
prevSwing_s := -2
prevLow_s := pivot_low_found
prevLowIndex_s := bar_index - swingSize_swing
if higher_highs and showSwing
label.new(bar_index - swingSize_swing, pivot_high_found, 'HH', color=CLEAR, style=label.style_label_down, textcolor=swingColor,size = label_size_buysell_s)
if lower_highs and showSwing
label.new(bar_index - swingSize_swing, pivot_high_found, 'LH', color=CLEAR, style=label.style_label_down, textcolor=swingColor,size = label_size_buysell_s)
if higher_lows and showSwing
label.new(bar_index - swingSize_swing, pivot_low_found, 'HL', color=CLEAR, style=label.style_label_up, textcolor=swingColor,size = label_size_buysell_s)
if lower_lows and showSwing
label.new(bar_index - swingSize_swing, pivot_low_found, 'LL', color=CLEAR, style=label.style_label_up, textcolor=swingColor,size = label_size_buysell_s)
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------- Fair Value Gaps
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// }
// ———————————————————— Global data {
//Using current bar data for HTF highs and lows instead of security to prevent future leaking
var htfH = open
var htfL = open
if close > htfH
htfH:= close
if close < htfL
htfL := close
//Security Data, used for HTF Bar Data reference
sClose = request.security(ticker.standard(syminfo.tickerid), i_tf, close , barmerge.gaps_off, barmerge.lookahead_on)
sHighP2 = request.security(ticker.standard(syminfo.tickerid), i_tf, high , barmerge.gaps_off, barmerge.lookahead_on)
sLowP2 = request.security(ticker.standard(syminfo.tickerid), i_tf, low , barmerge.gaps_off, barmerge.lookahead_on)
sOpen = request.security(ticker.standard(syminfo.tickerid), i_tf, open , barmerge.gaps_off, barmerge.lookahead_on)
sBar = request.security(ticker.standard(syminfo.tickerid), i_tf, bar_index, barmerge.gaps_off, barmerge.lookahead_on)
// }
//var keyword can be used to hold data in memory, with pinescript all data is lost including variables unless the var keyword is used to preserve this data
var bullishgapholder = array.new_box(0)
var bearishgapholder = array.new_box(0)
var bullishgapholder_fill = array.new_box(0)
var bearishgapholder_fill = array.new_box(0)
var bullish_high_holder = array.new_line(0)
var bearish_high_holder = array.new_line(0)
var bullish_low_holder = array.new_line(0)
var bearish_low_holder = array.new_line(0)
var bullishmidholder = array.new_line(0)
var bearishmidholder = array.new_line(0)
var bullishlabelholder = array.new_label(0)
var bearishlabelholder = array.new_label(0)
var transparentcolor = color.new(color.white,100)
var fvg_apper=false
var fvg_break=false
fvg_apper:=false
fvg_break:=false
// ———————————————————— Functions {
//function paramaters best declared with '_' this helps defer from variables in the function scope declaration and elsewhere e.g. close => _close
create_fvg_func(_upperlimit,_lowerlimit,_midlimit,_bar,_boxholder,_boxholder_fill,_midholder,_highholder,_lowholder,_labelholder,_boxcolor,_mtfboxcolor, _htf)=>
timeholder = str.tostring(i_tf)
offset = i_mtfos
boxbgcolor = _mtfboxcolor
bg_color = color.new(_mtfboxcolor,90)
if _htf == false
timeholder := str.tostring(timeframe.period)
offset := i_tfos
boxbgcolor := _boxcolor
array.push(_boxholder,box.new(_bar,_upperlimit,_bar+(timediff)*length_extend,_lowerlimit,border_color=fvg_color_fill? bg_color : na,bgcolor = fvg_color_fill? bg_color : na, extend = fvg_extend ? extend.right:extend.none,xloc = xloc.bar_time,text='',text_color=#787b86,text_halign=text.align_right,text_size=size.small))
array.push(_boxholder_fill,box.new(_bar,_upperlimit,_bar+(timediff)*length_extend,_lowerlimit,border_color=fvg_color_fill? bg_color : na ,bgcolor = fvg_color_fill? bg_color : na, extend = fvg_extend ? extend.right:extend.none,xloc = xloc.bar_time))
array.push(_midholder,line.new(_bar,(_lowerlimit+_upperlimit)/2.0,_bar+(timediff)*length_extend,_midlimit,color = i_midPointColor, extend = fvg_extend ? extend.right:extend.none,style=lineStyle(mid_style),width=1,xloc = xloc.bar_time))
array.push(_lowholder,line.new(_bar,_lowerlimit,_bar+(timediff)*length_extend,_lowerlimit,color = i_fillByMid?boxbgcolor:na, extend = fvg_extend ? extend.right:extend.none,width=1,xloc = xloc.bar_time))
array.push(_highholder,line.new(_bar,_upperlimit,_bar+(timediff)*length_extend,_upperlimit,color = i_fillByMid?boxbgcolor:na, extend = fvg_extend ? extend.right:extend.none,width=1,xloc = xloc.bar_time))
//checks for gap between current candle and 2 previous candle e.g. low of current candle and high of the candle before last, this is the fair value gap.
check_fvg_func(_close,_high,_highp2,_low,_lowp2,_open,_bar,_htf)=>
gap=0
thold_ = (ta.highest(_high,300) - ta.lowest(_low,300)) * math.max(max_width_fvg, 0.1) / 100.
if _open > _close // red
if _lowp2>_high
if not(remove_small) or math.abs(_lowp2 -_high) > thold_
upperlimit = _high//_close - (_close - _lowp2 )
lowerlimit = _lowp2//_close - (_close-_high)
midlimit = lowerlimit + ((upperlimit - lowerlimit) / 2.)
gap:=1
create_fvg_func(upperlimit,lowerlimit,midlimit,_bar,bullishgapholder,bullishgapholder_fill,bullishmidholder,bullish_high_holder,bullish_low_holder,bullishlabelholder,i_bullishfvgcolor,i_mtfbullishfvgcolor,_htf)
else
if _low>_highp2
if not(remove_small) or math.abs(_low - _highp2) > thold_
upperlimit = _low//_close - (_close-_low)
lowerlimit = _highp2//_close- (_close - _highp2),
midlimit = lowerlimit + ((upperlimit - lowerlimit) / 2.)
gap:=-1
create_fvg_func(upperlimit,lowerlimit,midlimit,_bar,bearishgapholder,bearishgapholder_fill,bearishmidholder,bearish_high_holder,bearish_low_holder,bearishlabelholder,i_bearishfvgcolor,i_mtfbearishfvgcolor,_htf)
gap
//Used to remove the gap from its relevant array as a result of it being filled.
delete_fvg_func(_currentgap,_currentgap_fill,_i,_boxholder,_boxholder_fill,_midholder,_highholder,_lowholder,_labelholder)=>
array.remove(_boxholder,_i)
array.remove(_boxholder_fill,_i)
currentmid=array.get(_midholder,_i)
currenthigh=array.get(_highholder,_i)
currentlow=array.get(_lowholder,_i)
array.remove(_midholder,_i)
array.remove(_highholder,_i)
array.remove(_lowholder,_i)
if i_deleteonfill
line.delete(currentmid)
line.delete(currenthigh)
line.delete(currentlow)
else
line.set_extend(currentmid, extend.none)
line.set_x2(currentmid,time)
line.set_extend(currenthigh, extend.none)
line.set_x2(currenthigh,time)
line.set_extend(currentlow, extend.none)
line.set_x2(currentlow,time)
if i_deleteonfill
box.delete(_currentgap)
box.delete(_currentgap_fill)
else
box.set_extend(_currentgap,extend.none)
box.set_right(_currentgap,time)
//checks if gap has been filled either by 0.5 fill (i_fillByMid) or SHRINKS the gap to reflect the true value gap left.
validate_fvg_func(_high,_low)=>
fvg_removed=0
if array.size(bullishgapholder) > 0
for i = array.size(bullishgapholder)-1 to 0
if fvg_extend_B
currentgap_fill = array.get(bullishgapholder_fill,i)
currentgap = array.get(bullishgapholder,i)
cmid = array.get(bullishmidholder,i)
chigh = array.get(bullish_high_holder,i)
clow = array.get(bullish_low_holder,i)
line.set_x2(cmid,timenow+(timediff)*length_extend)
line.set_x2(chigh,timenow+(timediff)*length_extend)
line.set_x2(clow,timenow+(timediff)*length_extend)
box.set_right(currentgap_fill,timenow+(timediff)*length_extend)
box.set_right(currentgap,timenow+(timediff)*length_extend)
if mittigation_filt_fvg=='Touch'
currentgap_fill = array.get(bullishgapholder_fill,i)
currentgap = array.get(bullishgapholder,i)
currentmid = array.get(bullishmidholder,i)
currenthigh = array.get(bullish_high_holder,i)
currentlow = array.get(bullish_low_holder,i)
currenttop = box.get_top(currentgap)
if high > currenttop
fvg_removed:=1
delete_fvg_func(currentgap,currentgap_fill,i,bullishgapholder,bullishgapholder_fill,bullishmidholder,bullish_high_holder,bullish_low_holder,bullishlabelholder)
if mittigation_filt_fvg=='Wicks'
currentgap_fill = array.get(bullishgapholder_fill,i)
currentgap = array.get(bullishgapholder,i)
currentmid = array.get(bullishmidholder,i)
currenthigh = array.get(bullish_high_holder,i)
currentlow = array.get(bullish_low_holder,i)
currenttop = box.get_bottom(currentgap)
currentbottom = box.get_top(currentgap_fill)
if high > currentbottom and fvg_shade_fill
currentgap_f = array.get(bullishgapholder_fill,i)
cur_bottom=box.get_bottom(currentgap_f)
_bottom=box.get_bottom(currentgap)
if _bottom==cur_bottom
box.set_bottom(currentgap_f,high)
else
box.set_bottom(currentgap_f,math.max(cur_bottom,high))
box.set_bgcolor(currentgap_f,#787b865e)
if high > currenttop
fvg_removed:=1
delete_fvg_func(currentgap,currentgap_fill,i,bullishgapholder,bullishgapholder_fill,bullishmidholder,bullish_high_holder,bullish_low_holder,bullishlabelholder)
if mittigation_filt_fvg=='Close'
currentgap_fill = array.get(bullishgapholder_fill,i)
currentgap = array.get(bullishgapholder,i)
currentmid = array.get(bullishmidholder,i)
currenthigh = array.get(bullish_high_holder,i)
currentlow = array.get(bullish_low_holder,i)
currenttop = box.get_bottom(currentgap)
currentbottom = box.get_top(currentgap_fill)
if high > currentbottom and fvg_shade_fill
currentgap_f = array.get(bullishgapholder_fill,i)
cur_bottom=box.get_bottom(currentgap_f)
_bottom=box.get_bottom(currentgap)
if _bottom==cur_bottom
box.set_bottom(currentgap_f,high)
else
box.set_bottom(currentgap_f,math.max(cur_bottom,high))
box.set_bgcolor(currentgap_f,#787b865e)
if close > currenttop
fvg_removed:=1
delete_fvg_func(currentgap,currentgap_fill,i,bullishgapholder,bullishgapholder_fill,bullishmidholder,bullish_high_holder,bullish_low_holder,bullishlabelholder)
if mittigation_filt_fvg=='Average'
currentgap_fill = array.get(bullishgapholder_fill,i)
currentgap = array.get(bullishgapholder,i)
currentmid = array.get(bullishmidholder,i)
currenthigh = array.get(bullish_high_holder,i)
currentlow = array.get(bullish_low_holder,i)
currenttop = line.get_y1(currentmid)
currentbottom = box.get_top(currentgap_fill)
if high > currentbottom and fvg_shade_fill
currentgap_f = array.get(bullishgapholder_fill,i)
cur_bottom=box.get_bottom(currentgap_f)
_bottom=box.get_bottom(currentgap)
if _bottom==cur_bottom
box.set_bottom(currentgap_f,high)
else
box.set_bottom(currentgap_f,math.max(cur_bottom,high))
box.set_bgcolor(currentgap_f,#787b865e)
if high > currenttop
fvg_removed:=1
delete_fvg_func(currentgap,currentgap_fill,i,bullishgapholder,bullishgapholder_fill,bullishmidholder,bullish_high_holder,bullish_low_holder,bullishlabelholder)
if array.size(bearishgapholder) > 0
for i = array.size(bearishgapholder)-1 to 0
if fvg_extend_B
currentgap_fill = array.get(bearishgapholder_fill,i)
currentgap = array.get(bearishgapholder,i)
cmid = array.get(bearishmidholder,i)
chigh = array.get(bearish_high_holder,i)
clow = array.get(bearish_low_holder,i)
line.set_x2(cmid,timenow+(timediff)*length_extend)
line.set_x2(chigh,timenow+(timediff)*length_extend)
line.set_x2(clow,timenow+(timediff)*length_extend)
box.set_right(currentgap_fill,timenow+(timediff)*length_extend)
box.set_right(currentgap,timenow+(timediff)*length_extend)
if mittigation_filt_fvg=='Touch'
currentgap_fill = array.get(bearishgapholder_fill,i)
currentgap = array.get(bearishgapholder,i)
currenttop = box.get_top(currentgap)
currentmid = array.get(bearishmidholder,i)
currenthigh = array.get(bearish_high_holder,i)
currentlow = array.get(bearish_low_holder,i)
if low < currenttop
fvg_removed:=-1
delete_fvg_func(currentgap,currentgap_fill,i,bearishgapholder,bearishgapholder_fill,bearishmidholder,bearish_high_holder,bearish_low_holder,bearishlabelholder)
if mittigation_filt_fvg=='Wicks'
currentgap_fill = array.get(bearishgapholder_fill,i)
currentgap = array.get(bearishgapholder,i)
currenttop = box.get_bottom(currentgap)
currentmid = array.get(bearishmidholder,i)
currenthigh = array.get(bearish_high_holder,i)
currentlow = array.get(bearish_low_holder,i)
currentbottom = box.get_top(currentgap_fill)
if low < currentbottom and fvg_shade_fill
currentgap_f = array.get(bearishgapholder_fill,i)
cur_bottom=box.get_bottom(currentgap_f)
_bottom=box.get_bottom(currentgap)
if _bottom==cur_bottom
box.set_bottom(currentgap_f,low)
else
box.set_bottom(currentgap_f,math.min(cur_bottom,low))
box.set_bgcolor(currentgap_f,#787b865e)
if low < currenttop
fvg_removed:=-1
delete_fvg_func(currentgap,currentgap_fill,i,bearishgapholder,bearishgapholder_fill,bearishmidholder,bearish_high_holder,bearish_low_holder,bearishlabelholder)
if mittigation_filt_fvg=='Close'
currentgap_fill = array.get(bearishgapholder_fill,i)
currentgap = array.get(bearishgapholder,i)
currenttop = box.get_bottom(currentgap)
currentmid = array.get(bearishmidholder,i)
currenthigh = array.get(bearish_high_holder,i)
currentlow = array.get(bearish_low_holder,i)
currentbottom = box.get_top(currentgap_fill)
if low < currentbottom and fvg_shade_fill
currentgap_f = array.get(bearishgapholder_fill,i)
cur_bottom=box.get_bottom(currentgap_f)
_bottom=box.get_bottom(currentgap)
if _bottom==cur_bottom
box.set_bottom(currentgap_f,low)
else
box.set_bottom(currentgap_f,math.min(cur_bottom,low))
box.set_bgcolor(currentgap_f,#787b865e)
if close < currenttop
fvg_removed:=-1
delete_fvg_func(currentgap,currentgap_fill,i,bearishgapholder,bearishgapholder_fill,bearishmidholder,bearish_high_holder,bearish_low_holder,bearishlabelholder)
if mittigation_filt_fvg=='Average'
currentgap_fill = array.get(bearishgapholder_fill,i)
currentgap = array.get(bearishgapholder,i)
currentmid = array.get(bearishmidholder,i)
currenttop = line.get_y1(currentmid)
currenthigh = array.get(bearish_high_holder,i)
currentlow = array.get(bearish_low_holder,i)
currentbottom = box.get_top(currentgap_fill)
if low < currentbottom and fvg_shade_fill
currentgap_f = array.get(bearishgapholder_fill,i)
cur_bottom=box.get_bottom(currentgap_f)
_bottom=box.get_bottom(currentgap)
if _bottom==cur_bottom
box.set_bottom(currentgap_f,low)
else
box.set_bottom(currentgap_f,math.min(cur_bottom,low))
box.set_bgcolor(currentgap_f,#787b865e)
if low < currenttop
fvg_removed:=-1
delete_fvg_func(currentgap,currentgap_fill,i,bearishgapholder,bearishgapholder_fill,bearishmidholder,bearish_high_holder,bearish_low_holder,bearishlabelholder)
fvg_removed
// pine provided function to determine a new bar
if is_newbar(i_tf)
htfH := high
htfL := low
// }
fvg_gap=0
// User Input, allow MTF data calculations
if is_newbar(i_tf) and (i_mtf == "Current + HTF" or i_mtf == "HTF") and show_fvg and barstate.isconfirmed
fvg_gap:=check_fvg_func(sClose,htfH,sHighP2,htfL,sLowP2,sOpen,time ,true)
alertcondition(fvg_gap==1,"Bullish FVG","Bullish FVG Found Ez-SMC")
alertcondition(fvg_gap==-1,"Bearish FVG","Bearish FVG Found Ez-SMC")
fvg_removed=validate_fvg_func(high,low)
alertcondition(fvg_removed==1,"Bullish FVG Break","Bullish FVG Broken Ez-SMC")
alertcondition(fvg_removed==-1,"Bearish FVG Break","Bearish FVG Broken Ez-SMC")
if array.size(bullishgapholder) > max_fvg
d_box=array.shift(bullishgapholder)
box.delete(d_box)
if array.size(bullishgapholder_fill) > max_fvg
d_box=array.shift(bullishgapholder_fill)
box.delete(d_box)
if array.size(bullishmidholder) > max_fvg
d_line=array.shift(bullishmidholder)
line.delete(d_line)
if array.size(bullish_high_holder) > max_fvg
d_line=array.shift(bullish_high_holder)
line.delete(d_line)
if array.size(bullish_low_holder) > max_fvg
d_line=array.shift(bullish_low_holder)
line.delete(d_line)
if array.size(bearishgapholder) > max_fvg
d_box_=array.shift(bearishgapholder)
box.delete(d_box_)
if array.size(bearishgapholder_fill) > max_fvg
d_box_=array.shift(bearishgapholder_fill)
box.delete(d_box_)
if array.size(bearishmidholder) > max_fvg
d_line_=array.shift(bearishmidholder)
line.delete(d_line_)
if array.size(bearish_high_holder) > max_fvg
d_line_=array.shift(bearish_high_holder)
line.delete(d_line_)
if array.size(bearish_low_holder) > max_fvg
d_line_=array.shift(bearish_low_holder)
line.delete(d_line_)
n=bar_index
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------- Liquidity Levels
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// --
highLineColor = highLineColorHTF//input.color(#1f4ef5, "High Line ", group = liquidity_level_group, inline = "1")
lowLineColor = lowLineColorHTF//input.color(#fd441c, "Low Line", group = liquidity_level_group, inline = "1")
highBoxBgColor = highLineColorHTF//input.color(color.new(#1f4ef5, 80), "High Box Bg ", group = liquidity_level_group, inline = "2")
highBoxBorderColor = highBoxBorderColorHTF//input.color(color.new(#1f4ef5, 80), "Box Border", group = liquidity_level_group, inline = "2")
lowBoxBgColor = lowLineColorHTF//input.color(color.new(#fd441c, 80), "Low Box Bg ", group = liquidity_level_group, inline = "3")
lowBoxBorderColor = lowBoxBorderColorHTF//input.color(color.new(#fd441c, 80), "Box Border", group = liquidity_level_group, inline = "3")
atr_liq = ta.atr(300)
float thold_liq = atr_liq * (box_width / 10)
// --
// --
// --
// ----------------------------------------------------
// Functions
// ----------------------------------------------------
tf_multi(tf) =>
ts = timeframe.in_seconds("")
htfs = timeframe.in_seconds(tf)
htfs/ts
display_limit_line(_array) =>
if array.size(_array) > displayLimit/2
a = array.shift(_array)
line.delete(a)
display_limit_box(_array) =>
if array.size(_array) > displayLimit/2
a = array.shift(_array)
box.delete(a)
remove_mitigated_lines(_array, _hl) =>
m = false
if array.size(_array) > 0
for i = array.size(_array) - 1 to 0 by 1
l = array.get(_array, i)
hh = _candleType == "Close" ? close : high
ll = _candleType == "Close" ? close : low
if _hl == "High" and hh > line.get_y1(l)
array.remove(_array, i)
if mitiOptions == "Show"
line.new(line.get_x1(l),line.get_y1(l),time,line.get_y1(l), xloc=xloc.bar_time, color = highLineColorHTF, style=highLineStyleHTF, width = lineWidthHTF)
line.delete(l)
m := true
if _hl == "Low" and ll < line.get_y1(l)
array.remove(_array, i)
if mitiOptions == "Show"
line.new(line.get_x1(l),line.get_y1(l),time,line.get_y1(l), xloc=xloc.bar_time, color = lowLineColorHTF, style=highLineStyleHTF, width = lineWidthHTF)
line.delete(l)
m := true
display_limit_line(_array)
m
remove_mitigated_boxes(_array, _hl) =>
m = false
if array.size(_array) > 0
for i = array.size(_array) - 1 to 0 by 1
l = array.get(_array, i)
hh = _candleType == "Close" ? close : high
ll = _candleType == "Close" ? close : low
if _hl == "High" and hh > box.get_top(l)
array.remove(_array, i)
if mitiOptions == "Show"
box.new(box.get_left(l),box.get_top(l),time,box.get_bottom(l), xloc=xloc.bar_time, bgcolor = color.new(highBoxBgColor, 90), border_color = color.new(highBoxBorderColor, 90), border_style = highLineStyleHTF)
box.delete(l)
m := true
if _hl == "Low" and ll < box.get_top(l)
array.remove(_array, i)
if mitiOptions == "Show"
box.new(box.get_left(l),box.get_top(l),time,box.get_bottom(l), xloc=xloc.bar_time, bgcolor = color.new(lowBoxBgColor, 90), border_color = color.new(lowBoxBorderColor, 90), border_style = highLineStyleHTF)
box.delete(l)
m := true
display_limit_box(_array)
m
extend_line_to_current(lineArray) =>
if array.size(lineArray) > 0
for i = array.size(lineArray) - 1 to 0 by 1
l = array.get(lineArray, i)
timeExt = timenow + ((timediff)*length_extend_liq)
line.set_x2(l, timeExt)
extend_box_to_current(boxArray) =>
if array.size(boxArray) > 0
for i = array.size(boxArray) - 1 to 0 by 1
b = array.get(boxArray, i)
timeExt = timenow + ((timediff)*length_extend_liq)
box.set_right(b, timeExt)
// ----------------------------------------------------
// Higher TimeFrame
// ----------------------------------------------------
// Varibles
// Lines
var highLineArrayHTF = array.new_line()
var lowLineArrayHTF = array.new_line()
// Boxes
var highBoxArrayHTF = array.new_box()
var lowBoxArrayHTF = array.new_box()
// Get HTF
= request.security(syminfo.tickerid, htfTF, )
// Pivots
pivotHighHTF = ta.pivothigh(_high, leftBars*tf_multi(htfTF), leftBars+tf_multi(htfTF))
pivotLowHTF = ta.pivotlow(_low, leftBars*tf_multi(htfTF), leftBars+tf_multi(htfTF))
if currentTF
timeExt = time+((time -time )*10)
dis = leftBars+tf_multi(htfTF)
if pivotHighHTF
if displayStyle_liq == "Lines"
array.push(highLineArrayHTF, line.new(_time ,_high ,_time ,_high ,color = highLineColorHTF, style=highLineStyleHTF, xloc=xloc.bar_time, extend=extentionMax?extend.right:extend.none, width = lineWidthHTF))
else
y1 = _high -thold_liq//math.max(_open , _close )
array.push(highBoxArrayHTF, box.new(_time ,_high ,_time ,y1,bgcolor = highLineColorHTF, border_color=highBoxBorderColorHTF, xloc=xloc.bar_time, border_style = highLineStyleHTF, extend=extentionMax?extend.right:extend.none, border_width = lineWidthHTF,text="BUY SIDE $$$",text_halign = text.align_center,text_color = liquidity_text_color,text_size = size.small))
if pivotLowHTF
if displayStyle_liq == "Lines"
array.push(lowLineArrayHTF, line.new(_time ,_low ,_time ,_low ,color = lowLineColorHTF, style=highLineStyleHTF, xloc=xloc.bar_time, extend=extentionMax?extend.right:extend.none, width = lineWidthHTF))
else
y1 = _low +thold_liq//math.min(_open , _close )
array.push(lowBoxArrayHTF, box.new(_time ,_low ,_time ,y1,bgcolor = lowLineColorHTF, border_color=lowBoxBorderColorHTF, xloc=xloc.bar_time, border_style = highLineStyleHTF, extend=extentionMax?extend.right:extend.none, border_width = lineWidthHTF,text="SELL SIDE $$$",text_halign = text.align_center,text_color = liquidity_text_color,text_size = size.small))
// ----------------------------------------------------
// Run Functions
// ----------------------------------------------------
highLineAlertHTF = remove_mitigated_lines(highLineArrayHTF, "High")
lowLineAlertHTF = remove_mitigated_lines(lowLineArrayHTF, "Low")
highBoxAlertHTF = remove_mitigated_boxes(highBoxArrayHTF, "High")
lowBoxAlertHTF = remove_mitigated_boxes(lowBoxArrayHTF, "Low")
extend_line_to_current(highLineArrayHTF)
extend_line_to_current(lowLineArrayHTF)
extend_box_to_current(highBoxArrayHTF)
extend_box_to_current(lowBoxArrayHTF)
// Alerts
alertcondition(pivotHighHTF, "High Liquidity Level", "High Liquidity Level Found Ez-SMC")
alertcondition(pivotLowHTF, "Low Liquidity Level", "Low Liquidity Level Found Ez-SMC")
alertcondition(highLineAlertHTF or highBoxAlertHTF, "High Liquidity Level Break", "High Liquidity Level Broken Ez-SMC")
alertcondition(lowLineAlertHTF or lowBoxAlertHTF, "Low Liquidity Level Break", "Low Liquidity Level Broken Ez-SMC")
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------- Key Levels
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
var monday_time = time
var monday_high = high
var monday_low = low
cdailyh_open = request.security(syminfo.tickerid, 'D', high, lookahead=barmerge.lookahead_on)
cdailyl_open = request.security(syminfo.tickerid, 'D', low, lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, 'D', , lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, 'D', [time , high ], lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, 'D', [time , low ], lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, 'W', , lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, 'W', [time , high ], lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, 'W', [time , low ], lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, 'M', , lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, 'M', [time , high ], lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, 'M', [time , low ], lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, '240', , lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, '240', [time , high ], lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, '240', [time , low ], lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, '3M', , lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, '3M', [time , high ], lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, '3M', [time , low ], lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, '12M', , lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, '12M', , lookahead=barmerge.lookahead_on)
= request.security(syminfo.tickerid, '12M', , lookahead=barmerge.lookahead_on)
if weekly_time != weekly_time
untested_monday := false
untested_monday
if Show_Monday_Levels == true and untested_monday == false
untested_monday := true
monday_time := daily_time
monday_high := cdailyh_open
monday_low := cdailyl_open
monday_low
linewidthint = 1
if linesize == 'Small'
linewidthint := 1
linewidthint
if linesize == 'Medium'
linewidthint := 2
linewidthint
if linesize == 'Large'
linewidthint := 3
linewidthint
var linewidth_def = linewidthint
fontsize = size.small
if labelsize == 'Small'
fontsize := size.small
fontsize
if labelsize == 'Medium'
fontsize := size.normal
fontsize
if labelsize == 'Large'
fontsize := size.large
fontsize
linestyles = line.style_solid
if linestyle == 'Dashed'
linestyles := line.style_dashed
linestyles
if linestyle == 'Dotted'
linestyles := line.style_dotted
linestyles
var DEFAULT_LABEL_SIZE = fontsize
var DEFAULT_LABEL_STYLE = label.style_none
var Rigth_Def = distanceright
var arr_price = array.new_float(0)
var arr_label = array.new_label(0)
Combine_Levels(arr_price, arr_label, currentprice, currentlabel, currentcolor) =>
if array.includes(arr_price, currentprice)
whichindex = array.indexof(arr_price, currentprice)
labelhold = array.get(arr_label, whichindex)
whichtext = label.get_text(labelhold)
label.set_text(labelhold, label.get_text(currentlabel) + ' / ' + whichtext)
label.set_text(currentlabel, '')
label.set_textcolor(labelhold, currentcolor)
else
array.push(arr_price, currentprice)
array.push(arr_label, currentlabel)
extend_to_current(bars) =>
timenow + (time - time ) * bars
if barstate.islast
arr_price := array.new_float(0)
arr_label := array.new_label(0)
if Show_4H_Levels
limit_4H_right = extend_to_current(Rigth_Def)
intrah_limit_right = extend_to_current(Rigth_Def)
intral_limit_right = extend_to_current(Rigth_Def)
var line_4H = line.new(x1=intra_time, x2=limit_4H_right, y1=intra_open, y2=intra_open, color=Color_4H_Levels, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Style_4H_Levels))
var label_4H = label.new(x=limit_4H_right, y=intra_open, text=iotext, style=DEFAULT_LABEL_STYLE, textcolor=Color_4H_Levels, size=DEFAULT_LABEL_SIZE, xloc=xloc.bar_time)
var intrah_line = line.new(x1=intrah_time, x2=intrah_limit_right, y1=intrah_open, y2=intrah_open, color=Color_4H_Levels, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Style_4H_Levels))
var intrah_label = label.new(x=intrah_limit_right, y=intrah_open, text=pihtext, style=DEFAULT_LABEL_STYLE, textcolor=Color_4H_Levels, size=DEFAULT_LABEL_SIZE, xloc=xloc.bar_time)
var intral_line = line.new(x1=intral_time, x2=intral_limit_right, y1=intral_open, y2=intral_open, color=Color_4H_Levels, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Style_4H_Levels))
var intral_label = label.new(x=intral_limit_right, y=intral_open, text=piltext, style=DEFAULT_LABEL_STYLE, textcolor=Color_4H_Levels, size=DEFAULT_LABEL_SIZE, xloc=xloc.bar_time)
label.set_text(label_4H, iotext)
line.set_xy1(line_4H,intra_time,intra_open)
line.set_xy2(line_4H,limit_4H_right,intra_open)
label.set_xy(label_4H,limit_4H_right,intra_open)
line.set_xy1(intrah_line,intrah_time,intrah_open)
line.set_xy2(intrah_line,intrah_limit_right,intrah_open)
label.set_xy(intrah_label,intrah_limit_right,intrah_open)
label.set_text(intrah_label, pihtext)
line.set_x1(intral_line, intral_time)
line.set_x2(intral_line, intral_limit_right)
line.set_y1(intral_line, intral_open)
line.set_y2(intral_line, intral_open)
label.set_x(intral_label, intral_limit_right)
label.set_y(intral_label, intral_open)
label.set_text(intral_label, piltext)
Combine_Levels(arr_price, arr_label, intra_open, label_4H, Color_4H_Levels)
Combine_Levels(arr_price, arr_label, intrah_open, intrah_label, Color_4H_Levels)
Combine_Levels(arr_price, arr_label, intral_open, intral_label, Color_4H_Levels)
if Show_Monday_Levels
monday_limit_right = extend_to_current(Rigth_Def)
mondaym_limit_right = extend_to_current(Rigth_Def)
mondaym_open = (monday_high + monday_low) / 2
var monday_line = line.new(x1=monday_time, x2=monday_limit_right, y1=monday_high, y2=monday_high, color=Color_Monday_Levels, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Style_Monday_Levels))
var monday_label = label.new(x=monday_limit_right, y=monday_high, text=pmonhtext, style=DEFAULT_LABEL_STYLE, textcolor=Color_Monday_Levels, size=DEFAULT_LABEL_SIZE, xloc=xloc.bar_time)
var mondaym_line = line.new(x1=monday_time, x2=mondaym_limit_right, y1=mondaym_open, y2=mondaym_open, color=Color_Monday_Levels, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Style_Monday_Levels))
var mondaym_label = label.new(x=mondaym_limit_right, y=mondaym_open, text=pmonmtext, style=DEFAULT_LABEL_STYLE, textcolor=Color_Monday_Levels, size=DEFAULT_LABEL_SIZE, xloc=xloc.bar_time)
var monday_low_line = line.new(x1=monday_time, x2=monday_limit_right, y1=monday_low, y2=monday_low, color=Color_Monday_Levels, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Style_Monday_Levels))
var monday_low_label = label.new(x=monday_limit_right, y=monday_low, text=pmonltext, style=DEFAULT_LABEL_STYLE, textcolor=Color_Monday_Levels, size=DEFAULT_LABEL_SIZE, xloc=xloc.bar_time)
line.set_x1(monday_line, monday_time)
line.set_x2(monday_line, monday_limit_right)
line.set_y1(monday_line, monday_high)
line.set_y2(monday_line, monday_high)
label.set_x(monday_label, monday_limit_right)
label.set_y(monday_label, monday_high)
label.set_text(monday_label, pmonhtext)
line.set_x1(monday_low_line, monday_time)
line.set_x2(monday_low_line, monday_limit_right)
line.set_y1(monday_low_line, monday_low)
line.set_y2(monday_low_line, monday_low)
label.set_x(monday_low_label, monday_limit_right)
label.set_y(monday_low_label, monday_low)
label.set_text(monday_low_label, pmonltext)
line.set_x1(mondaym_line, monday_time)
line.set_x2(mondaym_line, mondaym_limit_right)
line.set_y1(mondaym_line, mondaym_open)
line.set_y2(mondaym_line, mondaym_open)
label.set_x(mondaym_label, mondaym_limit_right)
label.set_y(mondaym_label, mondaym_open)
label.set_text(mondaym_label, pmonmtext)
Combine_Levels(arr_price, arr_label, monday_high, monday_label, Color_Monday_Levels)
Combine_Levels(arr_price, arr_label, monday_low, monday_low_label, Color_Monday_Levels)
Combine_Levels(arr_price, arr_label, mondaym_open, mondaym_label, Color_Monday_Levels)
if Show_Daily_Levels
daily_limit_right = extend_to_current(Rigth_Def)
dailyh_limit_right = extend_to_current(Rigth_Def)
dailyl_limit_right = extend_to_current(Rigth_Def)
var daily_line = line.new(x1=daily_time, x2=daily_limit_right, y1=daily_open, y2=daily_open, color=Color_Daily_Levels, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Style_Daily_Levels))
var daily_label = label.new(x=daily_limit_right, y=daily_open, text=dotext, style=DEFAULT_LABEL_STYLE, textcolor=Color_Daily_Levels, size=DEFAULT_LABEL_SIZE, xloc=xloc.bar_time)
var dailyh_line = line.new(x1=dailyh_time, x2=dailyh_limit_right, y1=dailyh_open, y2=dailyh_open, color=Color_Daily_Levels, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Style_Daily_Levels))
var dailyh_label = label.new(x=dailyh_limit_right, y=dailyh_open, text=pdhtext, style=DEFAULT_LABEL_STYLE, textcolor=Color_Daily_Levels, size=DEFAULT_LABEL_SIZE, xloc=xloc.bar_time)
var dailyl_line = line.new(x1=dailyl_time, x2=dailyl_limit_right, y1=dailyl_open, y2=dailyl_open, color=Color_Daily_Levels, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Style_Daily_Levels))
var dailyl_label = label.new(x=dailyl_limit_right, y=dailyl_open, text=pdltext, style=DEFAULT_LABEL_STYLE, textcolor=Color_Daily_Levels, size=DEFAULT_LABEL_SIZE, xloc=xloc.bar_time)
line.set_x1(daily_line, daily_time)
line.set_x2(daily_line, daily_limit_right)
line.set_y1(daily_line, daily_open)
line.set_y2(daily_line, daily_open)
label.set_x(daily_label, daily_limit_right)
label.set_y(daily_label, daily_open)
label.set_text(daily_label, dotext)
line.set_x1(dailyh_line, dailyh_time)
line.set_x2(dailyh_line, dailyh_limit_right)
line.set_y1(dailyh_line, dailyh_open)
line.set_y2(dailyh_line, dailyh_open)
label.set_x(dailyh_label, dailyh_limit_right)
label.set_y(dailyh_label, dailyh_open)
label.set_text(dailyh_label, pdhtext)
line.set_x1(dailyl_line, dailyl_time)
line.set_x2(dailyl_line, dailyl_limit_right)
line.set_y1(dailyl_line, dailyl_open)
line.set_y2(dailyl_line, dailyl_open)
label.set_x(dailyl_label, dailyl_limit_right)
label.set_y(dailyl_label, dailyl_open)
label.set_text(dailyl_label, pdltext)
Combine_Levels(arr_price, arr_label, daily_open, daily_label, Color_Daily_Levels)
Combine_Levels(arr_price, arr_label, dailyh_open, dailyh_label, Color_Daily_Levels)
Combine_Levels(arr_price, arr_label, dailyl_open, dailyl_label, Color_Daily_Levels)
if Show_Weekly_Levels
weekly_limit_right = extend_to_current(Rigth_Def)
weeklyh_limit_right = extend_to_current(Rigth_Def)
weeklyl_limit_right = extend_to_current(Rigth_Def)
cweekly_time = weekly_time
var weekly_line = line.new(x1=cweekly_time, x2=weekly_limit_right, y1=weekly_open, y2=weekly_open, color=WeeklyColor, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Weekly_style))
var weekly_label = label.new(x=weekly_limit_right, y=weekly_open, text=wotext, style=DEFAULT_LABEL_STYLE, textcolor=WeeklyColor, size=DEFAULT_LABEL_SIZE, xloc=xloc.bar_time)
var weeklyh_line = line.new(x1=weeklyh_time, x2=weeklyh_limit_right, y1=weeklyh_open, y2=weeklyh_open, color=WeeklyColor, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Weekly_style))
var weeklyh_label = label.new(x=weeklyh_limit_right, y=weeklyh_open, text=pwhtext, style=DEFAULT_LABEL_STYLE, textcolor=WeeklyColor, size=DEFAULT_LABEL_SIZE, xloc=xloc.bar_time)
var weeklyl_line = line.new(x1=weeklyl_time, x2=weeklyl_limit_right, y1=weekly_open, y2=weekly_open, color=WeeklyColor, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Weekly_style))
var weeklyl_label = label.new(x=weeklyl_limit_right, y=weeklyl_open, text=pwltext, style=DEFAULT_LABEL_STYLE, textcolor=WeeklyColor, size=DEFAULT_LABEL_SIZE, xloc=xloc.bar_time)
line.set_x1(weekly_line, cweekly_time)
line.set_x2(weekly_line, weekly_limit_right)
line.set_y1(weekly_line, weekly_open)
line.set_y2(weekly_line, weekly_open)
label.set_x(weekly_label, weekly_limit_right)
label.set_y(weekly_label, weekly_open)
label.set_text(weekly_label, wotext)
line.set_x1(weeklyh_line, weeklyh_time)
line.set_x2(weeklyh_line, weeklyh_limit_right)
line.set_y1(weeklyh_line, weeklyh_open)
line.set_y2(weeklyh_line, weeklyh_open)
label.set_x(weeklyh_label, weeklyh_limit_right)
label.set_y(weeklyh_label, weeklyh_open)
label.set_text(weeklyh_label, pwhtext)
line.set_x1(weeklyl_line, weeklyl_time)
line.set_x2(weeklyl_line, weeklyl_limit_right)
line.set_y1(weeklyl_line, weeklyl_open)
line.set_y2(weeklyl_line, weeklyl_open)
label.set_x(weeklyl_label, weeklyl_limit_right)
label.set_y(weeklyl_label, weeklyl_open)
label.set_text(weeklyl_label, pwltext)
Combine_Levels(arr_price, arr_label, weekly_open, weekly_label, WeeklyColor)
Combine_Levels(arr_price, arr_label, weeklyh_open, weeklyh_label, WeeklyColor)
Combine_Levels(arr_price, arr_label, weeklyl_open, weeklyl_label, WeeklyColor)
if Show_Yearly_Levels
yearlyl_limit_right = extend_to_current(Rigth_Def)
yearlyh_limit_right = extend_to_current(Rigth_Def)
yearly_limit_right = extend_to_current(Rigth_Def)
var yearlyl_line = line.new(x1=yearlyl_time, x2=yearlyl_limit_right, y1=yearlyl_open, y2=yearlyl_open, color=YearlyColor, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Yearly_style))
var yearlyl_label = label.new(x=yearlyl_limit_right, y=yearlyl_open, text=cyltext, style=DEFAULT_LABEL_STYLE, textcolor=YearlyColor, size=DEFAULT_LABEL_SIZE, xloc=xloc.bar_time)
var yearlyh_line = line.new(x1=yearlyh_time, x2=yearlyh_limit_right, y1=yearlyh_open, y2=yearlyh_open, color=YearlyColor, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Yearly_style))
var yearlyh_label = label.new(x=yearlyh_limit_right, y=yearlyh_open, text=cyhtext, style=DEFAULT_LABEL_STYLE, textcolor=YearlyColor, size=DEFAULT_LABEL_SIZE, xloc=xloc.bar_time)
var yearly_line = line.new(x1=yearly_time, x2=yearly_limit_right, y1=yearly_open, y2=yearly_open, color=YearlyColor, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Yearly_style))
var yearly_label = label.new(x=yearly_limit_right, y=yearly_open, text=yotext, style=DEFAULT_LABEL_STYLE, textcolor=YearlyColor, size=DEFAULT_LABEL_SIZE, xloc=xloc.bar_time)
line.set_x1(yearlyl_line, yearlyl_time)
line.set_x2(yearlyl_line, yearlyl_limit_right)
line.set_y1(yearlyl_line, yearlyl_open)
line.set_y2(yearlyl_line, yearlyl_open)
label.set_x(yearlyl_label, yearlyl_limit_right)
label.set_y(yearlyl_label, yearlyl_open)
label.set_text(yearlyl_label, cyltext)
line.set_x1(yearlyh_line, yearlyh_time)
line.set_x2(yearlyh_line, yearlyh_limit_right)
line.set_y1(yearlyh_line, yearlyh_open)
line.set_y2(yearlyh_line, yearlyh_open)
label.set_x(yearlyh_label, yearlyh_limit_right)
label.set_y(yearlyh_label, yearlyh_open)
label.set_text(yearlyh_label, cyhtext)
line.set_x1(yearly_line, yearly_time)
line.set_x2(yearly_line, yearly_limit_right)
line.set_y1(yearly_line, yearly_open)
line.set_y2(yearly_line, yearly_open)
label.set_x(yearly_label, yearly_limit_right)
label.set_y(yearly_label, yearly_open)
label.set_text(yearly_label, yotext)
Combine_Levels(arr_price, arr_label, yearlyh_open, yearlyh_label, YearlyColor)
Combine_Levels(arr_price, arr_label, yearlyl_open, yearlyl_label, YearlyColor)
Combine_Levels(arr_price, arr_label, yearly_open, yearly_label, YearlyColor)
if Show_Quaterly_Levels
quarterly_limit_right = extend_to_current(Rigth_Def)
quarterlyh_limit_right = extend_to_current(Rigth_Def)
quarterlyl_limit_right = extend_to_current(Rigth_Def)
var quarterly_line = line.new(x1=quarterly_time, x2=quarterly_limit_right, y1=quarterly_open, y2=quarterly_open, color=quarterlyColor, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Quaterly_style))
var quarterly_label = label.new(x=quarterly_limit_right, y=quarterly_open, text=qotext, style=DEFAULT_LABEL_STYLE, textcolor=quarterlyColor, size=DEFAULT_LABEL_SIZE, xloc=xloc.bar_time)
var quarterlyh_line = line.new(x1=quarterlyh_time, x2=quarterlyh_limit_right, y1=quarterlyh_open, y2=quarterlyh_open, color=quarterlyColor, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Quaterly_style))
var quarterlyh_label = label.new(x=quarterlyh_limit_right, y=quarterlyh_open, text=pqhtext, style=DEFAULT_LABEL_STYLE, textcolor=quarterlyColor, size=DEFAULT_LABEL_SIZE, xloc=xloc.bar_time)
var quarterlyl_line = line.new(x1=quarterlyl_time, x2=quarterlyl_limit_right, y1=quarterlyl_open, y2=quarterlyl_open, color=quarterlyColor, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Quaterly_style))
var quarterlyl_label = label.new(x=quarterlyl_limit_right, y=quarterlyl_open, text=pqltext, style=DEFAULT_LABEL_STYLE, textcolor=quarterlyColor, size=DEFAULT_LABEL_SIZE, xloc=xloc.bar_time)
line.set_x1(quarterly_line, quarterly_time)
line.set_x2(quarterly_line, quarterly_limit_right)
line.set_y1(quarterly_line, quarterly_open)
line.set_y2(quarterly_line, quarterly_open)
label.set_x(quarterly_label, quarterly_limit_right)
label.set_y(quarterly_label, quarterly_open)
label.set_text(quarterly_label, qotext)
line.set_x1(quarterlyh_line, quarterlyh_time)
line.set_x2(quarterlyh_line, quarterlyh_limit_right)
line.set_y1(quarterlyh_line, quarterlyh_open)
line.set_y2(quarterlyh_line, quarterlyh_open)
label.set_x(quarterlyh_label, quarterlyh_limit_right)
label.set_y(quarterlyh_label, quarterlyh_open)
label.set_text(quarterlyh_label, pqhtext)
line.set_x1(quarterlyl_line, quarterlyl_time)
line.set_x2(quarterlyl_line, quarterlyl_limit_right)
line.set_y1(quarterlyl_l
Higher Time Frame Support/ResistanceCustom support and resistance indicator modified with 5 different timeframes
Steph's Shadow Supply v2Detects HTF supply and demand zones by wick extremes, draws colored boxes that auto‑extend until broken (then dashed), and alerts on creation and price touches—no clutter, pure zone visuals.
(Based off of Steph's "Shadow" supply and demand strategy.)