Futures Algo SMC BETA AlgoPoint
Futures Algo SMC BETA AlgoPoint
0 at
https://mozilla.org/MPL/2.0/
//@version=5
indicator("Futures Algo SMC [BETA] [AlgoPoint]", overlay=true,
max_labels_count=500, max_lines_count=500)
// V43 is Smooth Version And last full version
// Constants
color CLEAR = color.rgb(0,0,0,100)
// Inputs
theme = input.string('Colored', 'Mode', ['Colored', 'Monochrome'], group = 'Theme')
barcoloring = input.bool(true, 'Bar Coloring', group = 'Theme')
swingSize = 10
bosConfType = 'Candle Close'
choch = true
showHalf = false
halfColor = #2927b0
halfStyle = 'Solid'
halfWidth = 1
//Colors
// Calculations
bool hh = false
bool lh = false
bool hl = false
bool ll = false
//Variable to track the previous swing type, used later on to draw 0.5 Retracement
Levels (HH = 2, LH = 1, HL = -1, LL = -2)
var int prevSwing = 0
if not na(pivHi)
if pivHi >= prevHigh
hh := true
prevSwing := 2
else
lh := true
prevSwing := 1
prevHigh := pivHi
highActive := true
prevHighIndex := bar_index - swingSize
if not na(pivLo)
if pivLo >= prevLow
hl := true
prevSwing := -1
else
ll := true
prevSwing := -2
prevLow := pivLo
lowActive := true
prevLowIndex := bar_index - swingSize
// Visual Output
// EQH/EQL
length_eqh = 7
n=bar_index
atrre = ta.atr(200)
show_equal_highlow = input(false, 'Equal Highs & Lows', group = 'Market
Structures',inline = 'equilibrium_zone')
eq_bear_color = bosbrokeup
eq_bull_color = bosbrokedown
eq_threshold = 0.10
label_sizes_s ="Small"
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
var high_eqh_pre = 0.,var eq_top_x = 0,var low_eqh_pre = 0.,var eq_btm_x = 0
if show_equal_highlow
high_eqh = ta.pivothigh(length_eqh, length_eqh)
low_eqh = ta.pivotlow(length_eqh, length_eqh)
if low_eqh
if math.min(low_eqh, low_eqh_pre) > math.max(low_eqh, low_eqh_pre) - atrre
* eq_threshold
eql_line = line.new(eq_btm_x, low_eqh_pre, n-length_eqh, low_eqh, color
= eq_bull_color, style = line.style_dotted)
eql_lbl = label.new(int(math.avg(n-length_eqh, eq_btm_x)), low_eqh,
'EQL', color = #00000000, textcolor = eq_bull_color, style = label.style_label_up,
size = label_size_buysell)
low_eqh_pre := low_eqh
eq_btm_x := n-length_eqh
if high_eqh
if math.max(high_eqh, high_eqh_pre) < math.min(high_eqh, high_eqh_pre) +
atrre * eq_threshold
eqh_line = line.new(eq_top_x, high_eqh_pre, n-length_eqh, high_eqh,
color = eq_bear_color, style = line.style_dotted)
eqh_lbl = label.new(int(math.avg(n-length_eqh, eq_top_x)), high_eqh,
'EQH', color = #00000000, textcolor = eq_bear_color, style =
label.style_label_down, size = label_size_buysell)
high_eqh_pre := high_eqh
eq_top_x := n-length_eqh
// Trendlines
// Trendlines
gr5 = 'Trendlines'
showPriceTl = false
newestTL = true
newestBreak = true
periodlen = input.string('Adaptive', 'Trendline Term', ['Long Term', 'Short
Term','Adaptive'])
period = (periodlen == 'Adaptive' ? 30 : periodlen == 'Long Term' ? 40 : periodlen
== 'Short Term' ? 20 : 0)
//period = input(30, 'Trendline Period')
srcI = input.string('Wick', 'TrendLine Source', ['Close Body', 'Wick'])
srcL = srcI=='Wick'? low : close
srcH = srcI=='Wick'? high : close
lStyleI = input.string('Solid', 'TrendLine Style', ['Solid', 'Dashed',
'Dotted'])
y2_mult = 1
lStyle = lStyleI=='Solid'? line.style_solid : lStyleI=='Dashed'?
line.style_dashed : line.style_dotted
lWidth = input(2, 'TrendLine Width')
lColor = trendlinescolor
supTextCol = color.red
resTextCol = color.blue
truncate(number) =>
factor = math.pow(10, dec)
int(number * factor) / factor
EndTime = timestamp('19 Jan 2022 00:00 +0000')
inDateRange = time<=EndTime
x1 = ta.valuewhen(cond_, time[x1Bar_], 0)
x2 = ta.valuewhen(cond_, time[x2Bar_], 0)
y1 = ta.valuewhen(cond_, y1Val_, 0)
y2 = ta.valuewhen(cond_, y2Val_, 0)
slope_ = ta.valuewhen(cond_, (y2-y1)/(x2-x1), 0)
a_trendline
// FVG
showfvg = input.bool(true, 'Show FVG', tooltip='Show or hide Fair Value Gaps',
group = 'Fair Value Gap')
f_choppedoffimb(imbboxarray) =>
if array.size(imbboxarray) > 0
for i = array.size(imbboxarray) - 1 to 0 by 1
cutbox = array.get(imbboxarray, i)
boxhighzone = box.get_top(cutbox)
boxlowzone = box.get_bottom(cutbox)
boxrightzone = box.get_right(cutbox)
boxleftzone = box.get_left(cutbox)
if na or bar_index - 1 == boxrightzone and (high > boxlowzone and high
< boxhighzone )
box.set_bottom(cutbox, high)
box.set_bgcolor(cutbox, boxcolor_filled)
box.set_right(cutbox, bar_index)
BOX1 = box.new(left=boxleftzone, top=high, right=bar_index,
bottom=boxlowzone)
box.set_bgcolor(BOX1, boxcolor_filled )
box.set_border_color(BOX1, #00000000 )
// else if na or bar_index - 1 == boxrightzone and high < boxlowzone
// box.set_right(cutbox, bar_index)
else if na or bar_index - 1 == boxrightzone and (low > boxlowzone and
low < boxhighzone )
box.set_top(cutbox, low)
box.set_bgcolor(cutbox, boxcolor_filled)
box.set_right(cutbox, bar_index)
BOX2 = box.new(left=boxleftzone, top=low, right=bar_index,
bottom=boxhighzone)
box.set_bgcolor(BOX2, boxcolor_filled)
box.set_border_color(BOX2, #00000000 )
else if na or bar_index - 1 == boxrightzone and not(high > boxlowzone
and low < boxlowzone or high > boxhighzone and low < boxhighzone)
box.set_right(array.get(imbboxarray, i), bar_index)
if high > boxhighzone
box.set_bgcolor(cutbox, boxcolor_bullish)
else if low < boxlowzone
box.set_bgcolor(cutbox, boxcolor_bearish)
f_choppedoffimb(imbboxarray)
// Order Blocks
// { <CONSTANTS>
OB_BORDER_WIDTH = 2
// } <CONSTANTS>
// { <INPUTS>
tuning = input.int(
title = "Sensitivity",
defval = 8,
group = "Order Block")
amountOfBoxes = input.int(
title = "Amount Of Grids",
defval = 3,
group = "Order Block")
mitigationMethod = input.string(
title = "Mitigation Method",
defval = "Close Engulfs 100% Of Order Block",
group = "Order Block",
inline = "mitigation",
options = [
"Close Engulfs 100% Of Order Block",
"Close Engulfs 75% Of Order Block",
"Close Engulfs 50% Of Order Block",
"Close Engulfs 25% Of Order Block",
"Wick Engulfs 100% Of Order Block",
"Wick Engulfs 75% Of Order Block",
"Wick Engulfs 50% Of Order Block",
"Wick Engulfs 25% Of Order Block"])
obHighVolumeColor = obhvc
obLowVolumeColor = oblvc
obBorderColor = obbc
obLinefillColor = oblfc
// } <INPUTS>
// { <FUNCTIONS>
checkObCondition(set)=>
bear = false
for i = tuning - 1 to 0
start = tuning - 1
if i == start
if close[i] <= open[i]
break
else
if close[i] > open[i]
break
if i == 0
bear := true
bull = false
for i = tuning - 1 to 0
start = tuning - 1
if i == start
if close[i] >= open[i]
break
else
if close[i] < open[i]
break
if i == 0
bull := true
[bear, bull]
// } <FUNCTIONS>
type orderBlock
line topLine
line botLine
linefill bgFill
array<box> boxArray = na
array<float> boxVolume = na
float topValue
float botValue
int leftTime
int rightTime
string direction
highestVolume = array.max(self.boxVolume)
lowestVolume = array.min(self.boxVolume)
timeLength = self.rightTime - self.leftTime
timeRatio = timeLength / highestVolume
startingValue = topValue
increment = (topValue - botValue) / amountOfBoxes
for i = 0 to amountOfBoxes - 1
topOfGrid = startingValue - (increment * i)
botOfGrid = startingValue - (increment * (i + 1))
color_ = color.from_gradient(array.get(self.boxVolume, i), lowestVolume,
highestVolume, obLowVolumeColor, obHighVolumeColor)
newbox = box.new(left = self.leftTime, top = topOfGrid, right =
self.leftTime + math.round(array.get(self.boxVolume, i) * timeRatio), bottom =
botOfGrid, border_color = color_, border_width = 2, xloc = xloc.bar_time, bgcolor =
color_, extend = extend.none)
array.push(newBoxesArray, newbox)
self.boxArray := newBoxesArray
highestVolume = array.max(self.boxVolume)
lowestVolume = array.min(self.boxVolume)
timeLength = self.rightTime - self.leftTime
timeRatio = timeLength / highestVolume
for i = 0 to amountOfBoxes - 1
box.set_right(array.get(self.boxArray, i), self.leftTime +
math.round(array.get(self.boxVolume, i) * timeRatio))
line.set_x2(self.topLine, self.rightTime)
line.set_x2(self.botLine, self.rightTime)
// { <CALCULATIONS>
// } <CALCULATIONS>
// Liquidity
//Settings
//-----------------------------------------------------------------------------{
//liqGrp = 'Liquidity Detection'
//liqLen = input.int (13, title = 'Detection Length', minval = 3, maxval = 13,
inline = 'LIQ', group = liqGrp)
//liqMar = 10 / input.float (6.9, 'Margin', minval = 4, maxval = 9, step = 0.1,
inline = 'LIQ', group = liqGrp)
//lqVoid = false
//cLQV_B = buysidecolor
//cLQV_S = selsidecolor
//lqText = false
//mode = 'Present'
//visLiq = 3
//-----------------------------------------------------------------------------}
//General Calculations
//-----------------------------------------------------------------------------{
//maxSize = 50
//atr = ta.atr(10)
//atr200 = ta.atr(200)
//per = mode == 'Present' ? last_bar_index - bar_index <= 500 : true
//type ZZ
//int [] d
//int [] x
//float [] y
////////
//type bar
//float o = open
//float h = high
//float l = low
//float c = close
//int i = bar_index
//////
//type liq
//box bx
//box bxz
//box bxt
//bool brZ
//bool brL
//line ln
//line lne
//-----------------------------------------------------------------------------}
//Variables
//-----------------------------------------------------------------------------{
//var ZZ aZZ = ZZ.new(
//array.new <int> (maxSize, 0),
//array.new <int> (maxSize, 0),
//array.new <float>(maxSize, na)
//)
//bar b = bar.new()
//var int dir = na, var int x1 = na, var float y1 = na, var int x2 = na, var float
y2 = na
//-----------------------------------------------------------------------------}
//Functions/methods
//-----------------------------------------------------------------------------{
//method in_out(ZZ aZZ, int _d, int _x, float _y) =>
//aZZ.d.unshift(_d), aZZ.x.unshift(_x), aZZ.y.unshift(_y), aZZ.d.pop(),
aZZ.x.pop(), aZZ.y.pop()
//////
//max_bars_back(time, 1000)
//-----------------------------------------------------------------------------}
//Calculations
//-----------------------------------------------------------------------------{
//x2 := b.i - 1
//ph = ta.pivothigh(liqLen, 1)
//pl = ta.pivotlow (liqLen, 1)
//if ph
//dir := aZZ.d.get(0)
//x1 := aZZ.x.get(0)
//y1 := aZZ.y.get(0)
//y2 := nz(b.h[1])
//if per
//count = 0
//st_P = 0.
//st_B = 0
//minP = 0.
//maxP = 10e6
//for i = 0 to maxSize - 1
//if aZZ.d.get(i) == 1
//if aZZ.y.get(i) > ph + (atr / liqMar)
//break
//else
//if aZZ.y.get(i) > ph - (atr / liqMar) and aZZ.y.get(i) < ph +
(atr / liqMar)
//count += 1
//st_B := aZZ.x.get(i)
//st_P := aZZ.y.get(i)
//if aZZ.y.get(i) > minP
//minP := aZZ.y.get(i)
//if aZZ.y.get(i) < maxP
//maxP := aZZ.y.get(i)
//if pl
//dir := aZZ.d.get (0)
//x1 := aZZ.x.get (0)
//y1 := aZZ.y.get (0)
//y2 := nz(b.l[1])
//if per
//count = 0
//st_P = 0.
//st_B = 0
//minP = 0.
//maxP = 10e6
//for i = 0 to maxSize - 1
//if aZZ.d.get(i) == -1
//if aZZ.y.get(i) < pl - (atr / liqMar)
//break
//else
//if aZZ.y.get(i) > pl - (atr / liqMar) and aZZ.y.get(i) < pl +
(atr / liqMar)
//count += 1
//st_B := aZZ.x.get(i)
//st_P := aZZ.y.get(i)
//if aZZ.y.get(i) > minP
//minP := aZZ.y.get(i)
//if aZZ.y.get(i) < maxP
//maxP := aZZ.y.get(i)
//else if x.brZ
//if b.l > x.ln.get_y1() - marBuy * (atr) and b.h < x.ln.get_y1() + marBuy
* (atr)
//x.bxz.set_right(b.i + 1)
//x.bxz.set_top(math.max(b.h, x.bxz.get_top()))
//if liqBuy
//x.lne.set_x2(b.i + 1)
//else
//x.brZ := false
//for i = 0 to b_liq_S.size() - 1
//x = b_liq_S.get(i)
//x.bxz.set_lefttop(b.i - 1, x.ln.get_y1())
//x.bxz.set_rightbottom(b.i + 1, math.max(x.ln.get_y1() - marSel *
(atr), b.l))
//x.bxz.set_bgcolor(color.new(cLIQ_S, 100))
//else if x.brZ
//if b.l > x.ln.get_y1() - marSel * (atr) and b.h < x.ln.get_y1() + marSel
* (atr)
//x.bxz.set_rightbottom(b.i + 1, math.min(b.l, x.bxz.get_bottom()))
//if liqSel
//x.lne.set_x2(b.i + 1)
//else
//x.brZ := false
// Multi-Timeframe S/R
sr_line_trans = 30
sr_trackprice = true
left = 5
right = 5
line_width = 3
sr_color = srcolor
c_white = srcolor
float level1 = na
float level2 = na
float level3 = na
float level4 = na
float level5 = na
float level6 = na
float level7 = na
float level8 = na
float level9 = na
float level0 = na
float level15m = na
float level15m1 = na
float level5m = na
float level5m1 = na
if activeATF
level1 := ta.valuewhen(ta.pivothigh(close, left, right), close[right], 0)
level2 := ta.valuewhen(ta.pivotlow(close, left, right), close[right], 0)
if timeframe.isintraday
if active4h
level3 := pivot_tf_high('240', close, left, right, 0)
level4 := pivot_tf_low('240', close, left, right, 0)
if active1h
level5 := pivot_tf_high('60', close, left, right, 0)
level6 := pivot_tf_low('60', close, left, right, 0)
if active30m
level7 := pivot_tf_high('30', close, left, right, 0)
level8 := pivot_tf_low('30', close, left, right, 0)
if active15m
level15m := pivot_tf_high('15', close, left, right, 0)
level15m1 := pivot_tf_low('15', close, left, right, 0)
if active5m
level5m := pivot_tf_high('5', close, left, right, 0)
level5m1 := pivot_tf_low('5', close, left, right, 0)
if activeD
level9 := pivot_tf_high('D', close, left, right, 0)
level0 := pivot_tf_low('D', close, left, right, 0)
level0
if barstate.islast
create_line_label(level1, level2, "ATF")
create_line_label(level3, level4, "H4")
create_line_label(level5, level6, "H1")
create_line_label(level7, level8, "M30")
create_line_label(level15m, level15m1, "M15")
create_line_label(level5m, level5m1, "M5")
create_line_label(level0, level9, "D")
// Bar Color
// Input
fastLength = 12
slowLength = 26
srcre = close
signalLength = 9
// Data reference
[macd, signal, hist] = ta.macd(srcre, fastLength, slowLength, signalLength)
// 4 level of green
greenHigh = #05df09
greenMidHigh = #05df09
greenMidLow = #388E3C
greenLow = #5f3a97
// Yellow
yellowLow = #5f3a97
// 4 level of red
redHigh = #ea0402
redMidHigh = #ea0402
redMidLow = #cc0402
redLow = #5f3a97
// Default color
candleBody = yellowLow
// Ranging trend
if hist > 0
if hist > hist[1] and hist[1] > 0
candleBody := greenLow
if hist < 0
if hist < hist[1] and hist[1] < 0
candleBody := redLow
// Bullish trend
if macd > 0 and hist > 0
candleBody := greenMidLow
if hist > hist[1] and macd[1] > 0 and hist[1] > 0
candleBody := greenMidHigh
// Bearish trend
if macd < 0 and hist < 0
candleBody := redMidLow
// MTF S/R //
group = "MULTI-TIMEFRAME S/R AREA (Beta Feature)"
showSR = input.bool(true, title = "", inline = "01", group=group)
timef = input.timeframe("", "", inline = "01", group=group)
levels = input.int(7 , "Levels", inline = "01", group = group)
linewidth = input.int(1, "Width", inline = "02", group = group) * 20
supportcolor = (theme == 'Colored' ? #0089774b : #d1d4dc4b)
resistancecolor = (theme == 'Colored' ? #b228344b : #d1d4dc4b)
labelon = input.string("On", "Label", ["On", "Off"], inline = "03",
group = group)
labelsize = input.string("Default", "Size", ["Small", "Default",
"Large"], inline = "03", group = group)
labelcol = input.color(#787b86, "", inline = "03", group = group)
labelloc = input.int(10, "Offset", inline = "04", group = group) + 30
showtimef = input.bool(true, "Show Timeframe", inline = "04", group =
group)
showtprice = input.bool(true, "Show Price", inline = "04", group = group)
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
//included?
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
if phsa or plsa
//because of new calculation, remove old S/R levels
array.clear(sr_up_level)
array.clear(sr_dn_level)
array.clear(sr_strength)
//find S/R zones
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 strength is in first levels sr then insert it to the arrays
if loc < levels and strength >= min_strength
array.insert(sr_strength, loc, strength)
array.insert(sr_up_level, loc, hi)
array.insert(sr_dn_level, loc, lo)
// keep size of the arrays = 5
if array.size(sr_strength) > levels
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))
label.delete(array.get(sr_labels, x))
label.delete(array.get(timef_labels, x))
f_crossed_over() =>
ret = false
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)
if close[1] <= mid and close > mid
ret := true
ret
ret
f_crossed_under() =>
ret = false
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)
if close[1] >= mid and close < mid
ret := true
ret
ret