Text
Text
//@version=5
// @achirameegasthanne
indicator("MG Algo", overlay=true)
enableDashboard = input(true, "Enable Dashboard", group="DASHBOARD SETTINGS")
locationDashboard = input.string("Top right", "Location", ["Top right", "Top left",
"Middle right", "Middle left", "Bottom right", "Bottom left"], group="DASHBOARD
SETTINGS")
sizeDashboard = input.string("Tiny", "Size", ["Tiny", "Small", "Normal"],
group="DASHBOARD SETTINGS")
colorBackground = input(#2a2e39, "Bg color", group="DASHBOARD SETTINGS")
colorFrame = input(#2A2E39, "Frame color", group="DASHBOARD SETTINGS")
colorBorder = input(#363A45, "Border color", group="DASHBOARD SETTINGS")
showSignals = input(true, "Show signals", group="BUY AND SELL SIGNALS
SETTINGS")
strategy = input.string("Normal", "Strategy", ["Normal", "Confirmed",
"Trend scalper"], group="BUY AND SELL SIGNALS SETTINGS")
sensitivity = input.float(2.6, "Sensitivity", 0.1, step=0.1, group="BUY AND
SELL SIGNALS SETTINGS")
consSignalsFilter = input(false, "Consolidation signals filter", group="BUY AND
SELL SIGNALS SETTINGS")
smartSignalsOnly = input(false, "Smart signals only", group="BUY AND SELL SIGNALS
SETTINGS")
candleColors = input(true, "Candle colors", group="BUY AND SELL SIGNALS
SETTINGS")
momentumCandles = input(true, "Momentum candles", group="BUY AND SELL SIGNALS
SETTINGS")
dynamicStopLess = input(true, "Dynamic stopless", group="BUY AND SELL SIGNALS
SETTINGS")
highVolSignals = input(false, "High volume signals only", group="BUY AND SELL
SIGNALS SETTINGS")
enableTrailingSL = input(false, "Enable trailing stop-loss", group="RISK
MANAGEMENT SETTINGS")
usePercSL = input(false, "% Trailing sl", inline="2", group="RISK
MANAGEMENT SETTINGS")
percTrailingSL = input.float(1, "", 0, step=0.1, inline="2", group="RISK
MANAGEMENT SETTINGS")
enableSwings = input(false, "Enable Swing High's & Swing's Low's", inline="3",
group="RISK MANAGEMENT SETTINGS")
periodSwings = input.int(10, "", 2, inline="3", group="RISK MANAGEMENT
SETTINGS")
enableTpSlAreas = input(false, "Enable take profit/stop-loss areas", group="RISK
MANAGEMENT SETTINGS")
useTP1 = input(true, "", inline="4", group="RISK MANAGEMENT SETTINGS")
multTP1 = input.float(1, "TP 1", 0, inline="4", group="RISK MANAGEMENT
SETTINGS")
useTP2 = input(true, "", inline="5", group="RISK MANAGEMENT SETTINGS")
multTP2 = input.float(2, "TP 2", 0, inline="5", group="RISK MANAGEMENT
SETTINGS")
useTP3 = input(true, "", inline="6", group="RISK MANAGEMENT SETTINGS")
multTP3 = input.float(3, "TP 3", 0, inline="6", group="RISK MANAGEMENT
SETTINGS")
tpLabels = input(true, "Take profit labels", group="RISK MANAGEMENT
SETTINGS")
showTrendCloud = input(true, "Show Trend cloud", group="TREND CLOUD SETTINGS")
periodTrendCloud = input.string("New", "Trend cloud period", ["Short term", "Long
term", "New"], group="TREND CLOUD SETTINGS")
signalsTrendCloud = input(false, "Trend only signals", group="TREND SETTINGS")
fastTrendCloud = input(false, "Fast trend cloud", group="TREND SETTINGS")
len = input.int(14, minval=1, title='Tralling Stop Length', group="TREND SETTINGS")
filt2 = input.string("Smooth", options = ["No Filter", "Smooth", "Zero
Lag"], title = "", group="Kernel Regression", inline="k", tooltip="Select Kernel
Regression type from the dropdown box.")
type2 = input.string("Rational Quadratic", options = ["Rational
Quadratic", "Gaussian", "Periodic", "Locally Periodic"], title="", group="Kernel
Regression", inline="k", tooltip="Select Kernel Regression type from the dropdown
box.")
h2 = input.int(8, 'Lookback Window', minval=3, tooltip='The number
of bars used for the estimation. Recommended range: 3-50', group="Kernel
Regression", inline="k")
r2 = input.float(1., 'Weighting', step=0.25, tooltip='Relative
weighting of time frames. Recommended range: 0.25-25', group="Kernel Regression",
inline="kernel2")
x2 = input.int(20, "Level", tooltip='Bar index on which to start
regression. Recommended range: 2-25', group="Kernel Regression", inline="kernel2")
lag2 = input.int(2, "Lag", tooltip="Lag for crossover detection.
Recommended range: 1-2", inline='kernel2', group='Kernel Regression')
fastTrendCloudLen = input.int(120, "Fast trend cloud", 2, group="TREND CLOUD
SETTINGS")
amplitude = input(title='Amplitude', defval=3, group="TREND CLOUD
SETTINGS")
channelDeviation = input(title='Channel Deviation', defval=2, group="TREND CLOUD
SETTINGS")
enableAutoTrend = input(false, "Enable Auto Trendlines", group="AUTO TRENDLINES
SETTINGS")
srcTrendChannel = input(close, "Trend channel source", group="AUTO TRENDLINES
SETTINGS")
lenTrendChannel = input.int(200, "Trend channel loopback", 2, group="AUTO
TRENDLINES SETTINGS")
enableSR = input(false, "Enable support and resistance", group="AUTO
SUPPORT AND RESISTANCE SETTINGS")
lineSrStyle = input.string("Dashed", "Line Style", ["Solid", "Dotted",
"Dashed"], group="AUTO SUPPORT AND RESISTANCE SETTINGS")
lineSrWidth = input.int(2, "Line Width", 1, 4, group="AUTO SUPPORT AND
RESISTANCE SETTINGS")
showCons = input(false, "Consolidation Zones", group="CONSOLIDATION
ZONES")
lbPeriod = input.int(10, "Loopback Period", 2, 50, group="CONSOLIDATION
ZONES")
lenCons = input.int(5, "Min Consolidation Length", 2, 20,
group="CONSOLIDATION ZONES")
paintCons = input(true, "Paint Consolidation Area", group="CONSOLIDATION
ZONES")
colorZone = input(color.new(color.blue, 70), "Zone Color",
group="CONSOLIDATION ZONES")
box_ob = input.bool(false, "Toggle Order Block", group="ORDER BLOCK")
box_hide_gray = input.bool(false, "Hide gray boxes", group="ORDER BLOCK")
bos_type = input.string("High and Low", "MSB trigger", ["High and Low",
"Close and Open"], group="ORDER BLOCK")
box_sv = input.bool(true, "Plot demand boxes", group="ORDER BLOCK")
box_test_delay = input.int(3, "Delay to count test of demand box", 1,
group="ORDER BLOCK")
box_fill_delay = input.int(3, "Delay to count fill of demand box", 1,
group="ORDER BLOCK")
box_test_sv = input.bool(true, "Dim tested demand boxes", group="ORDER
BLOCK")
box_stop_sv = input.bool(true, "Stop plotting filled demand boxes",
group="ORDER BLOCK")
show_swing_ms = input.string("All", "Swing ", inline = "1", group = "MARKET
STRUCTURE", options = ["All", "CHoCH", "BOS","None"])
show_internal_ms = input.string("All", "Internal", inline = "2", group = "MARKET
STRUCTURE", options = ["All", "CHoCH", "BOS", "CHoCH+", "None"])
internal_r_lookback= input.int(5, "" , inline = "2", group = "MARKET STRUCTURE",
minval = 2)
swing_r_lookback = input.int(50, "", inline = "1", group = "MARKET STRUCTURE",
minval = 2)
plotcandle_bool = input.bool(false, "Plotcandle", inline = "3", group = "MARKET
STRUCTURE", tooltip = "Plot a better coloring chart (require disable the current
ticker)")
barcolor_bool = input.bool(false, "Bar Color", inline = "4", group = "MARKET
STRUCTURE" , tooltip = "Normal bar coloring")
internal_l_lookback= math.round(internal_r_lookback)
swing_l_lookback = (swing_r_lookback )
i_ms_up_bos = input.color(#42bda8, "", inline = "2", group = "MARKET
STRUCTURE")
i_ms_up_choch = input.color(#056656, "", inline = "2", group = "MARKET
STRUCTURE")
i_ms_dn_bos = input.color(#ff5252, "", inline = "2", group = "MARKET
STRUCTURE")
i_ms_dn_choch = input.color(#b22833, "", inline = "2", group = "MARKET
STRUCTURE")
s_ms_up_bos = input.color(#42bda8, "", inline = "1", group = "MARKET
STRUCTURE")
s_ms_up_choch = input.color(#056656, "", inline = "1", group = "MARKET
STRUCTURE")
s_ms_dn_bos = input.color(#ff5252, "", inline = "1", group = "MARKET
STRUCTURE")
s_ms_dn_choch = input.color(#b22833, "", inline = "1", group = "MARKET
STRUCTURE")
lvl_daily = input.bool(false, "Day ", inline = "1", group = "HIGHS & LOWS
MTF")
lvl_weekly = input.bool(false, "Week ", inline = "2", group = "HIGHS & LOWS
MTF")
lvl_monthly = input.bool(false, "Month", inline = "3", group = "HIGHS & LOWS
MTF")
lvl_yearly = input.bool(false, "Year ", inline = "4", group = "HIGHS &
LOWS MTF")
css_d = input.color(color.blue, "", inline = "1", group = "HIGHS &
LOWS MTF")
css_w = input.color(color.blue, "", inline = "2", group = "HIGHS &
LOWS MTF")
css_m = input.color(color.blue, "", inline = "3", group = "HIGHS &
LOWS MTF")
css_y = input.color(color.blue, "", inline = "4", group = "HIGHS &
LOWS MTF")
s_d = input.string('⎯⎯⎯', '' , inline = '1', group = 'HIGHS & LOWS
MTF', options = ['⎯⎯⎯', '----', '····'])
s_w = input.string('⎯⎯⎯', '' , inline = '2', group = 'HIGHS & LOWS
MTF', options = ['⎯⎯⎯', '----', '····'])
s_m = input.string('⎯⎯⎯', '' , inline = '3', group = 'HIGHS & LOWS
MTF', options = ['⎯⎯⎯', '----', '····'])
s_y = input.string('⎯⎯⎯', '' , inline = '4', group = 'HIGHS & LOWS
MTF', options = ['⎯⎯⎯', '----', '····'])
ob_show = input.bool(true, "Show Last ", inline = "1", group =
"VOLUMETRIC ORDER BLOCKS", tooltip = "Display volumetric order blocks on the
chart \n\n[Input] Ammount of volumetric order blocks to show")
ob_num = input.int (2, "" , inline = "1", group = "VOLUMETRIC ORDER
BLOCKS", tooltip = "Orderblocks number", minval = 1, maxval = 10)
ob_metrics_show = input.bool(true, "Internal Buy/Sell Activity" , inline = "2",
group = "VOLUMETRIC ORDER BLOCKS", tooltip = "Display volume metrics that have
formed the orderblock")
css_metric_up = input.color(color.new(color.teal, 50) , " ", inline =
"2", group = "VOLUMETRIC ORDER BLOCKS")
css_metric_dn = input.color(color.new(color.red , 50) , "" , inline = "2",
group = "VOLUMETRIC ORDER BLOCKS")
ob_swings = input.bool(false, "Swing Order Blocks", inline = "a", group =
"VOLUMETRIC ORDER BLOCKS", tooltip = "Display swing volumetric order blocks")
css_swing_up = input.color(color.new(#42bda8, 40), " ", inline =
"a", group = "VOLUMETRIC ORDER BLOCKS")
css_swing_dn = input.color(color.new(#ff5252, 40), "" , inline = "a", group =
"VOLUMETRIC ORDER BLOCKS")
ob_lookback_bool = input.bool(false, "Lenght ", inline = "3", group =
"VOLUMETRIC ORDER BLOCKS", tooltip = "[Enable] Use the lenght period to determine
the lowest/highest point of the orderblock creation\n\n[Disable] Use the last
opposite candle to determine the orderblock creation")
ob_filter = input.string("None", "Filtering ", inline = "d", group
= "VOLUMETRIC ORDER BLOCKS", tooltip = "Filter out volumetric order blocks by
BOS/CHoCH/CHoCH+", options = ["None", "BOS", "CHoCH", "CHoCH+"])
ob_looback = input.int(5, "" , inline = "3", group = "VOLUMETRIC ORDER
BLOCKS" , tooltip = "Lookback to find lowest point for the construction of the
volumetric order blocks")
ob_mitigation = input.string("Absolute", "Mitigation ", inline = "4",
group = "VOLUMETRIC ORDER BLOCKS", tooltip = "Trigger to remove volumetric order
blocks", options = ["Absolute", "Middle"])
ob_timeframe = input.timeframe("", "Timeframe ", inline = "5", group =
"VOLUMETRIC ORDER BLOCKS", tooltip = "Timeframe of the volumetric order blocks")
use_grayscale = input.bool(true, "Grayscale", inline = "6", group =
"VOLUMETRIC ORDER BLOCKS", tooltip = "Use gray as basic order blocks color")
use_show_metric = input.bool(true, "Show Metrics" , inline = "7", group =
"VOLUMETRIC ORDER BLOCKS", tooltip = "Show volume associated with the orderblock
and his relevance")
use_middle_line = input.bool(true, "Show Middle-Line", inline = "8", group =
"VOLUMETRIC ORDER BLOCKS", tooltip = "Show mid-line order blocks")
use_overlap = input.bool(true, "Hide Overlap", inline = "9", group =
"VOLUMETRIC ORDER BLOCKS", tooltip = "Hide overlapping order blocks")
use_overlap_method = input.string("Previous", "Overlap Method ", inline = "Z",
group = "VOLUMETRIC ORDER BLOCKS", tooltip = "[Recent] Preserve the most recent
volumetric order blocks\n\n[Previous] Preserve the previous volumetric order
blocks", options = ["Recent", "Previous"])
ob_bull_css = input.color(color.new(color.teal, 90), "" , inline = "1",
group = "VOLUMETRIC ORDER BLOCKS")
ob_bear_css = input.color(color.new(color.red , 90), "", inline = "1",
group = "VOLUMETRIC ORDER BLOCKS")
show_lbl = input.bool(false, "Show swing point", inline = "1", group =
"High and Low", tooltip = "Display swing point")
show_mtb = input.bool(false, "Show High/Low/Equilibrium", inline = "2",
group = "High and Low", tooltip = "Display Strong/Weak High And Low and
Equilibrium")
toplvl = input.color(color.red, "Premium Zone ", inline = "3", group =
"High and Low")
midlvl = input.color(color.white, "Equilibrium Zone", inline = "4",
group = "High and Low")
btmlvl = input.color(color.teal, "Discount Zone ", inline = "5",
group = "High and Low")
fvg_enable = input.bool(false, "FVG ", inline = "1", group = "FVG",
tooltip = "Display fair value gap")
fvg_upcss = input.color(color.new(color.aqua, 80), "" , inline = "1",
group = "FVG")
fvg_dncss = input.color(color.new(color.red , 80), "" , inline = "1",
group = "FVG")
fvg_extend = input.int(10, "Extend FVG", inline = "2", group = "FVG",
tooltip = "Extend FVG")
fvg_src = input.string("Close", "Mitigation ", inline = "3", group =
"FVG", tooltip = "[Close] Use the close of the body as trigger\n\n[Wick] Use the
extreme point of the body as trigger", options = ["Close", "Wick"])
fvg_tf = input.timeframe("", "Timeframe ", inline = "4", group = "FVG",
tooltip = "Timeframe of the fair value gap")
eliteVP = input(false, "volume profile", group="VOLUME PROFILE")
colorBorderVP = input(color.new(color.black, 80), "Border color", group="VOLUME
PROFILE")
colorBuyVP = input(#7F1623, "Buy volume", group="VOLUME PROFILE")
colorSellVP = input(#00DD00, "Sell volume", group="VOLUME PROFILE")
offset = input.int(2, "Offset", 2, 20, group="VOLUME PROFILE")
lookback = input.int(100, "Lookback", 14, 365, group="VOLUME PROFILE")
levelNum = input.int(100, "Number of levels", 10, 100, group="VOLUME
PROFILE")
levelWidth = input.int(50, "Level width", 20, 100, group="VOLUME PROFILE")
// 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)
atr(len) =>
tr = ta.tr
atr = 0.0
atr := nz(atr[1] + (tr - atr[1]) / len, tr)
supertrend(src, factor, len) =>
atr = ta.atr(len)
upperBand = src + factor * atr
lowerBand = src - factor * atr
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ?
lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ?
upperBand : prevUpperBand
int direction = na
float superTrend = na
prevSuperTrend = superTrend[1]
if prevSuperTrend == prevUpperBand
direction := close > upperBand ? 1 : -1
else
direction := close < lowerBand ? -1 : 1
superTrend := direction == 1 ? lowerBand : direction == -1 ? upperBand : na
dchannel(len)=>
hh = ta.highest(len)
ll = ta.lowest (len)
trend = 0
trend := close > hh[1] ? 1 : close < ll[1] ? -1 : nz(trend[1])
trendScalper(show, len1, len2, len3, colorBull, colorBear, colorBarBull,
colorBarBear) =>
avgOC = math.avg(open, close)
ha_o = 0.0, ha_o := na(ha_o[1]) ? avgOC : (ha_o[1] + ohlc4[1]) / 2
ema1 = ta.ema(ha_o, len1), ema2 = ta.ema(ha_o, len2), ema3 = ta.ema(ha_o, len3)
ris1 = ema1 > ema1[1], ris2 = ema2 > ema2[1], ris3 = ema3 > ema3[1]
fal1 = ema1 < ema1[1], fal2 = ema2 < ema2[1], fal3 = ema3 < ema3[1]
colorEma1 = ris1 ? colorBull : fal1 ? colorBear : na, colorEma2 = ris2 ?
colorBull : fal2 ? colorBear : na, colorEma3 = ris3 ? colorBull : fal3 ?
colorBear : na
fillEma1 = avgOC > ema1 ? colorBull : avgOC < ema1 ? colorBear : na, fillEma2 =
ema1 > ema2 ? colorBull : ema1 < ema2 ? colorBear : na, fillEma3 = ema2 > ema3 ?
colorBull : ema2 < ema3 ? colorBear : na
colorBar = close < ema1 and close < ema2 ? colorBarBear : colorBarBull
[avgOC, show ? ema1 : na, show ? ema2 : na, show ? ema3 : na,
color.new(colorEma1, 55), color.new(colorEma2, 45), color.new(colorEma3, 35),
color.new(fillEma1, 85), color.new(fillEma2, 80), color.new(fillEma3, 75),
colorBar]
candlesMom() =>
[_, _, macd] = ta.macd(close, 12, 26, 9)
(macd > 0 and macd > macd[1]) or (macd < 0 and macd < macd[1])
trailingSL(buy, sell, factor, len, usePerc, perc) =>
atr = atr(len)
upperBand = high + (usePerc ? high * (perc / 100) : factor * atr)
lowerBand = low - (usePerc ? low * (perc / 100) : factor * atr)
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
lowerBand := lowerBand > prevLowerBand or buy ? lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or sell ? upperBand : prevUpperBand
int direction = na
float stop = na
prevSuperTrend = stop[1]
if prevSuperTrend == prevUpperBand
direction := buy ? 1 : -1
else
direction := sell ? -1 : 1
stop := direction == 1 ? lowerBand : direction == -1 ? upperBand : na
add_to_zz(zz, val, bi) =>
array.unshift(zz, bi)
array.unshift(zz, val)
if array.size(zz) > 12
array.pop(zz)
update_zz(zz, val, bi, dir) =>
if array.size(zz) == 0
add_to_zz(zz, val, bi)
else
if dir == 1 and val > array.get(zz, 0) or dir == -1 and val < array.get(zz,
0)
array.set(zz, 0, val)
array.set(zz, 1, bi)
0
float ph = ta.pivothigh(high, 10, 10)
float pl = ta.pivotlow (low , 10, 10)
LSRstyle = lineSrStyle == "Dashed" ? line.style_dashed : lineSrStyle == "Solid" ?
line.style_solid : line.style_dotted
prdhighest = ta.highest(300)
prdlowest = ta.lowest (300)
cwidth = (prdhighest - prdlowest) * 10 / 100
var pivotvals = array.new_float(0)
if ph or pl
array.unshift(pivotvals, ph ? ph : pl)
if array.size(pivotvals) > 20
array.pop(pivotvals)
get_sr_vals(ind) =>
float lo = array.get(pivotvals, ind)
float hi = lo
int numpp = 0
for y = 0 to array.size(pivotvals) - 1 by 1
float cpp = array.get(pivotvals, y)
float wdth = cpp <= lo ? hi - cpp : cpp - lo
if wdth <= cwidth
lo := cpp <= lo ? cpp : lo
hi := cpp > lo ? cpp : hi
numpp += 1
numpp
[hi, lo, numpp]
var sr_up_level = array.new_float(0)
var sr_dn_level = array.new_float(0)
sr_strength = array.new_float(0)
find_loc(strength) =>
ret = array.size(sr_strength)
for i = ret > 0 ? array.size(sr_strength) - 1 : na to 0 by 1
if strength <= array.get(sr_strength, i)
break
ret := i
ret
ret
check_sr(hi, lo, strength) =>
ret = true
for i = 0 to array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na by
1
if array.get(sr_up_level, i) >= lo and array.get(sr_up_level, i) <= hi or
array.get(sr_dn_level, i) >= lo and array.get(sr_dn_level, i) <= hi
if strength >= array.get(sr_strength, i)
array.remove(sr_strength, i)
array.remove(sr_up_level, i)
array.remove(sr_dn_level, i)
ret
else
ret := false
ret
break
ret
// Get components
rsi = ta.rsi(close, 14)
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
TFBull = securityNoRep(syminfo.tickerid, "" , emaBull)
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)
ema150 = ta.ema(close, 150)
ema250 = ta.ema(close, 250)
hma55 = ta.hma(close, 55 )
[_, _, macd] = ta.macd(close, 12, 26, 9)
supertrend = supertrend(ohlc4, sensitivity, 10)
maintrend = dchannel(30)
confBull = (ta.crossover (close, supertrend) or (ta.crossover (close, supertrend)
[1] and maintrend[1] < 0)) and macd > 0 and macd > macd[1] and ema150 > ema250 and
hma55 > hma55[2] and maintrend > 0
confBear = (ta.crossunder(close, supertrend) or (ta.crossunder(close, supertrend)
[1] and maintrend[1] > 0)) and macd < 0 and macd < macd[1] and ema150 < ema250 and
hma55 < hma55[2] and maintrend < 0
trendcloud = supertrend(ohlc4, periodTrendCloud == "Long term" ? 7 : 4, 10)
hma = fastTrendCloud ? ta.hma(close, fastTrendCloudLen) : na
rationalQuadratic(_src, _lookback, _relativeWeight, startAtBar, _filter) =>
float _currentWeight = 0.
float _cumulativeWeight = 0.
_size = array.size(array.from(_src))
for i = 0 to _size + startAtBar
y = _src[i]
w = math.pow(1 + (math.pow(i, 2) / ((math.pow(_lookback, 2) * 2 *
_relativeWeight))), -_relativeWeight)
_currentWeight += y*w
_cumulativeWeight += w
yhatdelt = _currentWeight / _cumulativeWeight
float _currentWeight2 = 0.
float _cumulativeWeight2 = 0.
_size2 = array.size(array.from(yhatdelt))
for i = 0 to _size2 + startAtBar
y = yhatdelt[i]
w = math.pow(1 + (math.pow(i, 2) / ((math.pow(_lookback, 2) * 2 *
_relativeWeight))), -_relativeWeight)
_currentWeight2 += y*w
_cumulativeWeight2 += w
yhatdelt2 = _currentWeight2 / _cumulativeWeight2
yhat = yhatdelt - (yhatdelt - yhatdelt2)
zlagcalc = yhatdelt + (yhatdelt - yhatdelt2)
lineout = _filter == "No Filter" ? yhatdelt : _filter == "Smooth" ? yhat :
_filter == "Zero Lag" ? zlagcalc : na
lineout
gaussian(_src, _lookback, startAtBar, _filter) =>
float _currentWeight = 0.
float _cumulativeWeight = 0.
_size = array.size(array.from(_src))
for i = 0 to _size + startAtBar
y = _src[i]
w = math.exp(-math.pow(i, 2) / (2 * math.pow(_lookback, 2)))
_currentWeight += y*w
_cumulativeWeight += w
yhatdelt = _currentWeight / _cumulativeWeight
float _currentWeight2 = 0.
float _cumulativeWeight2 = 0.
_size2 = array.size(array.from(yhatdelt))
for i = 0 to _size2 + startAtBar
y = yhatdelt[i]
w = math.exp(-math.pow(i, 2) / (2 * math.pow(_lookback, 2)))
_currentWeight2 += y*w
_cumulativeWeight2 += w
yhatdelt2 = _currentWeight2 / _cumulativeWeight2
yhat = yhatdelt - (yhatdelt - yhatdelt2)
zlagcalc = yhatdelt + (yhatdelt - yhatdelt2)
lineout = _filter == "No Filter" ? yhatdelt : _filter == "Smooth" ? yhat :
_filter == "Zero Lag" ? zlagcalc : na
lineout
//src1 = input(close)
src1 = close
// Tralling Stop
src5 = close
//rsi processing
up = ta.rma(math.max(ta.change(src5), 0), len)
atr2 = ta.atr(100) / 2
dev = channelDeviation * atr2
highPrice1 = high[math.abs(ta.highestbars(amplitude))]
lowPrice1 = low[math.abs(ta.lowestbars(amplitude))]
highma = ta.sma(high, amplitude)
lowma = ta.sma(low, amplitude)
if nextTrend == 1
maxLowPrice := math.max(lowPrice1, maxLowPrice)
if trend == 0
if not na(trend[1]) and trend[1] != 0
up1 := na(down1[1]) ? down1 : down1[1]
arrowUp := up - atr2
arrowUp
else
up1 := na(up1[1]) ? maxLowPrice : math.max(maxLowPrice, up1[1])
up1
atrHigh := up1 + dev
atrLow := up1 - dev
atrLow
else
if not na(trend[1]) and trend[1] != 1
down1 := na(up1[1]) ? up1 : up1[1]
arrowDown := down1 + atr2
arrowDown
else
down1 := na(down1[1]) ? minHighPrice : math.min(minHighPrice, down1[1])
down1
atrHigh := down1 + dev
atrLow := down1 - dev
atrLow
utrend = ta.crossunder(trend, 1)
dtrend = ta.crossover(trend, 0)
//
//Sell Stop
var float sellPrice = na
if (bear)
sellPrice := close
SellStop = sellPrice<close
//Buy Stop
var float buyPrice = na
if (bull)
buyPrice := close
buyStop = buyPrice>close
weekgreen = color.gray
weekred = color.gray
if((not (trend == 0)) or (buyPrice>close) or (TFBull == false))
weekgreen := color.gray
weekred := red
else
weekgreen := green
weekred := red
y1 = low - (ta.atr(30) * 2)
y2 = high + (ta.atr(30) * 2)
buy = showSignals and bull ? label.new(bar_index, y1, close > smartFilter ? "Smart
Buy" : "Buy", xloc.bar_index, yloc.price, weekgreen, label.style_label_up,
color.white, size.normal) : na
sell = showSignals and bear ? label.new(bar_index, y2, close < smartFilter ? "Smart
Sell" : "Sell", xloc.bar_index, yloc.price, weekred, label.style_label_down,
color.white, size.normal) : na
tpLabels(tp) =>
tp1Bull = ta.crossover (rsi, 70), tp2Bull = ta.crossover (rsi, 75), tp3Bull =
ta.crossover (rsi, 80)
tp1Bear = ta.crossunder(rsi, 30), tp2Bear = ta.crossunder(rsi, 25), tp3Bear =
ta.crossunder(rsi, 20)
tp1Bull := tp1Bull and (nz(ta.barssince(tp1Bull)[1], 9999) > countBull),
tp2Bull := tp2Bull and (ta.barssince(tp1Bull)[1] <= countBull), tp2Bull := tp2Bull
and (nz(ta.barssince(tp2Bull)[1], 9999) > countBull), tp3Bull := tp3Bull and
(ta.barssince(tp2Bull)[1] <= countBull), tp3Bull := tp3Bull and
(nz(ta.barssince(tp3Bull)[1], 9999) > countBull)
tp1Bear := tp1Bear and (nz(ta.barssince(tp1Bear)[1], 9999) > countBear),
tp2Bear := tp2Bear and (ta.barssince(tp1Bear)[1] <= countBear), tp2Bear := tp2Bear
and (nz(ta.barssince(tp2Bear)[1], 9999) > countBear), tp3Bear := tp3Bear and
(ta.barssince(tp2Bear)[1] <= countBear), tp3Bear := tp3Bear and
(nz(ta.barssince(tp3Bear)[1], 9999) > countBear)
if strategy != "Trend scalper" and tpLabels
trigger ? (tp == 1 ? tp1Bull : tp == 2 ? tp2Bull : tp3Bull) : (tp == 1 ?
tp1Bear : tp == 2 ? tp2Bear : tp3Bear)
plotshape(tpLabels(1), "", shape.cross, location.abovebar, trigger ? green : na ,
0, "TP 1", trigger ? green : na , false)
plotshape(tpLabels(2), "", shape.cross, location.abovebar, trigger ? green : na ,
0, "TP 2", trigger ? green : na , false)
plotshape(tpLabels(3), "", shape.cross, location.abovebar, trigger ? green : na ,
0, "TP 3", trigger ? green : na , false)
plotshape(tpLabels(1), "", shape.cross, location.belowbar, trigger ? na : red,
0, "TP 1", trigger ? na : red, false)
plotshape(tpLabels(2), "", shape.cross, location.belowbar, trigger ? na : red,
0, "TP 2", trigger ? na : red, false)
plotshape(tpLabels(3), "", shape.cross, location.belowbar, trigger ? na : red,
0, "TP 3", trigger ? na : red, false)
var label zzLabel = na
if array.size(zz) > 12 and enableSwings
if array.get(zz, 0) != array.get(zzOld, 0) or array.get(zz, 1) !=
array.get(zzOld, 1)
if array.get(zz, 2) == array.get(zzOld, 2) and array.get(zz, 3) ==
array.get(zzOld, 3)
label.delete(zzLabel)
zzLabel := label.new(math.round(array.get(zz, 1)), array.get(zz, 0), _dir
== 1 ? array.get(zz, 0) > array.get(zz, 4) ? ((array.get(zz, 4) < array.get(zz, 8))
? "High" : "HH") : "LH" : array.get(zz, 0) < array.get(zz, 4) ? ((array.get(zz, 4)
> array.get(zz, 8)) ? "Low" : "LL") : "HL", xloc.bar_index, yloc.price,
color.new(color.white, 100), _dir == 1 ? label.style_label_down :
label.style_label_up, _dir == 1 ? color.green : color.red)
var sr_lines = array.new_line(11, na)
for x = 1 to 10 by 1
line.set_color(array.get(sr_lines, x), color=line.get_y1(array.get(sr_lines,
x)) >= close ? color.red : color.lime)
if ph or pl
array.clear(sr_up_level)
array.clear(sr_dn_level)
array.clear(sr_strength)
for x = 0 to array.size(pivotvals) - 1 by 1
[hi, lo, strength] = get_sr_vals(x)
if check_sr(hi, lo, strength)
loc = find_loc(strength)
if loc < 5 and strength >= 2
array.insert(sr_strength, loc, strength)
array.insert(sr_up_level, loc, hi)
array.insert(sr_dn_level, loc, lo)
if array.size(sr_strength) > (enableSR ? 5 : 0)
array.pop(sr_strength)
array.pop(sr_up_level)
array.pop(sr_dn_level)
for x = 1 to 10 by 1
line.delete(array.get(sr_lines, x))
for x = 0 to array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na by
1
float mid = math.round_to_mintick((array.get(sr_up_level, x) +
array.get(sr_dn_level, x)) / 2)
rate = 100 * (mid - close) / close
array.set(sr_lines, x + 1, line.new(x1=bar_index, y1=mid, x2=bar_index - 1,
y2=mid, extend=extend.both, color=mid >= close ? color.red : color.lime,
style=LSRstyle, width=lineSrWidth))
if showCons and barstate.isconfirmed
dir := hb_ and na(lb_) ? 1 : lb_ and na(hb_) ? -1 : dir
if hb_ and lb_
if dir == 1
zz_ := hb_
else
zz_ := lb_
else
zz_ := hb_ ? hb_ : lb_ ? lb_ : na
for x = 0 to 1000
if na(close) or dir != dir[x]
break
if zz_[x]
if na(pp)
pp := zz_[x]
else
if dir[x] == 1 and zz_[x] > pp
pp := zz_[x]
if dir[x] == -1 and zz_[x] < pp
pp := zz_[x]
if pp != pp[1]
if consCnt > lenCons
if pp > condHi
breakUp := true
if pp < condLo
breakDn := true
if consCnt > 0 and pp <= condHi and pp >= condLo
consCnt += 1
else
consCnt := 0
else
consCnt += 1
if consCnt >= lenCons
if consCnt == lenCons
condHi := H_
condLo := L_
else
line.delete(lineUp)
line.delete(lineDn)
condHi := math.max(condHi, high)
condLo := math.min(condLo, low )
lineUp := line.new(bar_index, condHi , bar_index - consCnt, condHi ,
color=color.red , style=line.style_dashed)
lineDn := line.new(bar_index, condLo , bar_index - consCnt, condLo ,
color=color.lime, style=line.style_dashed)
fill(plot(condHi, "", na, 1, plot.style_stepline, editable=false), plot(condLo, "",
na, 1, plot.style_stepline, editable=false), paintCons and consCnt > lenCons ?
colorZone : na, "", false)
if box_ob and barstate.isconfirmed
if pvh
array.pop(pvh1_price)
array.pop(pvh1_time)
array.unshift(pvh1_price, pv1_high)
array.unshift(pvh1_time, pv1_time)
if array.size(pvh1_price) > 2
temp_pv_0 := array.get(pvh1_price, 0)
temp_pv_1 := array.get(pvh1_price, 1)
temp_pv_2 := array.get(pvh1_price, 2)
if temp_pv_0 > temp_pv_1
for i = 0 to array.size(pvl1_time) - 1 by 1
temp_ltcmrhh_time = array.get(pvl1_time, i)
if temp_ltcmrhh_time < array.get(pvh1_time, 0)
ltcmrhh_price := array.get(pvl1_price, i)
ltcmrhh_time := temp_ltcmrhh_time
break
if temp_pv_0 < temp_pv_1 and temp_pv_1 > temp_pv_2
array.pop(pvh2_price)
array.pop(pvh2_time)
array.unshift(pvh2_price, temp_pv_1)
array.unshift(pvh2_time, array.get(pvh1_time, 1))
if pvl
array.pop(pvl1_price)
array.pop(pvl1_time)
array.unshift(pvl1_price, pv1_low)
array.unshift(pvl1_time, pv1_time)
if array.size(pvl1_price) > 2
temp_pv_0 := array.get(pvl1_price, 0)
temp_pv_1 := array.get(pvl1_price, 1)
temp_pv_2 := array.get(pvl1_price, 2)
if temp_pv_0 < temp_pv_1
for i = 0 to array.size(pvh1_time) - 1 by 1
temp_htcmrll_time = array.get(pvh1_time, i)
if temp_htcmrll_time < array.get(pvl1_time, 0)
htcmrll_price := array.get(pvh1_price, i)
htcmrll_time := temp_htcmrll_time
break
if temp_pv_0 > temp_pv_1 and temp_pv_1 < temp_pv_2
array.pop(pvl2_price)
array.pop(pvl2_time)
array.unshift(pvl2_price, temp_pv_1)
array.unshift(pvl2_time, array.get(pvl1_time, 1))
if trigger_high > htcmrll_price
if box_sv
loBox = box.new(left=array.get(pvl1_time, 0),
top=math.min(high[bar_index - array.get(pvl1_time, 0)], high[bar_index -
array.get(pvl1_time, 0) + 1]), right=bar_index, bottom=array.get(pvl1_price, 0),
bgcolor=color.rgb(0, 255, 0, 80), border_color=color.rgb(0, 255, 0, 80),
extend=extend.right)
if array.size(long_boxes) >= 25
box.delete(array.shift(long_boxes))
array.push(long_boxes, loBox)
htcmrll_price := na
htcmrll_price
if trigger_low < ltcmrhh_price
if box_sv
hiBox = box.new(left=array.get(pvh1_time, 0), top=array.get(pvh1_price,
0), right=bar_index, bottom=math.max(low[bar_index - array.get(pvh1_time, 0)],
low[bar_index - array.get(pvh1_time, 0) + 1]), bgcolor=color.rgb(255, 0, 0, 80),
border_color=color.rgb(255, 0, 0, 80), extend=extend.right)
if array.size(short_boxes) >= 25
box.delete(array.shift(short_boxes))
array.push(short_boxes, hiBox)
ltcmrhh_price := na
ltcmrhh_price
if array.size(short_boxes) > 0
for i = array.size(short_boxes) - 1 to 0 by 1
tbox = array.get(short_boxes, i)
top = box.get_top(tbox)
bottom = box.get_bottom(tbox)
if trigger_high > bottom and box.get_left(tbox) + box_test_delay <
bar_index and box_test_sv
if box_hide_gray
box.set_bgcolor(tbox, #00000000)
box.set_border_color(tbox, #00000000)
else
box.set_bgcolor(tbox, color.rgb(192, 192, 192, 80))
box.set_border_color(tbox, color.rgb(192, 192, 192, 80))
if trigger_high > top and box.get_left(tbox) + box_fill_delay <
bar_index
if box_stop_sv
box.set_right(tbox, bar_index)
box.set_extend(tbox, extend.none)
array.remove(short_boxes, i)
if array.size(long_boxes) > 0
for i = array.size(long_boxes) - 1 to 0 by 1
lbox = array.get(long_boxes, i)
top = box.get_top(lbox)
bottom = box.get_bottom(lbox)
if trigger_low < top and box.get_left(lbox) + box_test_delay <
bar_index and box_test_sv
if box_hide_gray
box.set_bgcolor(lbox, #00000000)
box.set_border_color(lbox, #00000000)
else
box.set_bgcolor(lbox, color.rgb(192, 192, 192, 80))
box.set_border_color(lbox, color.rgb(192, 192, 192, 80))
if trigger_low < bottom and box.get_left(lbox) + box_fill_delay <
bar_index
if box_stop_sv
box.set_right(lbox, bar_index)
box.set_extend(lbox, extend.none)
array.remove(long_boxes, i)
if barstate.islast and eliteVP
for i = 0 to levelNum - 1
histogramLow = rangeLow + histogramHeight * i
histogramHigh = rangeLow + histogramHeight * (i + 1)
array.set(histogramLowList, i, histogramLow)
array.set(histogramHighList, i, histogramHigh)
for i = 0 to lookback - 1
currentBarHeight = high[i] - low[i]
currentBuyVolume = high[i] == low[i] ? 0 : volume[i] * (close[i] - low
[i]) / currentBarHeight
currentSellVolume = high[i] == low[i] ? 0 : volume[i] * (high [i] -
close[i]) / currentBarHeight
for j = 0 to levelNum - 1
histogramLow = array.get(histogramLowList, j)
histogramHigh = array.get(histogramHighList, j)
target = math.max(histogramHigh, high[i]) - math.min(histogramLow,
low[i]) - (math.max(histogramHigh, high[i]) - math.min(histogramHigh, high[i])) -
(math.max(histogramLow, low[i]) - math.min(histogramLow, low[i]))
histogramVolumePercentage = target / currentBarHeight
histogramBuyVolume = array.get(histogramBuyVolumeList, j)
histogramSellVolume = array.get(histogramSellVolumeList, j)
if histogramVolumePercentage > 0
array.set(histogramBuyVolumeList, j, histogramBuyVolume +
currentBuyVolume * histogramVolumePercentage)
array.set(histogramSellVolumeList, j, histogramSellVolume +
currentSellVolume * histogramVolumePercentage)
highestHistogramVolume = 0.0
for i = 0 to levelNum - 1
histogramBuyVolume = array.get(histogramBuyVolumeList, i)
histogramSellVolume = array.get(histogramSellVolumeList, i)
histogramVolume = histogramBuyVolume + histogramSellVolume
highestHistogramVolume := math.max(highestHistogramVolume, histogramVolume)
highestHistogramVolume
for i = 0 to levelNum - 1
histogramLow = array.get(histogramLowList, i)
histogramHigh = array.get(histogramHighList, i)
histogramBuyVolume = array.get(histogramBuyVolumeList, i)
histogramSellVolume = array.get(histogramSellVolumeList, i)
histogramVolume = histogramBuyVolume + histogramSellVolume
histogramWidth = levelWidth * histogramVolume / highestHistogramVolume
histogramBuyWidth = math.floor(histogramWidth * histogramBuyVolume /
histogramVolume)
histogramSellWidth = math.floor(histogramWidth * histogramSellVolume /
histogramVolume)
array.set(buyBars , i, box.new(bar_index + offset + levelWidth - 1 -
histogramBuyWidth, histogramHigh, bar_index + offset + levelWidth - 1
, histogramLow, colorBorderVP, bgcolor=colorBuyVP ))
array.set(sellBars, i, box.new(bar_index + offset + levelWidth - 1 -
histogramBuyWidth, histogramHigh, bar_index + offset + levelWidth - 1 -
histogramBuyWidth - histogramSellWidth, histogramLow, colorBorderVP,
bgcolor=colorSellVP))
//Boolean set
s_bos = 0
s_choch = 1
i_bos = 2
i_choch = 3
i_pp_choch = 4
green_candle = 5
red_candle = 6
boolean =
array.from(
false // s_bos
, false // s_choch
, false // i_bos
, false // i_choch
, false // i_pp_choch
, false // up
, false // dn
)
switch use_grayscale
true => ob_bull_css := color.gray, ob_bear_css := color.gray
=> na
switch show_swing_ms
"All" => boolean.set(s_bos, true ), boolean.set(s_choch, true )
"CHoCH" => boolean.set(s_bos, false), boolean.set(s_choch, true )
"BOS" => boolean.set(s_bos, true ), boolean.set(s_choch, false)
"None" => boolean.set(s_bos, false), boolean.set(s_choch, false)
=> na
switch show_internal_ms
"All" => boolean.set(i_bos, true ), boolean.set(i_choch, true ),
boolean.set(i_pp_choch, true )
"CHoCH" => boolean.set(i_bos, false), boolean.set(i_choch, true ),
boolean.set(i_pp_choch, false)
"BOS" => boolean.set(i_bos, true ), boolean.set(i_choch, false),
boolean.set(i_pp_choch, false)
"CHoCH+" => boolean.set(i_bos, false), boolean.set(i_choch, false),
boolean.set(i_pp_choch, true )
"None" => boolean.set(i_bos, false), boolean.set(i_choch, false),
boolean.set(i_pp_choch, false)
=> na
type bar
float o = open
float c = close
float h = high
float l = low
float v = volume
int n = bar_index
int t = time
string xt = xloc.bar_time
string xn = xloc.bar_index
type bin
float [] i_hpoint
float [] i_lpoint
int [] i_nBull
int [] i_nBear
float [] s_hpoint
float [] s_lpoint
int [] s_nBull
int [] s_nBear
float [] up_ms_logs
float [] dn_ms_logs
string[] i_bulltxt
string[] i_beartxt
type ob
float[] up_vol
float[] up_top
float[] up_bottom
int [] up_current_time
int [] up_last_time
int [] up_n
float[] dn_vol
float[] dn_top
float[] dn_bottom
int [] dn_current_time
int [] dn_last_time
int [] dn_n
float[] metric_up
float[] metric_dn
type Zphl
line top
line bottom
label top_label
label bottom_label
bool stopcross
bool sbottomcross
bool itopcross
bool ibottomcross
string txtup
string txtdn
float topy
float bottomy
float topx
float bottomx
float tup
float tdn
int tupx
int tdnx
float itopy
float itopx
float ibottomy
float ibottomx
type tfvg
box[] bull_max
box[] bull_min
box[] bear_max
box[] bear_min
bar b1
= bar.new()
var pp1 = bin.new(
array.new< float >(1, na)
, array.new< float >(1, na)
, array.new< int >(1, na)
, array.new< int >(1, na)
, array.new< float >(1, na)
, array.new< float >(1, na)
, array.new< int >(1, na)
, array.new< int >(1, na)
, array.new< float >(1, na)
, array.new< float >(1, na)
, array.new< string >(1, na)
, array.new< string >(1, na)
)
lstyle(style) =>
zhl(len)=>
upper = ta.highest(len)
lower = ta.lowest(len)
[top, btm]
hy = ta.valuewhen(h != h[1] , h , 1)
hx = ta.valuewhen(h == high , time , 1)
ly = ta.valuewhen(l != l[1] , l , 1)
lx = ta.valuewhen(l == low , time , 1)
if barstate.islast
line.set_xy1(hl , hx , hy)
line.set_xy2(hl , extension , hy)
label.set_xy(hlb, extension , hy)
line.set_xy1(ll , lx , ly)
line.set_xy2(ll , extension , ly)
label.set_xy(lbl, extension , ly)
upphl(trendPACL) =>
phl.stopcross := true
phl.txtup := top > phl.topy ? "HH" : "LH"
if show_lbl
topl = label.new(
b1.n - swing_r_lookback
, top
, phl.txtup
, color = invcol
, textcolor = toplvl
, style = label.style_label_down
, size = size.small
)
line.delete(phl.top[1])
phl.top := line.new(
b1.n - swing_r_lookback
, top
, b1.n
, top
, color = toplvl)
phl.topy := top
phl.topx := b1.n - swing_r_lookback
phl.tup := top
phl.tupx := b1.n - swing_r_lookback
if itop
phl.itopcross := true
phl.itopy := itop
phl.itopx := b1.n - internal_r_lookback
if barstate.islast
line.set_xy1(
phl.top
, phl.tupx
, phl.tup
)
line.set_xy2(
phl.top
, b1.n + 50
, phl.tup
)
label.set_x(
lbl
, b1.n + 50
)
label.set_y(
lbl
, phl.tup
)
dnphl(trendPLCL2) =>
if btm
phl.sbottomcross := true
phl.txtdn := btm > phl.bottomy ? "HH" : "LH"
if show_lbl
btml = label.new(
b1.n - swing_r_lookback
, btm, phl.txtdn
, color = invcol
, textcolor = btmlvl
, style = label.style_label_up
, size = size.small
)
line.delete(phl.bottom[1])
phl.bottom := line.new(
b1.n - swing_r_lookback
, btm
, b1.n
, btm
, color = btmlvl
)
phl.bottomy := btm
phl.bottomx := b1.n - swing_r_lookback
phl.tdn := btm
phl.tdnx := b1.n - swing_r_lookback
if ibtm
phl.ibottomcross := true
phl.ibottomy := ibtm
phl.ibottomx := b1.n - internal_r_lookback
phl.tdn := math.min(low, phl.tdn)
phl.tdnx := phl.tdn == low ? b1.n : phl.tdnx
if barstate.islast
line.set_xy1(
phl.bottom
, phl.tdnx
, phl.tdn
)
line.set_xy2(
phl.bottom
, b1.n + 50
, phl.tdn
)
label.set_x(
lbl
, b1.n + 50
)
label.set_y(
lbl
, phl.tdn
)
midphl() =>
if barstate.islast
vol() =>
switch
close > open => posVol += volume
close < open => negVol -= volume
close >= close[1] => posVol += volume
close < close[1] => negVol -= volume
[posVol, negVol]
volblock(bool condition, bool bull, string mitigation, float top, float bottom, int
left, int right, color css, float upx, float dnx, int position, float upv, float
dnv) =>
var ob_top = array.new< float >()
var ob_bottom = array.new< float >()
var ob_left = array.new< int >()
var ob_right = array.new< int >()
var ob_avg = array.new< float >()
var ob_vol = array.new< float >()
var redvol = array.new< float >()
var greenvol = array.new< float >()
var pos = array.new< int >()
var when = array.new< int >()
var countup = array.new< int >()
var countdn = array.new< int >()
if condition
paperlow = array.new< float >()
paperhigh = array.new< float >()
paperindex = array.new< int >()
paperlow .clear()
paperhigh.clear()
float avg = na
var bool isna = na
for i = 1 to ob_looback + 1
if ob_lookback_bool == false
ob_top .unshift(top )
ob_bottom.unshift(bottom)
ob_left .unshift(left )
if ob_lookback_bool
ob_top .unshift(bull ?
paperhigh .get(paperlow.indexof(paperlow.min())) : paperhigh .max())
ob_bottom.unshift(bull ? paperlow .min()
: paperlow .get(paperhigh.indexof(paperhigh.max())))
ob_left .unshift(bull ?
paperindex.get(paperlow.indexof(paperlow.min())) :
paperindex.get(paperhigh.indexof(paperhigh.max())))
ob_right .unshift(right )
ob_avg .unshift(avg )
ob_vol .unshift(bull ? dnv : upv)
redvol .unshift(dnx )
greenvol .unshift(upx )
pos .unshift(position )
when .unshift(1 )
countup .unshift(0 )
countdn .unshift(0 )
if use_overlap
if ob_avg.size() > 1
ob_top .remove(num)
ob_bottom.remove(num)
ob_left .remove(num)
ob_right .remove(num)
ob_avg .remove(num)
ob_vol .remove(num)
redvol .remove(num)
greenvol .remove(num)
pos .remove(num)
when .remove(num)
countup .remove(num)
countdn .remove(num)
if barstate.isconfirmed
out = switch mitigation
"Middle" => ob_avg
"Absolute" => bull ? ob_bottom : ob_top
target = out
idx = target.indexof(stuff)
ob_top .remove(idx)
ob_bottom.remove(idx)
ob_left .remove(idx)
ob_right .remove(idx)
ob_avg .remove(idx)
ob_vol .remove(idx)
redvol .remove(idx)
greenvol .remove(idx)
pos .remove(idx)
when .remove(idx)
countup .remove(idx)
countdn .remove(idx)
if true
if barstate.isfirst
for i = 0 to ob_num - 1
if barstate.islast
if ob_top.size() > 0
// MAIN ORDERBLOCK
box.set_top (get_orderblock, ob_top .get(i)
)
box.set_bottom(get_orderblock, ob_bottom .get(i)
)
box.set_left (get_orderblock, ob_left .get(i)
)
box.set_right (get_orderblock, time
)
// CONTINUATION BLOCK
box.set_top (get_continuationorderblock, ob_top .get(i)
)
box.set_bottom(get_continuationorderblock, ob_bottom.get(i)
)
box.set_left (get_continuationorderblock, time
)
box.set_right (get_continuationorderblock, time + (time -
time[1]) * 100)
// MIDDLE LEVEL
if use_middle_line
if ob_metrics_show
takeup = box.get_right(get_uporderblock)
takedn = box.get_right(get_dnorderblock)
box.set_right (get_dnorderblock, takedn + (time - time[1])
* countdn.get(i))
box.set_right (get_uporderblock, takeup + (time - time[1])
* countup.get(i))
if use_show_metric
box.set_text (get_continuationorderblock,
str.tostring(math.round(ob_vol.get(i) / 1000,3)) + "K" + " (" +
str.tostring( math.abs(math.round((ob_vol.get(i) - (i == 0 ? sum : ob_vol.get(0)) )
/ (i == 0 ? sum : ob_vol.get(0)) ,3)) * 10) + "%)")
box.set_text_size (get_continuationorderblock, size.auto)
box.set_text_halign(get_continuationorderblock,
text.align_left)
box.set_text_color (get_continuationorderblock,
color.new(css,0))
if ob_metrics_show
for i = 0 to countup.size() - 1
switch when.get(i)
1 => countup.set(i, countup.get(i) + 1), when.set(i, 2)
2 => countup.set(i, countup.get(i) + 1), when.set(i, 3)
3 => countdn.set(i, countdn.get(i) + 1), when.set(i, 1)
switch when.get(i)
1 => countdn.set(i, countdn.get(i) + 1), when.set(i, 2)
2 => countdn.set(i, countdn.get(i) + 1), when.set(i, 3)
3 => countup.set(i, countup.get(i) + 1), when.set(i, 1)
var line id = na
var label lbl = na
id := line.new(
x
, y
, z
, y
, xloc = b1.xn
, color = css
, width = 1
, style = style
)
lbl := label.new(
int(math.avg(x, z))
, y
, txt
, color = invcol
, textcolor = css
, style = down ? label.style_label_down : label.style_label_up
, size = size
)
switch
b1.c > b1.o => boolean.set(green_candle, true)
b1.c < b1.o => boolean.set(red_candle , true)
switch
boolean.get(green_candle) => obv.up_bottom.push(obsec(low)),
obv.up_top.push(obsec(high)), obv.up_vol.push(math.abs(_v)),
obv.up_current_time.push(time), obv.up_last_time.push(time[1]),
obv.up_n.push(bar_index), obv.metric_up.push(upvol),
obv.metric_dn.push(math.abs(dnvol))
boolean.get(red_candle) => obv.dn_bottom.push(obsec(low)),
obv.dn_top.push(obsec(high)), obv.dn_vol.push(math.abs(_v)),
obv.dn_current_time.push(time), obv.dn_last_time.push(time[1]),
obv.dn_n.push(bar_index), obv.metric_up.push(upvol),
obv.metric_dn.push(math.abs(dnvol))
=> na
switch
ph_i => pp1.i_hpoint.clear(), pp1.i_nBull.clear(),
pp1.i_hpoint.push(b1.h[internal_r_lookback]),
pp1.i_nBull.push(b1.n[internal_r_lookback]),
pp1.up_ms_logs.push(b1.h[internal_r_lookback])
pl_i => pp1.i_lpoint.clear(), pp1.i_nBear.clear(),
pp1.i_lpoint.push(b1.l[internal_r_lookback]),
pp1.i_nBear.push(b1.n[internal_r_lookback]),
pp1.dn_ms_logs.push(b1.l[internal_r_lookback])
ph_s => pp1.s_hpoint.clear(), pp1.s_nBull.clear(),
pp1.s_hpoint.push(b1.h[swing_r_lookback]) ,
pp1.s_nBull.push(b1.n[swing_r_lookback]
)
pl_s => pp1.s_lpoint.clear(), pp1.s_nBear.clear(),
pp1.s_lpoint.push(b1.l[swing_r_lookback]) ,
pp1.s_nBear.push(b1.n[swing_r_lookback]
)
=> na
//-----------------------------------------------------------------------------{
// strcture set
//-----------------------------------------------------------------------------{
method structure(bin zz) =>
if true
//-------------------------------------------------------------------------
----{
//Internal structure bullish
//-------------------------------------------------------------------------
----{
if ta.crossover(b1.c, zz.i_hpoint.last())
bool choch = na
string txt = na
if itrend < 0
choch := true
switch
choch and not (zz.dn_ms_logs.last() >
zz.dn_ms_logs.get(zz.dn_ms_logs.indexof(zz.dn_ms_logs.last()) - 1)) => txt :=
"CHoCH"
choch and (zz.dn_ms_logs.last() >
zz.dn_ms_logs.get(zz.dn_ms_logs.indexof(zz.dn_ms_logs.last()) - 1)) => txt :=
"CHoCH+"
not choch
=> txt := "BOS"
itrend := 1
switch txt
"CHoCH" => css := i_ms_up_choch
"BOS" => css := i_ms_up_bos
"CHoCH+" => css := i_ms_up_choch
=> css
switch
ob_filter == "None" => bull_ob := true
ob_filter == "BOS" and txt == "BOS" => bull_ob := true
ob_filter == "CHoCH" and txt == "CHoCH" => bull_ob := true
ob_filter == "CHoCH+" and txt == "CHoCH+" => bull_ob := true
=> bull_ob := false
zz.i_nBull.clear ()
zz.i_hpoint.clear()
zz.i_bulltxt.push(txt)
if ta.crossunder(b1.c, zz.i_lpoint.last())
bool choch = na
string txt = na
if itrend > 0
choch := true
switch
choch and not (zz.up_ms_logs.last() <
zz.up_ms_logs.get(zz.up_ms_logs.indexof(zz.up_ms_logs.last()) - 1)) => txt :=
"CHoCH"
choch and (zz.up_ms_logs.last() <
zz.up_ms_logs.get(zz.up_ms_logs.indexof(zz.up_ms_logs.last()) - 1)) => txt :=
"CHoCH+"
not choch
=> txt := "BOS"
itrend := -1
switch txt
"CHoCH" => css := i_ms_dn_choch
"BOS" => css := i_ms_dn_bos
"CHoCH+" => css := i_ms_dn_choch
=> css
switch
ob_filter == "None" => bear_ob := true
ob_filter == "BOS" and txt == "BOS" => bear_ob := true
ob_filter == "CHoCH" and txt == "CHoCH" => bear_ob := true
ob_filter == "CHoCH+" and txt == "CHoCH+" => bear_ob := true
=> bear_ob := false
zz.i_nBear.clear ()
zz.i_lpoint.clear()
zz.i_beartxt.push(txt)
//-------------------------------------------------------------------------
----{
//Swing structure bullish
//-------------------------------------------------------------------------
----{
if zz.s_hpoint.size() > 0
if ta.crossover(b1.c, zz.s_hpoint.last())
bool choch = na
string txt = na
if trendPAC < 0
choch := true
css := i_ms_up_bos
zz.s_nBull.clear ()
zz.s_hpoint.clear()
if ob_swings
swing_up := true
//-------------------------------------------------------------------------
----{
//Swing structure bearish
//-------------------------------------------------------------------------
----{
if zz.s_lpoint.size() > 0
if ta.crossunder(b1.c, zz.s_lpoint.last())
bool choch = na
string txt = na
if trendPAC > 0
choch := true
zz.s_nBear.clear ()
zz.s_lpoint.clear()
if ob_swings
swing_dn := true
if show_mtb
upphl (trendPAC)
dnphl (trendPAC)
midphl( )
p_css = css
b_css = css
w_css = css
bull_fvg = false
bear_fvg = false
delta = (c1 - o1) / o1 * 100
change_tf = timeframe.change(fvg_tf)
threshold = 0
bull_fvg := l0 > h2 and c1 > h2 and delta > threshold and change_tf
bear_fvg := h0 < l2 and c1 < l2 and -delta > threshold and change_tf
if bull_fvg
fvg.bull_max.unshift(
box.new(
b1.n - 1
, l0
, b1.n + fvg_extend
, math.avg(l0, h2)
, border_color = bull_fvg_css
, bgcolor = bull_fvg_css)
)
fvg.bull_min.unshift(
box.new(
b1.n - 1
, math.avg(l0, h2)
, b1.n + fvg_extend
, h2
, border_color = bull_fvg_css
, bgcolor = bull_fvg_css)
)
if bear_fvg
fvg.bear_max.unshift(
box.new(
b1.n - 1
, h0
, b1.n + fvg_extend
, math.avg(h0, l2)
, border_color = bear_fvg_css
, bgcolor = bear_fvg_css)
)
fvg.bear_min.unshift(
box.new(
b1.n - 1
, l2
, b1.n + fvg_extend
, math.avg(h0, l2)
, border_color = bear_fvg_css
, bgcolor = bear_fvg_css)
)
for bx in fvg.bull_min
bx.delete()
fvg.bull_max.get(array.indexof(fvg.bull_min, bx)).delete()
for bx in fvg.bear_min
bx.delete()
fvg.bear_max.get(array.indexof(fvg.bear_min, bx)).delete()
if fvg_enable
if lvl_weekly
if lvl_monthly
if lvl_yearly
mtfphl(pyh , pyl , '12M', css_y, s_y)
if ob_show
if ob_swings
if(barcolor_bool == true)
if(dynamicStopLess==true)
if((not trigger and SellStop and showSignals) or (trigger and buyStop and
showSignals))
barColor := silver
else
barColor := b_css
else
barColor := b_css
else
if (momentumCandles and candlesMom())
if((not trigger and SellStop and showSignals) or (trigger and buyStop and
showSignals))
if((not trigger and SellStop and showSignals) or (trigger and buyStop
and showSignals))
if(dynamicStopLess==true)
barColor := silver
else
barColor := color.black
else
barColor := color.purple
else if (candleColors)
if (strategy == "Trend scalper")
barColor := colorBar
else if (na(countBull) and na(countBear))
barColor := color.gray
else
barColor := trigger ? green : red
if((not trigger and SellStop and showSignals) or (trigger and buyStop and
showSignals))
if(dynamicStopLess==true)
barColor := silver
barcolor(barColor, editable=false)
if barstate.isfirst
var table errorBox = table.new(position.bottom_left, 1, 1, bgcolor =
color.new(#363a45, 100))
table.cell(errorBox, 0, 0, "© MG Algo", text_color = color.gray,
text_halign = text.align_center, text_size = size.normal)