Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 10

//@version=5

indicator('Easy money with IMB, EntryTime', overlay=true, max_lines_count=200,


max_boxes_count=200, max_labels_count=200, max_bars_back=500,
explicit_plot_zorder=true)

// ------------------------
// Group
// ------------------------
g0 = '//Session Settings//'
g1_01 = '// ♯1 SESSION //'
g1_02 = '// ♯2 SESSION //'
g1_03 = '// ♯3 SESSION //'
g1_04 = '// ♯4 SESSION //'
g1_05 = '// ♯5 SESSION //'
g1_06 = '// ♯6 SESSION //'
g1_07 = '// ♯7 SESSION //'
g1_08 = '// ♯8 SESSION //'
g1_09 = '// ♯9 SESSION //'
g1_10 = '// ♯10 SESSION //'
g4 = '// EMA200 //'

TRANSPARENT = color.new(color.black, 100)

tf1 = timeframe.period=='1'

// ------------------------
// Input
// ------------------------

tz = input.string('GMT+7', title='Timezone', options=['GMT-


11', 'GMT-10', 'GMT-9', 'GMT-8', 'GMT-7', 'GMT-6', 'GMT-5', 'GMT-4', 'GMT-3', 'GMT-
2', 'GMT-1', 'GMT+0', 'GMT+1', 'GMT+2', 'GMT+3', 'GMT+330', 'GMT+4', 'GMT+430',
'GMT+5', 'GMT+530', 'GMT+6', 'GMT+7', 'GMT+8', 'GMT+9', 'GMT+10', 'GMT+11',
'GMT+12'], group=g0)
text_size = input.string('small', 'Text Size', options=['tiny',
'small', 'normal', 'large', 'huge', 'auto'], group=g0)
text_Hali = input.string('center', 'Text Alignment',
options=['center', 'left', 'right'], group=g0)
extZone = input.int(defval=400, minval=10, maxval=1000, step=1,
title="Session Length", group=g0)
history = input.int(defval=0, minval=0, maxval=1000, step=1,
title="History Day", group=g0)
text_Color = input.color(color.red, 'Text Color', group=g0)
alertS = input.bool(true, 'Alert the trading session has opened',
group=g0)

ema_0 = input.color(color.orange, 'EMA 21 1m', inline = '0',


group=g4)
show_ema_0 = input.bool(true, " ", inline = "0", group=g4)
ema_1 = input.color(color.blue, 'EMA 200 1m', inline = '1',
group=g4)
show_ema_1 = input.bool(true, " ", inline = "1", group=g4)
ema_2 = input.color(color.red, 'EMA 200 5m', inline = '2',
group=g4)
show_ema_2 = input.bool(true, " ", inline = "2", group=g4)
ema_3 = input.color(color.purple, 'EMA 21 1D ', inline = '3',
group=g4)
show_ema_3 = input.bool(true, " ", inline = "3", group=g4)
// Sessions
i_show_sess1 = input.bool(true, 'Session 1 ', group=g1_01,
inline='session1_1')
i_sess1_label = input.string('08:30', '', group=g1_01,
inline='session1_1')
i_sess1_color = input.color(#66D9EF, 'Box color', group=g1_01,
inline='session1_1')
i_sess1 = input.session('0830-0831', 'Time', group=g1_01)

i_show_sess2 = input.bool(true, 'Session 2 ', group=g1_02,


inline='session2_1')
i_sess2_label = input.string('13:00', '', group=g1_02,
inline='session2_1')
i_sess2_color = input.color(#1081FF, 'Box color', group=g1_02,
inline='session2_1')
i_sess2 = input.session('1300-1301', 'Time', group=g1_02)

i_show_sess3 = input.bool(true, 'Session 3 ', group=g1_03,


inline='session3_1')
i_sess3_label = input.string('14:00', '', group=g1_03,
inline='session3_1')
i_sess3_color = input.color(#1081FF, 'Box color', group=g1_03,
inline='session3_1')
i_sess3 = input.session('1400-1401', 'Time', group=g1_03)

