[Indicator] Magnetic Zones - Multi Timeframe
[Indicator] Magnetic Zones - Multi Timeframe
0 at
https://mozilla.org/MPL/2.0/
//@version=5
indicator(title='Magnetic Zones - Multi Timeframe', shorttitle='Magnetic Zones',
overlay=true)
g_st = 'Supertrend'
bool i_st_show = input.bool(defval=false, title='Show', inline='', group=g_st)
int i_st_atr_period = input.int(defval=7, title='ATR Length', minval=1, inline='',
group=g_st)
float i_st_factor = input.float(defval=2, title='Factor', minval=0.01, step=0.01,
inline='', group=g_st)
color i_st_up_color = input.color(defval=#22AB94, title='Color???????????',
inline='st_c', group=g_st)
color i_st_dn_color = input.color(defval=#F7525F, title='', inline='st_c',
group=g_st)
txt_scr =
'Formula for price Near R2:\n\n'+
'Line 1.\n'+
'5 minute Close <= 1 day ago High + ( ( 1 day ago High - 1 day ago Low ) / 2 )\n\
n'+
'Line 2.\n'+
'5 minute Close >= 1 day ago High + ( ( 1 day ago High - 1 day ago Low ) / 3 )\n\
n\n'+
txt_git =
'Source Code is available at GitHub:\n'+
'Link: https://github.com/ArunKBhaskar/PineScript'
get_time(timeframe) =>
[_time, _time_close] = request.security(symbol=syminfo.tickerid,
timeframe=timeframe, expression=[time, time_close], gaps=barmerge.gaps_off,
lookahead=barmerge.lookahead_on)
[_time, _time_close]
[mz_1_time, mz_1_time_close] = get_time(i_mz_1_tf)
[mz_2_time, mz_2_time_close] = get_time(i_mz_2_tf)
[mz_3_time, mz_3_time_close] = get_time(i_mz_3_tf)
// MZ Function
magnetic_zones(float multiplier) =>
prev_hl_diff = high[1] - low[1]
r = hl2[1] + multiplier * prev_hl_diff
s = hl2[1] - multiplier * prev_hl_diff
[r, s]
/// MZ 1
// PDHL
mz_1_ph = data(i_mz_1_tf, high[1])
mz_1_pl = data(i_mz_1_tf, low[1])
// Pivot
mz_1_p = data(i_mz_1_tf, hl2[1])
// MZ 1 SR
mz_1_r_1 = data(i_mz_1_tf, r_1)
mz_1_r_2 = data(i_mz_1_tf, r_2)
mz_1_r_3 = data(i_mz_1_tf, r_3)
mz_1_r_4 = data(i_mz_1_tf, r_4)
mz_1_r_5 = data(i_mz_1_tf, r_5)
mz_1_r_6 = data(i_mz_1_tf, r_6)
// Buffer
[mz_1_r_1_top, mz_1_r_1_bot] = buffer_zone(mz_1_r_1, mz_1_r_1, mz_1_s_1)
[mz_1_s_1_top, mz_1_s_1_bot] = buffer_zone(mz_1_s_1, mz_1_r_1, mz_1_s_1)
[mz_1_r_2_top, mz_1_r_2_bot] = buffer_zone(mz_1_r_2, mz_1_r_2, mz_1_r_1)
[mz_1_s_2_top, mz_1_s_2_bot] = buffer_zone(mz_1_s_2, mz_1_s_1, mz_1_s_2)
//[mz_1_r_3_top, mz_1_r_3_bot] = buffer_zone(mz_1_r_3, mz_1_r_3, mz_1_r_2)
//[mz_1_s_3_top, mz_1_s_3_bot] = buffer_zone(mz_1_s_3, mz_1_s_2, mz_1_s_3)
[mz_1_r_4_top, mz_1_r_4_bot] = buffer_zone(mz_1_r_4, mz_1_r_4, mz_1_r_3)
[mz_1_s_4_top, mz_1_s_4_bot] = buffer_zone(mz_1_s_4, mz_1_s_3, mz_1_s_4)
//[mz_1_r_5_top, mz_1_r_5_bot] = buffer_zone(mz_1_r_5, mz_1_r_5, mz_1_r_4)
//[mz_1_s_5_top, mz_1_s_5_bot] = buffer_zone(mz_1_s_5, mz_1_s_4, mz_1_s_5)
[mz_1_r_6_top, mz_1_r_6_bot] = buffer_zone(mz_1_r_6, mz_1_r_6, mz_1_r_5)
[mz_1_s_6_top, mz_1_s_6_bot] = buffer_zone(mz_1_s_6, mz_1_s_5, mz_1_s_6)
/// MZ 2
// PDHL
mz_2_ph = data(i_mz_2_tf, high[1])
mz_2_pl = data(i_mz_2_tf, low[1])
// Pivot
mz_2_p = data(i_mz_2_tf, hl2[1])
// MZ 2 SR
mz_2_r_1 = data(i_mz_2_tf, r_1)
mz_2_r_2 = data(i_mz_2_tf, r_2)
// Buffer
[mz_2_r_1_top, mz_2_r_1_bot] = buffer_zone(mz_2_r_1, mz_2_r_1, mz_2_s_1)
[mz_2_s_1_top, mz_2_s_1_bot] = buffer_zone(mz_2_s_1, mz_2_r_1, mz_2_s_1)
[mz_2_r_2_top, mz_2_r_2_bot] = buffer_zone(mz_2_r_2, mz_2_r_2, mz_2_r_1)
[mz_2_s_2_top, mz_2_s_2_bot] = buffer_zone(mz_2_s_2, mz_2_s_1, mz_2_s_2)
/// MZ 3
// PDHL
mz_3_ph = data(i_mz_3_tf, high[1])
mz_3_pl = data(i_mz_3_tf, low[1])
// Pivot
mz_3_p = data(i_mz_3_tf, hl2[1])
// MZ 3 SR
mz_3_r_1 = data(i_mz_3_tf, r_1)
mz_3_r_2 = data(i_mz_3_tf, r_2)
// Buffer
[mz_3_r_1_top, mz_3_r_1_bot] = buffer_zone(mz_3_r_1, mz_3_r_1, mz_3_s_1)
[mz_3_s_1_top, mz_3_s_1_bot] = buffer_zone(mz_3_s_1, mz_3_r_1, mz_3_s_1)
[mz_3_r_2_top, mz_3_r_2_bot] = buffer_zone(mz_3_r_2, mz_3_r_2, mz_3_r_1)
[mz_3_s_2_top, mz_3_s_2_bot] = buffer_zone(mz_3_s_2, mz_3_s_1, mz_3_s_2)
if(timeframe.change(i_mz_1_tf))
if i_mz_1_pdhl_show
mz_1_ph_ln = draw_line(mz_1_time, mz_1_time_close, mz_1_ph,
i_mz_1_sub_color, i_mz_1_ln_style, i_mz_1_ln_width)
array.push(mz_1_ph_ln_arr, mz_1_ph_ln)
mz_1_pl_ln = draw_line(mz_1_time, mz_1_time_close, mz_1_pl,
i_mz_1_sub_color, i_mz_1_ln_style, i_mz_1_ln_width)
array.push(mz_1_pl_ln_arr, mz_1_pl_ln)
if i_mz_1_p_show
mz_1_p_ln = draw_line(mz_1_time, mz_1_time_close, mz_1_p, i_mz_1_sub_color,
i_mz_1_ln_style, i_mz_1_ln_width)
array.push(mz_1_p_ln_arr, mz_1_p_ln)
if i_mz_1_sr_1_show
mz_1_r_1_ln = draw_line(mz_1_time, mz_1_time_close, mz_1_r_1,
i_mz_1_sub_color, i_mz_1_ln_style, i_mz_1_ln_width)
array.push(mz_1_r_1_ln_arr, mz_1_r_1_ln)
mz_1_s_1_ln = draw_line(mz_1_time, mz_1_time_close, mz_1_s_1,
i_mz_1_sub_color, i_mz_1_ln_style, i_mz_1_ln_width)
array.push(mz_1_s_1_ln_arr, mz_1_s_1_ln)
if i_mz_1_sr_2_show
mz_1_r_2_ln = draw_line(mz_1_time, mz_1_time_close, mz_1_r_2,
i_mz_1_s_ln_color, i_mz_1_ln_style, i_mz_1_ln_width)
array.push(mz_1_r_2_ln_arr, mz_1_r_2_ln)
mz_1_s_2_ln = draw_line(mz_1_time, mz_1_time_close, mz_1_s_2,
i_mz_1_r_ln_color, i_mz_1_ln_style, i_mz_1_ln_width)
array.push(mz_1_s_2_ln_arr, mz_1_s_2_ln)
if i_mz_1_sr_3_show
mz_1_r_3_ln = draw_line(mz_1_time, mz_1_time_close, mz_1_r_3,
i_mz_1_r_t_ln_color, i_mz_1_ln_style, i_mz_1_ln_width)
array.push(mz_1_r_3_ln_arr, mz_1_r_3_ln)
mz_1_s_3_ln = draw_line(mz_1_time, mz_1_time_close, mz_1_s_3,
i_mz_1_s_t_ln_color, i_mz_1_ln_style, i_mz_1_ln_width)
array.push(mz_1_s_3_ln_arr, mz_1_s_3_ln)
// if i_mz_1_sr_3_show
// mz_1_r_3_bx = draw_box(mz_1_time, mz_1_time_close, mz_1_r_3_top,
mz_1_r_3_bot, color.new(i_mz_1_r_ln_color, i_mz_bx_transp), 1, i_mz_bx_style,
str.tostring(math.round_to_mintick(mz_1_r_3)) + '\n' + '\n', i_mz_bx_txt_size,
i_mz_1_r_ln_color, i_mz_bx_txt_align)
// array.push(mz_1_r_3_bx_arr, mz_1_r_3_bx)
// mz_1_s_3_bx = draw_box(mz_1_time, mz_1_time_close, mz_1_s_3_top,
mz_1_s_3_bot, color.new(i_mz_1_s_ln_color, i_mz_bx_transp), 1, i_mz_bx_style, '\n'
+ str.tostring(math.round_to_mintick(mz_1_s_3)), i_mz_bx_txt_size,
i_mz_1_s_ln_color, i_mz_bx_txt_align)
// array.push(mz_1_s_3_bx_arr, mz_1_s_3_bx)
if i_mz_1_sr_4_show
mz_1_r_4_ln = draw_line(mz_1_time, mz_1_time_close, mz_1_r_4,
i_mz_1_r_t_ln_color, i_mz_1_ln_style, i_mz_1_ln_width)
array.push(mz_1_r_4_ln_arr, mz_1_r_4_ln)
mz_1_s_4_ln = draw_line(mz_1_time, mz_1_time_close, mz_1_s_4,
i_mz_1_s_t_ln_color, i_mz_1_ln_style, i_mz_1_ln_width)
array.push(mz_1_s_4_ln_arr, mz_1_s_4_ln)
mz_1_r_4_bx = draw_box(mz_1_time, mz_1_time_close, mz_1_r_4_top,
mz_1_r_4_bot, color.new(i_mz_1_r_t_ln_color, i_mz_bx_transp), 1, i_mz_bx_style,
str.tostring(math.round_to_mintick(mz_1_r_4)) + '\n' + '\n', i_mz_bx_txt_size,
i_mz_1_r_t_ln_color, i_mz_bx_txt_align)
array.push(mz_1_r_4_bx_arr, mz_1_r_4_bx)
mz_1_s_4_bx = draw_box(mz_1_time, mz_1_time_close, mz_1_s_4_top,
mz_1_s_4_bot, color.new(i_mz_1_s_t_ln_color, i_mz_bx_transp), 1, i_mz_bx_style, '\
n' + str.tostring(math.round_to_mintick(mz_1_s_4)), i_mz_bx_txt_size,
i_mz_1_s_t_ln_color, i_mz_bx_txt_align)
array.push(mz_1_s_4_bx_arr, mz_1_s_4_bx)
if i_mz_1_sr_5_show
mz_1_r_5_ln = draw_line(mz_1_time, mz_1_time_close, mz_1_r_5,
i_mz_1_r_t_ln_color, i_mz_1_ln_style, i_mz_1_ln_width)
array.push(mz_1_r_5_ln_arr, mz_1_r_5_ln)
mz_1_s_5_ln = draw_line(mz_1_time, mz_1_time_close, mz_1_s_5,
i_mz_1_s_t_ln_color, i_mz_1_ln_style, i_mz_1_ln_width)
array.push(mz_1_s_5_ln_arr, mz_1_s_5_ln)
// if i_mz_1_sr_5_show
// mz_1_r_5_bx = draw_box(mz_1_time, mz_1_time_close, mz_1_r_5_top,
mz_1_r_5_bot, color.new(i_mz_1_r_t_ln_color, i_mz_bx_transp), 1, i_mz_bx_style,
str.tostring(math.round_to_mintick(mz_1_r_5)) + '\n' + '\n', i_mz_bx_txt_size,
i_mz_1_r_t_ln_color, i_mz_bx_txt_align)
// array.push(mz_1_r_5_bx_arr, mz_1_r_5_bx)
// mz_1_s_5_bx = draw_box(mz_1_time, mz_1_time_close, mz_1_s_5_top,
mz_1_s_5_bot, color.new(i_mz_1_s_t_ln_color, i_mz_bx_transp), 1, i_mz_bx_style, '\
n' + str.tostring(math.round_to_mintick(mz_1_s_5)), i_mz_bx_txt_size,
i_mz_1_s_t_ln_color, i_mz_bx_txt_align)
// array.push(mz_1_s_5_bx_arr, mz_1_s_5_bx)
if i_mz_1_sr_6_show
mz_1_r_6_ln = draw_line(mz_1_time, mz_1_time_close, mz_1_r_6,
i_mz_1_r_t_ln_color, i_mz_1_ln_style, i_mz_1_ln_width)
array.push(mz_1_r_6_ln_arr, mz_1_r_6_ln)
mz_1_s_6_ln = draw_line(mz_1_time, mz_1_time_close, mz_1_s_6,
i_mz_1_s_t_ln_color, i_mz_1_ln_style, i_mz_1_ln_width)
array.push(mz_1_s_6_ln_arr, mz_1_s_6_ln)
show_last_lines(mz_1_ph_ln_arr, i_mz_1_showlast)
show_last_lines(mz_1_pl_ln_arr, i_mz_1_showlast)
show_last_lines(mz_1_p_ln_arr, i_mz_1_showlast)
show_last_lines(mz_1_r_1_ln_arr, i_mz_1_showlast)
show_last_lines(mz_1_s_1_ln_arr, i_mz_1_showlast)
show_last_lines(mz_1_r_2_ln_arr, i_mz_1_showlast)
show_last_lines(mz_1_s_2_ln_arr, i_mz_1_showlast)
show_last_lines(mz_1_r_3_ln_arr, i_mz_1_showlast)
show_last_lines(mz_1_s_3_ln_arr, i_mz_1_showlast)
show_last_lines(mz_1_r_4_ln_arr, i_mz_1_showlast)
show_last_lines(mz_1_s_4_ln_arr, i_mz_1_showlast)
show_last_lines(mz_1_r_5_ln_arr, i_mz_1_showlast)
show_last_lines(mz_1_s_5_ln_arr, i_mz_1_showlast)
show_last_lines(mz_1_r_6_ln_arr, i_mz_1_showlast)
show_last_lines(mz_1_s_6_ln_arr, i_mz_1_showlast)
show_last_boxes(mz_1_r_1_s_1_bx_arr, i_mz_1_showlast)
show_last_boxes(mz_1_r_1_bx_arr, i_mz_1_showlast)
show_last_boxes(mz_1_s_1_bx_arr, i_mz_1_showlast)
show_last_boxes(mz_1_r_2_bx_arr, i_mz_1_showlast)
show_last_boxes(mz_1_s_2_bx_arr, i_mz_1_showlast)
//show_last_boxes(mz_1_r_3_bx_arr, i_mz_1_showlast)
//show_last_boxes(mz_1_s_3_bx_arr, i_mz_1_showlast)
show_last_boxes(mz_1_r_4_bx_arr, i_mz_1_showlast)
show_last_boxes(mz_1_s_4_bx_arr, i_mz_1_showlast)
//show_last_boxes(mz_1_r_5_bx_arr, i_mz_1_showlast)
//show_last_boxes(mz_1_s_5_bx_arr, i_mz_1_showlast)
show_last_boxes(mz_1_r_6_bx_arr, i_mz_1_showlast)
show_last_boxes(mz_1_s_6_bx_arr, i_mz_1_showlast)
if(timeframe.change(i_mz_2_tf))
if i_mz_2_pdhl_show
mz_2_ph_ln = draw_line(mz_2_time, mz_2_time_close, mz_2_ph,
i_mz_2_sub_color, i_mz_2_ln_style, i_mz_2_ln_width)
array.push(mz_2_ph_ln_arr, mz_2_ph_ln)
mz_2_pl_ln = draw_line(mz_2_time, mz_2_time_close, mz_2_pl,
i_mz_2_sub_color, i_mz_2_ln_style, i_mz_2_ln_width)
array.push(mz_2_pl_ln_arr, mz_2_pl_ln)
if i_mz_2_p_show
mz_2_p_ln = draw_line(mz_2_time, mz_2_time_close, mz_2_p, i_mz_2_sub_color,
i_mz_2_ln_style, i_mz_2_ln_width)
array.push(mz_2_p_ln_arr, mz_2_p_ln)
if i_mz_2_sr_1_show
mz_2_r_1_ln = draw_line(mz_2_time, mz_2_time_close, mz_2_r_1,
i_mz_2_sub_color, i_mz_2_ln_style, i_mz_2_ln_width)
array.push(mz_2_r_1_ln_arr, mz_2_r_1_ln)
mz_2_s_1_ln = draw_line(mz_2_time, mz_2_time_close, mz_2_s_1,
i_mz_2_sub_color, i_mz_2_ln_style, i_mz_2_ln_width)
array.push(mz_2_s_1_ln_arr, mz_2_s_1_ln)
if i_mz_2_sr_2_show
mz_2_r_2_ln = draw_line(mz_2_time, mz_2_time_close, mz_2_r_2,
i_mz_2_s_ln_color, i_mz_2_ln_style, i_mz_2_ln_width)
array.push(mz_2_r_2_ln_arr, mz_2_r_2_ln)
mz_2_s_2_ln = draw_line(mz_2_time, mz_2_time_close, mz_2_s_2,
i_mz_2_r_ln_color, i_mz_2_ln_style, i_mz_2_ln_width)
array.push(mz_2_s_2_ln_arr, mz_2_s_2_ln)
show_last_lines(mz_2_ph_ln_arr, i_mz_2_showlast)
show_last_lines(mz_2_pl_ln_arr, i_mz_2_showlast)
show_last_lines(mz_2_p_ln_arr, i_mz_2_showlast)
show_last_lines(mz_2_r_1_ln_arr, i_mz_2_showlast)
show_last_lines(mz_2_s_1_ln_arr, i_mz_2_showlast)
show_last_lines(mz_2_r_2_ln_arr, i_mz_2_showlast)
show_last_lines(mz_2_s_2_ln_arr, i_mz_2_showlast)
show_last_boxes(mz_2_r_1_s_1_bx_arr, i_mz_2_showlast)
show_last_boxes(mz_2_r_1_bx_arr, i_mz_2_showlast)
show_last_boxes(mz_2_s_1_bx_arr, i_mz_2_showlast)
show_last_boxes(mz_2_r_2_bx_arr, i_mz_2_showlast)
show_last_boxes(mz_2_s_2_bx_arr, i_mz_2_showlast)
if(timeframe.change(i_mz_3_tf))
if i_mz_3_pdhl_show
mz_3_ph_ln = draw_line(mz_3_time, mz_3_time_close, mz_3_ph,
i_mz_3_sub_color, i_mz_3_ln_style, i_mz_3_ln_width)
array.push(mz_3_ph_ln_arr, mz_3_ph_ln)
mz_3_pl_ln = draw_line(mz_3_time, mz_3_time_close, mz_3_pl,
i_mz_3_sub_color, i_mz_3_ln_style, i_mz_3_ln_width)
array.push(mz_3_pl_ln_arr, mz_3_pl_ln)
if i_mz_3_p_show
mz_3_p_ln = draw_line(mz_3_time, mz_3_time_close, mz_3_p, i_mz_3_sub_color,
i_mz_3_ln_style, i_mz_3_ln_width)
array.push(mz_3_p_ln_arr, mz_3_p_ln)
if i_mz_3_sr_1_show
mz_3_r_1_ln = draw_line(mz_3_time, mz_3_time_close, mz_3_r_1,
i_mz_3_sub_color, i_mz_3_ln_style, i_mz_3_ln_width)
array.push(mz_3_r_1_ln_arr, mz_3_r_1_ln)
mz_3_s_1_ln = draw_line(mz_3_time, mz_3_time_close, mz_3_s_1,
i_mz_3_sub_color, i_mz_3_ln_style, i_mz_3_ln_width)
array.push(mz_3_s_1_ln_arr, mz_3_s_1_ln)
if i_mz_3_sr_2_show
mz_3_r_2_ln = draw_line(mz_3_time, mz_3_time_close, mz_3_r_2,
i_mz_3_s_ln_color, i_mz_3_ln_style, i_mz_3_ln_width)
array.push(mz_3_r_2_ln_arr, mz_3_r_2_ln)
mz_3_s_2_ln = draw_line(mz_3_time, mz_3_time_close, mz_3_s_2,
i_mz_3_r_ln_color, i_mz_3_ln_style, i_mz_3_ln_width)
array.push(mz_3_s_2_ln_arr, mz_3_s_2_ln)
show_last_lines(mz_3_ph_ln_arr, i_mz_3_showlast)
show_last_lines(mz_3_pl_ln_arr, i_mz_3_showlast)
show_last_lines(mz_3_p_ln_arr, i_mz_3_showlast)
show_last_lines(mz_3_r_1_ln_arr, i_mz_3_showlast)
show_last_lines(mz_3_s_1_ln_arr, i_mz_3_showlast)
show_last_lines(mz_3_r_2_ln_arr, i_mz_3_showlast)
show_last_lines(mz_3_s_2_ln_arr, i_mz_3_showlast)
show_last_boxes(mz_3_r_1_s_1_bx_arr, i_mz_3_showlast)
show_last_boxes(mz_3_r_1_bx_arr, i_mz_3_showlast)
show_last_boxes(mz_3_s_1_bx_arr, i_mz_3_showlast)
show_last_boxes(mz_3_r_2_bx_arr, i_mz_3_showlast)
show_last_boxes(mz_3_s_2_bx_arr, i_mz_3_showlast)
// Functions
// Resolution to String
res_to_str(_res) =>
if _res == ''
''
else if _res == '1'
'1m'
else if _res == '3'
'3m'
else if _res == '5'
'5m'
else if _res == '15'
'15m'
else if _res == '30'
'30m'
else if _res == '45'
'45m'
else if _res == '60'
'1h'
else if _res == '120'
'2h'
else if _res == '180'
'3h'
else if _res == '240'
'4h'
else if _res == '1D'
'D'
else if _res == '1W'
'W'
else if _res == '1M'
'M'
else if _res == '3M'
'3M'
else if _res == '6M'
'6M'
else if _res == '12M'
'12M'
else
_res
ma_offset() =>
offset_spaces = ''
if i_ma_offset > 0
for i = 1 to i_ma_offset by 1
offset_spaces += ' '
offset_spaces
float vwap_value = na
// Supertrend Calculation
dir_up = hl2 - i_st_factor * ta.atr(i_st_atr_period)
dir_dn = hl2 + i_st_factor * ta.atr(i_st_atr_period)
trend_up = 0.0
trend_up := close[1] > trend_up[1] ? math.max(dir_up, trend_up[1]) : dir_up
trend_down = 0.0
trend_down := close[1] < trend_down[1] ? math.min(dir_dn, trend_down[1]) : dir_dn
trend = 0.0
trend := close > trend_down[1] ? 1 : close < trend_up[1] ? -1 : nz(trend[1], 1)
supertrend = trend == 1 ? trend_up : trend_down
// Color
st_ln_col = trend == 1 ? i_st_up_color : i_st_dn_color