March 2, 2026

K

K

K

K

BTCUSDT Perpetual Contract BYBIT:BTCUSDT
maalialmwatn


K

//@version=4

study(title=”Binary System Ver.2 By Mahmoud Yahia”, overlay=true)

// number of candles used
distance = input(250, ‘Time range’, input.integer, minval=5, step=10)
// sensitivity when searching levels
sensitivity = input(1, ‘Sensitivity’, input.float, minval=0.1, step=0.1)
// weight coefficients
float wOpenClose = 1
float wHighLow = 0.5
float wCross = 0.5
// number of intervals
int n_intervals = 300
// block size (in intervals)
int block_size = 11

// how it works:
// price range from minimim to maximum on <distance> candles is
// divided into <n_intervals> equal intervals;
// <block_size> intervals make up one block;
// “weight” of the entire block is calculated as a sum of its intervals value;
// next level is set where local maximum of the sum has been reached;
// to prevent levels from going too often, “sensitivity” is introduced;
// there are two states: searching level and level found

// minimum and maximum values
float min_value = barstate.islast? low: 0
float max_value = barstate.islast? high: 0

// recalculate sensitivity according to the weights
float sens = barstate.islast?
2 / (sensitivity * (wOpenClose + wHighLow + wCross)) : 0

// calculate everything on the last bar
if barstate.islast
// number of “key points” falling into each interval
// last element is stored but not used
m = array.new_int(n_intervals + 1, 0)
// sum of the “scores” of the points falling into each interval
// last element is stored but not used
r = array.new_float(n_intervals + 1, 0)
// sums of the interval forming the block
a = array.new_float(block_size, 0)

// declaring variables
int i_close = na
int i_open = na
int i_high = na
int i_low = na
int mn = na
int mx = na
float interval_size = (max_value-min_value) / float(n_intervals)

// populate arrays r, m
for k = 1 to distance-1
i_close := floor((close-min_value) / interval_size)
i_open := floor((open-min_value) / interval_size)
i_high := floor((high-min_value) / interval_size)
i_low := floor((low-min_value) / interval_size)
array.set(r, i_close, array.get(r, i_close) + wOpenClose)
array.set(r, i_open, array.get(r, i_open) + wOpenClose)
array.set(r, i_high, array.get(r, i_high) + wHighLow)
array.set(r, i_low, array.get(r, i_low) + wHighLow)
array.set(m, i_close, array.get(m, i_close) + 1)
array.set(m, i_open, array.get(m, i_open) + 1)
array.set(m, i_high, array.get(m, i_high) + 1)
array.set(m, i_low, array.get(m, i_low) + 1)
// if current candle crosses the interval
if abs(i_open-i_close) >= 2
mn := min(i_open, i_close)
mx := max(i_open, i_close)
for i = mn+1 to mx-1
array.set(r, i, array.get(r, i) – wCross)
array.set(m, i, array.get(m, i) + 1)

// current block sum
float cur_block = 0
// last extremum
float extr_block = 0
// number of the first interval of extremum block
int extr_val = 0
// level value
float level_val = 0
// initial state: level search
bool state = false
// current interval sum
float cur_sum = 0
// iterate intervals
for i = 0 to n_intervals+block_size-2
// shift all the interval sums
array.shift(a)
if i < n_intervals
array.push(a, array.get(r, i) / array.get(m, i))
else
array.push(a, 0)
// current block sum
cur_block := array.sum(a)
// check state
if not state
// searching level: <extr_block> keeps the last maximum
if i == 0 or cur_block > extr_block
extr_block := cur_block
extr_val := i-block_size+1
else
// if we’ve gone far enough from the maximum downwards
if extr_block – cur_block >= sens or
i == n_intervals – 1
// draw level
level_val := min_value +
interval_size * (extr_val + float(block_size) / 2)
line.new(bar_index-1, level_val, bar_index, level_val,
style=line.style_solid, extend=extend.both,
color=color.blue, width=1)
extr_block := cur_block
extr_val := i-block_size+1
state := true
else
// level is found: <extr_block> keeps the last minimum
if cur_block < extr_block
extr_block := cur_block
extr_val := i-block_size+1
else
// if we’ve gone far enough from the minimum upwards
if cur_block – extr_block >= sens
extr_block := cur_block
extr_val := i-block_size+1
state := false
plotshape(barstate.islast, style=shape.circle, color=color.navy,
size=size.tiny, offset=-distance)

src2 = input(defval = close, title = “Source”)
len = input(defval = 100, title = “Length”, minval = 10)
devlen = input(defval = 1.6, title = “Deviation”, minval = 0.1, step = 0.1)
extendit = input(defval = true, title = “Extend Lines”)
showfibo = input(defval = false, title = “Show Fibonacci Levels”)
showbroken = input(defval = false, title = “Show Broken Channel”, inline = “brk”)
brokencol = input(defval = color.blue, title = “”, inline = “brk”)
upcol = input(defval = color.lime, title = “Up/Down Trend Colors”, inline = “trcols”)
dncol = input(defval = color.red, title = “”, inline = “trcols”)
widt = input(defval = 2, title = “Line Width”)