i_show_sess4 = input.bool(true, 'Session 4 ', group=g1_04,


inline='session4_1')
i_sess4_label = input.string('16:30', '', group=g1_04,
inline='session4_1')
i_sess4_color = input.color(#FD971F,'Box color', group=g1_04,
inline='session4_1')
i_sess4 = input.session('1630-1631', 'Time', group=g1_04)

i_show_sess5 = input.bool(true, 'Session 5 ', group=g1_05,


inline='session5_1')
i_sess5_label = input.string('19:00', '', group=g1_05,
inline='session5_1')
i_sess5_color = input.color(#07b354, 'Box color', group=g1_05,
inline='session5_1')
i_sess5 = input.session('1900-1901', 'Time', group=g1_05)

i_show_sess6 = input.bool(true, 'Session 6 ', group=g1_06,


inline='session6_1')
i_sess6_label = input.string('20:30', '', group=g1_06,
inline='session6_1')
i_sess6_color = input.color(#ae81ff,'Box color', group=g1_06,
inline='session6_1')
i_sess6 = input.session('2030-2031', 'Time', group=g1_06)

i_show_sess7 = input.bool(true, 'Session 7 ', group=g1_07,


inline='session7_1')
i_sess7_label = input.string('22:30', '', group=g1_07,
inline='session7_1')
i_sess7_color = input.color(#1081FF, 'Box color', group=g1_07,
inline='session7_1')
i_sess7 = input.session('2230-2231', 'Time', group=g1_07)
i_show_sess8 = input.bool(true, 'Session 8 ', group=g1_08,
inline='session8_1')
i_sess8_label = input.string('00:30', '', group=g1_08,
inline='session8_1')
i_sess8_color = input.color(#1081FF, 'Box color', group=g1_08,
inline='session8_1')
i_sess8 = input.session('0030-0031', 'Time', group=g1_08)

// ------------------------
// Type and method
// ------------------------

type Session
string sess
string tz
string name
color colour
box[] boxes
int session

method create (Session this) =>


this.boxes := array.new<box>()
this

method session (Session this) =>


time("1", this.sess, this.tz)

// ------------------------
// Session
// ------------------------

draw (_show, Session data) =>


session = data.session()
col = data.colour
name = data.name
is_started = na(session[1]) and not na(session)
if _show and is_started
if data.boxes.size() > history
ele = data.boxes.get(0)
box.delete(ele)
data.boxes.shift()

my_box = box.new(bar_index, low, bar_index + extZone, high, col, 1,


line.style_dashed, bgcolor=color.new(col, 85), text = name, text_size = text_size,
text_halign = text_Hali, text_color = text_Color)
array.push(data.boxes, my_box)

var sess1_data = Session.new(i_sess1, tz, i_sess1_label, i_sess1_color).create()


var sess2_data = Session.new(i_sess2, tz, i_sess2_label, i_sess2_color).create()
var sess3_data = Session.new(i_sess3, tz, i_sess3_label, i_sess3_color).create()
var sess4_data = Session.new(i_sess4, tz, i_sess4_label, i_sess4_color).create()
var sess5_data = Session.new(i_sess5, tz, i_sess5_label, i_sess5_color).create()
var sess6_data = Session.new(i_sess6, tz, i_sess6_label, i_sess6_color).create()
var sess7_data = Session.new(i_sess7, tz, i_sess7_label, i_sess7_color).create()
var sess8_data = Session.new(i_sess8, tz, i_sess8_label, i_sess8_color).create()

if tf1
draw(i_show_sess1, sess1_data)
draw(i_show_sess2, sess2_data)
draw(i_show_sess3, sess3_data)
draw(i_show_sess4, sess4_data)
draw(i_show_sess5, sess5_data)
draw(i_show_sess6, sess6_data)
draw(i_show_sess7, sess7_data)
draw(i_show_sess8, sess8_data)

// ------------------------
// Ema
// ------------------------

drawLiveEma(bool condition, float y, color co, string txt) =>


x = time
if barstate.islast and condition and tf1
lbl = label.new(x, y, txt, xloc.bar_time, color = TRANSPARENT, textcolor =
co, style = label.style_label_left, size = size.small)
label.delete(lbl[1])

