Professional Documents
Culture Documents
indi m1
indi m1
indi m1
///////////////
// Groups
///////////////
gema = '//EMA'
g0 = '// GENERAL //'
g1 = '// BOX TYPE //'
g2 = '//DWMY Opens//'
g3 = '//DWMY Styles//'
g4 = '//DWMY Settings//'
g5 = '//Open Session//'
g111_01 = '// ♯1 SESSION //'
g111_02 = '// ♯2 SESSION //'
g111_03 = '// ♯3 SESSION //'
g111_04 = '// ♯4 SESSION //'
g111_05 = '// ♯5 SESSION //'
g111_06 = '// ♯6 SESSION //'
g111_07 = '// ♯7 SESSION //'
g111_08 = '// ♯8 SESSION //'
g111_09 = '// ♯9 SESSION //'
g111_10 = '// ♯10 SESSION //'
g111_11 = '// ♯11 SESSION //'
g111_12 = '// ♯12 SESSION //'
g111_13 = '// ♯13 SESSION //'
g111_14 = '// ♯14 SESSION //'
g111_15 = '// ♯15 SESSION //'
g111_16 = '// ♯16 SESSION //'
g111_17 = '// ♯17 SESSION //'
g111_18 = '// ♯18 SESSION //'
g111_19 = '// ♯19 SESSION //'
g111_20 = '// ♯20 SESSION //'
g111_21 = '// ♯21 SESSION //'
g111_22 = '// ♯22 SESSION //'
g111_23 = '// ♯23 SESSION //'
g111_24 = '// ♯24 SESSION //'
g111_25 = '// ♯25 SESSION //'
g111_26 = '// ♯26 SESSION //'
g111_27 = '// ♯27 SESSION //'
g111_28 = '// ♯28 SESSION //'
g111_29 = '// ♯29 SESSION //'
g111_30 = '// ♯30 SESSION //'
g111_31 = '// ♯31 SESSION //'
g111_32 = '// ♯32 SESSION //'
g111_33 = '// ♯33 SESSION //'
g111_34 = '// ♯34 SESSION //'
g111_35 = '// ♯35 SESSION //'
g111_36 = '// ♯36 SESSION //'
g111_37 = '// ♯37 SESSION //'
g111_38 = '// ♯38 SESSION //'
g111_39 = '// ♯39 SESSION //'
g111_40 = '// ♯40 SESSION //'
g111_41 = '// ♯41 SESSION //'
g111_42 = '// ♯42 SESSION //'
g111_43 = '// ♯43 SESSION //'
g111_44 = '// ♯44 SESSION //'
g111_45 = '// ♯45 SESSION //'
g111_46 = '// ♯46 SESSION //'
g111_47 = '// ♯47 SESSION //'
g111_48 = '// ♯48 SESSION //'
//--------------------------------------------------------------------
// Constants
//--------------------------------------------------------------------
var HEAD_PADDING = -2
var HEAD_TRANSP = 60
var LABEL_SIZE = size.small
var LABEL_STYLE = label.style_none
var LINE_STYLE = line.style_solid
var LINE_WIDTH = 1
var OFFSET_PADDING = 4
var TAIL_STYLE = line.style_dotted
//--------------------------------------------------------------------
// Inputs
//--------------------------------------------------------------------
// Calculate EMAs
ema1 = ta.ema(close, len1)
ema2 = ta.ema(close, len2)
// EMA Plots
plot(ema1, title='EMA 1', style=plot.style_line, linewidth=1, color=ema1color)
plot(ema2, title='EMA 2', style=plot.style_line, linewidth=1, color=ema2color)
///////////////
// Defined
///////////////
MAX_BARS = 500
option_yes = 'Yes'
option_no = '× No'
option_border_style1 = '────'
option_border_style2 = '- - - - - -'
option_border_style3 = '•••••••••'
///////////////
// Methods
///////////////
method clear (array<string> id, int _min = 0) =>
if array.size(id) > _min
array.pop(id)
///////////////
// Types
///////////////
// Candle
type Candle
box[] body
line[] wick
// Data
type Session
string sess
string tz
string name
color colour
color lbcolour
box[] boxes
int session
Candle candle
this
// Sessions
i_show_sess1 = input.bool(true, 'Session 1 ', group=g111_01,
inline='session1_1') and i_show
i_sess1_label = input.string('00h00', '', group=g111_01,
inline='session1_1')
i_sess1 = input.session('0000-0031', 'Time', group=g111_01)
i_sess1_max = input.int(30,'Max box size', group=g111_01)
// ------------------------
// ------------------------
// Drawing
// ------------------------
draw (_show, Session data, max_box_size) =>
session = data.session()
col = data.colour
lbcolor = data.lbcolour
name = data.name
var box my_box = na
is_started = f_get_started(session)
if _show and is_started
my_box := box.new(bar_index, low, bar_index, high, col,
i_sess_border_width, i_sess_border_style, bgcolor=color.new(col,
i_sess_box_background ? i_sess_bgopacitys : 100),text = name,text_size = text_size,
text_halign = text_Hali, text_color = lbcolor)
array.push(data.boxes, my_box)
util.clear_boxes(data.boxes, i_history_period)
f_set_box_right(my_box, bar_index + max_box_size)
[session]
if timeframe.period=='1'
[is_sess1] = draw(i_show_sess1, sess1_data,i_sess1_max)
[is_sess2] = draw(i_show_sess2, sess2_data,i_sess2_max)
[is_sess3] = draw(i_show_sess3, sess3_data,i_sess3_max)
[is_sess4] = draw(i_show_sess4, sess4_data,i_sess4_max)
[is_sess5] = draw(i_show_sess5, sess5_data,i_sess5_max)
[is_sess6] = draw(i_show_sess6, sess6_data,i_sess6_max)
[is_sess7] = draw(i_show_sess7, sess7_data,i_sess7_max)
[is_sess8] = draw(i_show_sess8, sess8_data,i_sess8_max)
[is_sess9] = draw(i_show_sess9, sess9_data,i_sess9_max)
[is_sess10] = draw(i_show_sess10, sess10_data,i_sess10_max)
[is_sess11] = draw(i_show_sess11, sess11_data,i_sess11_max)
[is_sess12] = draw(i_show_sess12, sess12_data,i_sess12_max)
[is_sess13] = draw(i_show_sess13, sess13_data,i_sess13_max)
[is_sess14] = draw(i_show_sess14, sess14_data,i_sess14_max)
[is_sess15] = draw(i_show_sess15, sess15_data,i_sess15_max)
[is_sess16] = draw(i_show_sess16, sess16_data,i_sess16_max)
[is_sess17] = draw(i_show_sess17, sess17_data,i_sess17_max)
[is_sess18] = draw(i_show_sess18, sess18_data,i_sess18_max)
[is_sess19] = draw(i_show_sess19, sess19_data, i_sess19_max)
[is_sess20] = draw(i_show_sess20, sess20_data, i_sess20_max)
[is_sess21] = draw(i_show_sess21, sess21_data, i_sess21_max)
[is_sess22] = draw(i_show_sess22, sess22_data, i_sess22_max)
[is_sess23] = draw(i_show_sess23, sess23_data, i_sess23_max)
[is_sess24] = draw(i_show_sess24, sess24_data, i_sess24_max)
[is_sess25] = draw(i_show_sess25, sess25_data, i_sess25_max)
[is_sess26] = draw(i_show_sess26, sess26_data, i_sess26_max)
[is_sess27] = draw(i_show_sess27, sess27_data, i_sess27_max)
[is_sess28] = draw(i_show_sess28, sess28_data, i_sess28_max)
[is_sess29] = draw(i_show_sess29, sess29_data, i_sess29_max)
[is_sess30] = draw(i_show_sess30, sess30_data, i_sess30_max)
[is_sess31] = draw(i_show_sess31, sess31_data, i_sess31_max)
[is_sess32] = draw(i_show_sess32, sess32_data, i_sess32_max)
[is_sess33] = draw(i_show_sess33, sess33_data, i_sess33_max)
[is_sess34] = draw(i_show_sess34, sess34_data, i_sess34_max)
[is_sess35] = draw(i_show_sess35, sess35_data, i_sess35_max)
[is_sess36] = draw(i_show_sess36, sess36_data, i_sess36_max)
[is_sess37] = draw(i_show_sess37, sess37_data, i_sess37_max)
[is_sess38] = draw(i_show_sess38, sess38_data, i_sess38_max)
[is_sess39] = draw(i_show_sess39, sess39_data, i_sess39_max)
[is_sess40] = draw(i_show_sess40, sess40_data, i_sess40_max)
[is_sess41] = draw(i_show_sess41, sess41_data, i_sess41_max)
[is_sess42] = draw(i_show_sess42, sess42_data, i_sess42_max)
[is_sess43] = draw(i_show_sess43, sess43_data, i_sess43_max)
[is_sess44] = draw(i_show_sess44, sess44_data, i_sess44_max)
[is_sess45] = draw(i_show_sess45, sess45_data, i_sess45_max)
[is_sess46] = draw(i_show_sess46, sess46_data, i_sess46_max)
[is_sess47] = draw(i_show_sess47, sess47_data, i_sess47_max)
[is_sess48] = draw(i_show_sess48, sess48_data, i_sess48_max)
//--------------------------------------------------------------------
// Variables declarations
//--------------------------------------------------------------------
//--------------------------------------------------------------------
// Functions
//--------------------------------------------------------------------
// If different opens share the same opening prices, their labels will overlap
// Instead, we pad the higher time frame ones for achieving a "separator sheet"
f_getPadding(int _index) =>
_padding = 0
// Weekly, monthly, or yearly overlaps the daily open
if _index > 0 and canShowDaily and array.get(a_lastOpens, 0) ==
array.get(a_lastOpens, _index)
_padding += 1
// Monthly or yearly overlaps the weekly open
if _index > 1 and canShowWeekly and array.get(a_lastOpens, 1) ==
array.get(a_lastOpens, _index)
_padding += 1
// Yearly overlaps the monthly open
if _index > 2 and canShowMonthly and array.get(a_lastOpens, 2) ==
array.get(a_lastOpens, _index)
_padding += 1
_padding
// On the weekly time frame, the monthly/yearly open is drawn from the first candle
of the month/year
// The first weekly candle is not necessarily containing the first day of the month
// In such case, we visually anchor the open of the previous weekly candle
f_isContainedOnPrevWeekly(int _time) => timeframe.isweekly and dayofmonth(time) >
dayofmonth(_time)
// Create and update an open level. An open is composed of a label, a "body" line,
and optional "tail" and "head" lines extensions
f_draw(bool _newOpen, float _y, int _lookback, int _padding, color _color, string
_text, bool _prevTime=false, int candle_index = bar_index) =>
var line _body = na
var _label = label.new(na, na, _text, style=LABEL_STYLE, textcolor=_color,
size=LABEL_SIZE)
var _tail = line.new(na, na, na, na, color=_color, style=TAIL_STYLE,
width=LINE_WIDTH, extend=extend.left)
var _bodies = array.new_line()
var _heads = array.new_line()
_start = _prevTime ? candle_index - 1 : candle_index
_end = f_getRightBarIndex(_padding)
if _newOpen
// Label
label.set_xy(_label, _end, _y)
label.set_tooltip(_label, str.tostring(_y, format.mintick))
// Body
line.set_x2(_body, candle_index)
_body := line.new(_start, _y, _end, _y, color=_color, style=LINE_STYLE,
width=LINE_WIDTH)
array.push(_bodies, _body)
// Head
if i_areHeadsEnabled
array.push(_heads, line.new(candle_index, _y, candle_index, _y,
color=color.new(_color, HEAD_TRANSP), style=LINE_STYLE, width=LINE_WIDTH))
// Tail
if i_areTailsEnabled
line.set_xy1(_tail, _start - 1, _y)
line.set_xy2(_tail, _start, _y)
if barstate.islast
line.set_x2(_body, _end)
label.set_x(_label, _end)
//--------------------------------------------------------------------
// Logic
//--------------------------------------------------------------------
//--------------------------------------------------------------------
// Plotting & styling
//--------------------------------------------------------------------
if canShowYearly
f_draw(hasYearlyTimeChanged, array.get(a_lastOpens, 3), i_yearlyLookback,
f_getPadding(3), i_yearlyColor, "Y ", f_isContainedOnPrevWeekly(yearlyTime))
if canShowMonthly
f_draw(hasMonthlyTimeChanged, array.get(a_lastOpens, 2), i_monthlyLookback,
f_getPadding(2), i_monthlyColor, "M ", f_isContainedOnPrevWeekly(monthlyTime))
if canShowWeekly
f_draw(hasWeekklyTimeChanged, array.get(a_lastOpens, 1), i_weeklyLookback,
f_getPadding(1), i_weeklyColor, "W ")
if canShowDaily
f_draw(hasDailyTimeChanged, array.get(a_lastOpens, 0), i_dailyLookback,
f_getPadding(0), i_dailyColor, "D ")
// Plot invisible opens for displaying last values in `status line`, `scale`, `data
window` as well for providing defaults alert conditions
// Lấy giá thấp và giá cao của cây nến 30 phút gần nhất
[prev30mTime, previous_low] = request.security(syminfo.tickerid, prevHLTimeFrame,
[time, low[1]], lookahead=barmerge.lookahead_on)
[prev30mTimeHigh, previous_high] = request.security(syminfo.tickerid,
prevHLTimeFrame, [time, high[1]], lookahead=barmerge.lookahead_on)
previous_candle_bar_index = request.security(syminfo.tickerid, prevHLTimeFrame,
bar_index, lookahead=barmerge.lookahead_on)
// MISC
TokyoOpen = time ("1", i_sess_tokyo, i_tz)
LonDonOpen = time ("1", i_sess_london, i_tz)
CMEOpen = time ("1", i_sess_cme, i_tz)
// CALC
var openpriceTokyo = 0.0
var openpriceLD = 0.0
var openpriceCME = 0.0
if TokyoOpen
if not TokyoOpen[1]
openpriceTokyo := open
else
openpriceTokyo := math.max(open, openpriceTokyo)
if LonDonOpen
if not LonDonOpen[1]
openpriceLD := open
else
openpriceLD := math.max(open, openpriceLD)
if CMEOpen
if not CMEOpen[1]
openpriceCME := open
else
openpriceCME := math.max(open, openpriceCME)