var fibo_ratios = array.new_float(0)
var colors = array.new_color(2)
if barstate.isfirst
array.unshift(colors, upcol)
array.unshift(colors, dncol)
array.push(fibo_ratios, 0.236)
array.push(fibo_ratios, 0.382)
array.push(fibo_ratios, 0.618)
array.push(fibo_ratios, 0.786)

get_channel(src2, len )=>
mid = sum(src2, len ) / len
slope = linreg(src2, len , 0) – linreg(src2, len , 1)
intercept = mid – slope * floor( len / 2) + ((1 – ( len % 2)) / 2) * slope
endy = intercept + slope * ( len – 1)
dev = 0.0
for x = 0 to len – 1
dev := dev + pow(src2 – (slope * ( len – x) + intercept), 2)
dev := sqrt(dev/ len )

= get_channel(src2, len )

outofchannel = (slope > 0 and close < y2_ – dev * devlen) ? 0 : (slope < 0 and close > y2_ + dev * devlen) ? 2 : -1

var reglines = array.new_line(3)
var fibolines = array.new_line(4)
for x = 0 to 2
if not showbroken or outofchannel != x or nz (outofchannel, -1) != -1
line.delete(array.get(reglines, x))
else
line.set_color(array.get(reglines, x), color = brokencol)
line.set_width(array.get(reglines, x), width = 3)
line.set_style(array.get(reglines, x), style = line.style_solid)
line.set_extend(array.get(reglines, x), extend = extend.none)

array.set(reglines, x,
line.new(x1 = bar_index – ( len – 1),
y1 = y1_ + dev * devlen * (x – 1),
x2 = bar_index,
y2 = y2_ + dev * devlen * (x – 1),
color = array.get(colors, round(max(sign(slope), 0))),
style = x % 2 == 1 ? line.style_solid : line.style_solid,
width = widt,
extend = extendit ? extend.right : extend.none))
if showfibo
for x = 0 to 3
line.delete(array.get(fibolines, x))
array.set(fibolines, x,
line.new(x1 = bar_index – ( len – 1),
y1 = y1_ – dev * devlen + dev * devlen * 2 * array.get(fibo_ratios, x),
x2 = bar_index,
y2 = y2_ – dev * devlen + dev * devlen * 2 * array.get(fibo_ratios, x),
color = array.get(colors, round(max(sign(slope), 0))),
style = line.style_solid,
width = widt,
extend = extendit ? extend.right : extend.none))

var label sidelab = label.new(x = bar_index – ( len – 1), y = y1_, text = “S”, size = size.large)
txt = slope > 0 ? slope > slope ? “⇑” : “⇗” : slope < 0 ? slope < slope ? “⇓” : “⇘” : “⇒”
stl = slope > 0 ? slope > slope ? label.style_label_up : label.style_label_upper_right : slope < 0 ? slope < slope ? label.style_label_down : label.style_label_lower_right : label.style_label_right
label.set_style(sidelab, stl )
label.set_text(sidelab, txt )
label.set_x(sidelab, bar_index – ( len – 1))
label.set_y(sidelab, slope > 0 ? y1_ – dev * devlen : slope < 0 ? y1_ + dev * devlen : y1_)
label.set_color(sidelab, slope > 0 ? upcol : slope < 0 ? dncol : color.blue)

alertcondition(outofchannel, title=’Channel Broken’, message=’Channel Broken’)

// direction
trendisup = sign(slope) != sign(slope) and slope > 0
trendisdown = sign(slope) != sign(slope) and slope < 0
alertcondition(trendisup, title=’Up trend has started’, message=’Up trend has started’)
alertcondition(trendisdown, title=’Down trend has started’, message=’Down trend has started’)

l = input(title=”period”, type=input.integer, defval=28)

t1 = input(title=”Ticker1″ , title=input.symbol, defval=”BINANCE:BTCUSDT” )
t2 = input(title=”Ticker2″ , title=input.symbol, defval=”BINANCE:ADABTC” )
t3 = input(title=”Ticker3″ , title=input.symbol, defval=”BINANCE:BCHBTC” )
t4 = input(title=”Ticker4″ , title=input.symbol, defval=”BINANCE:EOSBTC” )
t5 = input(title=”Ticker5″ , title=input.symbol, defval=”BINANCE:ETHBTC” )
t6 = input(title=”Ticker6″ , title=input.symbol, defval=”BINANCE:LTCBTC” )
t7 = input(title=”Ticker7″ , title=input.symbol, defval=”BINANCE:TRXBTC” )
t8 = input(title=”Ticker8″ , title=input.symbol, defval=”BINANCE:XRPBTC” )
t9 = input(title=”Ticker9″ , title=input.symbol, defval=”BINANCE:LINKBTC”)
t0 = input(title=”Ticker10″, title=input.symbol, defval=”BINANCE:YFIBTC” )