ema21_1m = ta.ema(close, 21)


ema200_1m = ta.ema(close, 200)
ema200_5m = request.security(syminfo.tickerid, '5', ta.ema(close, 200), lookahead =
barmerge.lookahead_on)
ema21_1D = request.security(syminfo.tickerid, 'D', ta.ema(close, 21), lookahead =
barmerge.lookahead_on)
smooth_ema200_5m = ta.sma(ema200_5m, 5)
smooth_ema21_1D = ta.sma(ema21_1D, 1440)

plot(show_ema_0 and tf1 ? ema21_1m : na, color=ema_0, linewidth=1, title='EMA21


1m')
plot(show_ema_1 and tf1 ? ema200_1m : na, color=ema_1, linewidth=1, title='EMA200
1m')
plot(show_ema_2 and tf1 ? smooth_ema200_5m : na, color=ema_2, linewidth=1,
title='EMA200 5m')
plot(show_ema_3 and tf1 ? smooth_ema21_1D : na, color=ema_3, linewidth=1,
title='EMA21 1D')
drawLiveEma(show_ema_0, ema21_1m, ema_0, 'EMA 21 1m')
drawLiveEma(show_ema_1, ema200_1m, ema_1, 'EMA 200 1m')
drawLiveEma(show_ema_2, smooth_ema200_5m, ema_2, 'EMA 200 5m')
drawLiveEma(show_ema_3, smooth_ema21_1D, ema_3, 'EMA 21 1D')

// ------------------------
// Alert
// ------------------------
alertSession(sess, string lbl, bool show) =>
if not na(time(timeframe.period, sess, tz)) and show and alertS
alert('The ' + lbl + ' trading session has opened')

alertSession(i_sess1, i_sess1_label, i_show_sess1)


alertSession(i_sess2, i_sess2_label, i_show_sess2)
alertSession(i_sess3, i_sess3_label, i_show_sess3)
alertSession(i_sess4, i_sess4_label, i_show_sess4)
alertSession(i_sess5, i_sess5_label, i_show_sess5)
alertSession(i_sess6, i_sess6_label, i_show_sess6)
alertSession(i_sess7, i_sess7_label, i_show_sess7)
alertSession(i_sess8, i_sess8_label, i_show_sess8)
////////////////////
//------------------------------------------------------------------------------
//Settings
//------------------------------------------------------------------------------{
//Fair Value Gaps
show_fvg = input(true, 'Fair Value Gaps (FVG)', inline='fvg_css', group='Fair Value
Gaps')
bull_fvg_css = input.color(#2157f3, '', inline='fvg_css', group='Fair Value Gaps')
bear_fvg_css = input.color(#ff1100, '', inline='fvg_css', group='Fair Value Gaps')
fvg_usewidth = input(false, 'Min Width', inline='fvg_width', group='Fair Value
Gaps')
fvg_gapwidth = input.float(0, '', inline='fvg_width', group='Fair Value Gaps')
fvg_method = input.string('Points', '', options=['Points', '%', 'ATR'],
inline='fvg_width', group='Fair Value Gaps')
fvg_extend = input.int(0, 'Extend FVG', minval=0, group='Fair Value Gaps')

//Opening Gaps
show_og = input(true, 'Show Opening Gaps (OG)', inline='og_css', group='Opening
Gaps')
bull_og_css = input.color(#2157f3, '', inline='og_css', group='Opening Gaps')
bear_og_css = input.color(#ff1100, '', inline='og_css', group='Opening Gaps')
og_usewidth = input(false, 'Min Width', inline='og_width', group='Opening Gaps')
og_gapwidth = input.float(0, '', inline='og_width', group='Opening Gaps')
og_method = input.string('Points', '', options=['Points', '%', 'ATR'],
inline='og_width', group='Opening Gaps')
og_extend = input.int(0, 'Extend OG', minval=0, group='Opening Gaps')

//Volume Imbalance
show_vi = input(true, 'Show Volume Imbalances (VI)', inline='vi_css', group='Volume
Imbalance')
bull_vi_css = input.color(#2157f3, '', inline='vi_css', group='Volume Imbalance')
bear_vi_css = input.color(#ff1100, '', inline='vi_css', group='Volume Imbalance')
vi_usewidth = input(false, 'Min Width', inline='vi_width', group='Volume
Imbalance')
vi_gapwidth = input.float(0, '', inline='vi_width', group='Volume Imbalance')
vi_method = input.string('Points', '', options=['Points', '%', 'ATR'],
inline='vi_width', group='Volume Imbalance')
vi_extend = input.int(5, 'Extend VI', minval=0, group='Volume Imbalance')

// ------------------------
// Dashboard
// ------------------------
show_dash = input(false, 'Show Dashboard', group='Dashboard')
dash_loc = input.string('Bottom Right', 'Dashboard Location', options=['Top Right',
'Bottom Right', 'Bottom Left'], group='Dashboard')
dashboard_text_size = input.string('Tiny', 'Dashboard Size', options=['Tiny',
'Small', 'Normal'], group='Dashboard')

//------------------------------------------------------------------------------}

//------------------------------------------------------------------------------
//Functions
//------------------------------------------------------------------------------{
n = bar_index
atr = ta.atr(200)

//Detect imbalance and return count over time


imbalance_detection(show, usewidth, method, width, top, btm, condition) =>
var is_width = true
var count = 0
if usewidth
dist = top - btm
is_width := switch method
'Points' => dist > width
'%' => dist / btm * 100 > width
'ATR' => dist > atr * width

is_true = show and condition and is_width


count += is_true ? 1 : 0
[is_true, count]

//Detect if bullish imbalance is filled and return count over time


bull_filled(condition, btm) =>
var btms = array.new_float(0)
var count = 0

if condition
array.unshift(btms, btm)

size = array.size(btms)

for i = (size > 0 ? size-1 : na) to 0


value = array.get(btms, i)
if low < value
array.remove(btms, i)
count += 1

count

//Detect if bearish imbalance is filled and return count over time


bear_filled(condition, top) =>
var tops = array.new_float(0)
var count = 0

if condition
array.unshift(tops, top)

size = array.size(tops)

for i = (size > 0 ? size-1 : na) to 0


value = array.get(tops, i)
if high > value
array.remove(tops, i)
count += 1

count

//Set table data cells


set_cells(tb, column, bull_filled, bull_count, bear_filled, bear_count, bull_css,
bear_css, table_size) =>
table.cell(tb, column, 1, str.tostring(bull_count), text_color=bull_css,
text_size=table_size, text_halign=text.align_left)
table.cell(tb, column, 2, str.format('{0,number,percent}', bull_filled /
bull_count), text_color=bull_css, text_size=table_size,
text_halign=text.align_left)
table.cell(tb, column, 3, str.tostring(bear_count), text_color=bear_css,
text_size=table_size, text_halign=text.align_left)
table.cell(tb, column, 4, str.format('{0,number,percent}', bear_filled /
bear_count), text_color=bear_css, text_size=table_size,
text_halign=text.align_left)

//------------------------------------------------------------------------------}

//------------------------------------------------------------------------------
//Volume Imbalances
//------------------------------------------------------------------------------{
//Bullish
bull_gap_top = math.min(close, open)
bull_gap_btm = math.max(close[1], open[1])
[bull_vi, bull_vi_count] = imbalance_detection(show_vi, vi_usewidth, vi_method,
vi_gapwidth, bull_gap_top, bull_gap_btm, open > close[1] and high[1] > low and
close > close[1] and open > open[1] and high[1] < bull_gap_top)
bull_vi_filled = bull_filled(bull_vi[1], bull_gap_btm[1])

//Bearish
bear_gap_top = math.min(close[1], open[1])
bear_gap_btm = math.max(close, open)
[bear_vi, bear_vi_count] = imbalance_detection(show_vi, vi_usewidth, vi_method,
vi_gapwidth, bear_gap_top, bear_gap_btm, open < close[1] and low[1] < high and
close < close[1] and open < open[1] and low[1] > bear_gap_btm)
bear_vi_filled = bear_filled(bear_vi[1], bear_gap_top[1])

if bull_vi
box.new(n-1, bull_gap_top, n + vi_extend, bull_gap_btm,
border_color=bull_vi_css, bgcolor=na, border_style=line.style_dotted)

if bear_vi
box.new(n-1, bear_gap_top, n + vi_extend, bear_gap_btm,
border_color=bear_vi_css, bgcolor=na, border_style=line.style_dotted)
//------------------------------------------------------------------------------}

//------------------------------------------------------------------------------
//Opening Gaps
//------------------------------------------------------------------------------{
//Bullish
[bull_og, bull_og_count] = imbalance_detection(show_og, og_usewidth, og_method,
og_gapwidth, bull_gap_top, bull_gap_btm, low > high[1])
bull_og_filled = bull_filled(bull_og, bull_gap_btm)

//Bearish
[bear_og, bear_og_count] = imbalance_detection(show_og, og_usewidth, og_method,
og_gapwidth, bear_gap_top, bear_gap_btm, high < low[1])
bear_og_filled = bear_filled(bear_og, bear_gap_top)

if bull_og
box.new(n-1, bull_gap_top, n + og_extend, bull_gap_btm, border_color=na,
bgcolor=color.new(bull_og_css, 50), text='OG', text_color=chart.fg_color)

if bear_og
box.new(n-1, bear_gap_top, n + og_extend, bear_gap_btm, border_color=na,
bgcolor=color.new(bear_og_css, 50), text='OG', text_color=chart.fg_color)
//------------------------------------------------------------------------------}

//------------------------------------------------------------------------------
//Fair Value Gaps
//------------------------------------------------------------------------------{
//Bullish
[bull_fvg, bull_fvg_count] = imbalance_detection(show_fvg, fvg_usewidth,
fvg_method, fvg_gapwidth, low, high[2], low > high[2] and close[1] > high[2] and
not (bull_og or bull_og[1]))
bull_fvg_filled = bull_filled(bull_fvg, high[2])

//Bearish
[bear_fvg, bear_fvg_count] = imbalance_detection(show_fvg, fvg_usewidth,
fvg_method, fvg_gapwidth, low[2], high, high < low[2] and close[1] < low[2] and not
(bear_og or bear_og[1]))
bear_fvg_filled = bear_filled(bear_fvg, low[2])

if bull_fvg
avg = math.avg(low, high[2])
box.new(n-2, low, n + fvg_extend, high[2], border_color=na,
bgcolor=color.new(bull_fvg_css, 80))
line.new(n-2, avg, n + fvg_extend, avg, color=bull_fvg_css)

if bear_fvg
avg = math.avg(low[2], high)
box.new(n-2, low[2], n + fvg_extend, high, border_color=na,
bgcolor=color.new(bear_fvg_css, 80))
line.new(n-2, avg, n + fvg_extend, avg, color=bear_fvg_css)
//------------------------------------------------------------------------------}

//------------------------------------------------------------------------------
//Dashboard
//------------------------------------------------------------------------------{
var table_position = dash_loc == 'Bottom Left' ? position.bottom_left : dash_loc ==
'Top Right' ? position.top_right : position.bottom_right
var table_size = text_size == 'Tiny' ? size.tiny : text_size == 'Small' ?
size.small : size.normal
var table tb = na

//Set table legends


if barstate.isfirst and show_dash
tb := table.new(table_position, 5, 7, bgcolor=#1e222d, border_color=#373a46,
border_width=1, frame_color=#373a46, frame_width=1)

if show_fvg
table.cell(tb, 2, 0, '〓 FVG', text_color=color.white,
text_size=table_size)

if show_og
table.cell(tb, 3, 0, '◼ OG', text_color=color.white, text_size=table_size)

if show_vi
table.cell(tb, 4, 0, '⬚ VI', text_color=color.white, text_size=table_size)

table.merge_cells(tb, 0, 0, 1, 0)
table.cell(tb, 0, 1, 'Bullish', text_color=#089981, text_size=table_size)
table.cell(tb, 1, 1, 'Frequency', text_color=#089981, text_size=table_size,
text_halign=text.align_left)
table.cell(tb, 1, 2, 'Filled', text_color=#089981, text_size=table_size,
text_halign=text.align_left)
table.merge_cells(tb, 0, 1, 0, 2)
table.cell(tb, 0, 3, 'Bearish', text_color=#f23645, text_size=table_size)
table.cell(tb, 1, 3, 'Frequency', text_color=#f23645, text_size=table_size,
text_halign=text.align_left)
table.cell(tb, 1, 4, 'Filled', text_color=#f23645, text_size=table_size,
text_halign=text.align_left)
table.merge_cells(tb, 0, 3, 0, 4)

//Set dashboard data


if barstate.islast and show_dash
if show_fvg
set_cells(tb, 2, bull_fvg_filled, bull_fvg_count, bear_fvg_filled,
bear_fvg_count, bull_fvg_css, bear_fvg_css, table_size)

if show_og
set_cells(tb, 3, bull_og_filled, bull_og_count, bear_og_filled,
bear_og_count, bull_og_css, bear_og_css, table_size)

if show_vi
set_cells(tb, 4, bull_vi_filled, bull_vi_count, bear_vi_filled,
bear_vi_count, bull_vi_css, bear_vi_css, table_size)
//------------------------------------------------------------------------------}

//------------------------------------------------------------------------------
// Easy Money Indicator from the second script
//------------------------------------------------------------------------------
Period1 = 3
Period2 = 7
Period3 = 14
PipsMinSepPercent = 40
length = 14
smoothK = 3
smoothD = 3
rsiLength = 8

// Set up Stochastic oscillator (Calculation only, no plot)


k = ta.sma(ta.stoch(close, high, low, length), smoothK)

// Set up RSI (Calculation only, no plot)


rsi = ta.rsi(close, rsiLength)

// Moving Average Function for Braid Filter


ma(type, src, len) =>
float result = na
switch type
"SMA" => result := ta.sma(src, len)
"EMA" => result := ta.ema(src, len)
result

// Assume a default MA type for Braid Filter as EMA


ma01 = ma("EMA", close, Period1)
ma02 = ma("EMA", open, Period2)
ma03 = ma("EMA", close, Period3)

// Braid Filter Calculations


max_val = math.max(math.max(ma01, ma02), ma03)
min_val = math.min(math.min(ma01, ma02), ma03)
dif = max_val - min_val
filter = ta.atr(14) * PipsMinSepPercent / 100
BraidColor = ma01 > ma02 and dif > filter ? color.green : (ma02 > ma01 and dif >
filter ? color.red : color.white)

// Initialize candleColor variable


var color candleColor = na
// Update candle color based on Stochastic and RSI conditions
candleColor := k > 80 or rsi > 70 ? color.red : k < 20 or rsi < 30 ? color.green :
color.white

// Arrow plotting based on color transitions


arrowUp = (candleColor[1] == color.green and candleColor == color.white) and
((BraidColor[1] == color.red or BraidColor[1] == color.white) and (BraidColor ==
color.green or BraidColor == color.white))
arrowDown = (candleColor[1] == color.red and candleColor == color.white) and
((BraidColor[1] == color.green or BraidColor[1] == color.white) and (BraidColor ==
color.red or BraidColor == color.white))

plotshape(series=arrowUp, title="Arrow Up", location=location.belowbar,


color=color.green, style=shape.arrowup, size=size.small)
plotshape(series=arrowDown, title="Arrow Down", location=location.abovebar,
color=color.red, style=shape.arrowdown, size=size.small)

// Alert conditions
alertcondition(arrowUp, title="Green Arrow Alert", message="Green arrow appeared!")
alertcondition(arrowDown, title="Red Arrow Alert", message="Red arrow appeared!")

// Apply bar color based on candle color


barcolor(candleColor)

// daily open
// Lấy giá trị mở cửa của ngày hôm nay
today_open = request.security(syminfo.tickerid, "D", open,
lookahead=barmerge.lookahead_on)

// Hiển thị giá trị mở cửa của ngày hôm nay trên biểu đồ
plot(today_open, color=color.blue, linewidth=2, title="Today's Open",
style=plot.style_line)

You might also like