showscr = input(true, title=”Show Screener Label”)
posX_scr = input(20, title=”Pos. Label x-axis”)
posY_scr = input(1, title=”Pos. Size Label y-axis”)

colinput = input(title=”Label Color”, defval=”White”, options=)

col = color.gray
if colinput==”White”
col:=color.white
if colinput==”Black”
col:=color.black
if colinput==”Red”
col:=color.red
if colinput==”Green”
col:=color.green
if colinput==”Yellow”
col:=color.yellow
if colinput==”Blue”
col:=color.blue

HMA (l) =>
n2ma = 2 * wma (close, round(l / 2))
nma = wma (close, l)
diff = n2ma – nma
sqn = round(sqrt(l))
n2ma1 = 2 * wma (close, round(l / 2))
nma1 = wma (close, l)
diff1 = n2ma1 – nma1
sqn1 = round(sqrt(l))
h1 = wma (diff, sqn )
h2 = wma (diff1, sqn )

= HMA (l)

c = h1 > h2 ? color.green : color.red
ma = plot(h1, color=c, linewidth=2)
// ma2 = plot(h2, color=c, linewidth=2)

// Signals
turnGreen = h1 > h2 and h1 <= h2
turnRed = h1 <= h2 and h1 > h2

buy = turnGreen
sell = turnRed

plotshape(buy, style=shape.labelup, location=location.belowbar, color=color.blue, size=size.tiny, title=”buy label”, text=”Call”, textcolor=color.white)
plotshape(sell, style=shape.labeldown, location=location.abovebar, color=color.red, size=size.tiny, title=”sell label”, text=”Put”, textcolor=color.white)

= security(t1, timeframe.period, HMA (l))
= security(t2, timeframe.period, HMA (l))
= security(t3, timeframe.period, HMA (l))
= security(t4, timeframe.period, HMA (l))
= security(t5, timeframe.period, HMA (l))
= security(t6, timeframe.period, HMA (l))
= security(t7, timeframe.period, HMA (l))
= security(t8, timeframe.period, HMA (l))
= security(t9, timeframe.period, HMA (l))
= security(t0, timeframe.period, HMA (l))

tr01 = ( h101 > h201 and h101 <= h201 ) or ( h101 <= h201 and h101 > h201 )
tr02 = ( h102 > h202 and h102 <= h202 ) or ( h102 <= h202 and h102 > h202 )
tr03 = ( h103 > h203 and h103 <= h203 ) or ( h103 <= h203 and h103 > h203 )
tr04 = ( h104 > h204 and h104 <= h204 ) or ( h104 <= h204 and h104 > h204 )
tr05 = ( h105 > h205 and h105 <= h205 ) or ( h105 <= h205 and h105 > h205 )
tr06 = ( h106 > h206 and h106 <= h206 ) or ( h106 <= h206 and h106 > h206 )
tr07 = ( h107 > h207 and h107 <= h207 ) or ( h107 <= h207 and h107 > h207 )
tr08 = ( h108 > h208 and h108 <= h208 ) or ( h108 <= h208 and h108 > h208 )
tr09 = ( h109 > h209 and h109 <= h209 ) or ( h109 <= h209 and h109 > h209 )
tr10 = ( h110 > h210 and h110 <= h210 ) or ( h110 <= h210 and h110 > h210 )

up01 = h101 > h201 , dn01 = h101 < h201
up02 = h102 > h202 , dn02 = h102 < h202
up03 = h103 > h203 , dn03 = h103 < h203
up04 = h104 > h204 , dn04 = h104 < h204
up05 = h105 > h205 , dn05 = h105 < h205
up06 = h106 > h206 , dn06 = h106 < h206
up07 = h107 > h207 , dn07 = h107 < h207
up08 = h108 > h208 , dn08 = h108 < h208
up09 = h109 > h209 , dn09 = h109 < h209
up10 = h110 > h210 , dn10 = h110 < h210

Previous Article

CELOUSDT_Daily 4.5.2022

Next Article

Soul long

You might be interested in …

Bitcoin and Crypto

Bitcoin and Crypto

Bitcoin and Crypto Bitcoin / U. S. Dollar KRAKEN:BTCUSD nigel62e thoroughly deserve their inglorious fate – displaying the resolve of a bunch of feeble old women , when faced with a few “nasty Words” from […]

Bitcoin rally

Bitcoin rally

Bitcoin rally BTC/USD COINBASE:BTCUSD Coinathlon – Broke resistance, flipped support – Looking for a retracement to the support & .382 FIB level for a nice entry – MACD showing positive signs with a consistent histogram