Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ============= By UpWork.com/fl/pavletabatadze ============//
- // v1: http://tinyurl.com/y729ue8d , v2: http://tinyurl.com/yb2ch7p9
- //@version=3
- study("Hi-Lo Between Crossovers", overlay=true, max_bars_back=5000)
- ma1_length = input(defval=10, type=integer)
- ma2_length = input(defval=30, type=integer)
- show_ema_lines = input(defval=false)
- //max_arrows = input(defval=10, type=integer, title="Arrows amount (max.10)" )
- max_arrows = 10
- start_arrows_offset = input(defval=0, type=integer, title="start plotting from last X arrows" )
- ma1_val = ema(close, ma1_length)
- ma2_val = ema(close, ma2_length)
- plot( show_ema_lines ? ma1_val : na, color= green, title="MA 1")
- plot( show_ema_lines ? ma2_val : na, color= red, title="MA 2")
- arrow_down_color = green
- arrow_up_color =red
- highest_(values, length) =>
- h_val = na
- if length >= 1
- for i = 0 to length-1
- if (na(h_val) or (not na(values[i]) and values[i] > h_val) )
- h_val := values[i]
- h_val
- lowest_(values, length) =>
- l_val = na
- if length >= 1
- for i = 0 to length-1
- if (na(l_val) or (not na(values[i]) and values[i] < l_val) )
- l_val := values[i]
- l_val
- cross_up = ma1_val > ma2_val
- cross_down = ma1_val < ma2_val
- cross_up_first = cross_up and not cross_up[1]
- cross_down_first= cross_down and not cross_down[1]
- cross_up_first_count = 0
- cross_up_first_count := cross_up_first ? cross_up_first_count[1] +1 : cross_up_first_count[1]
- cross_down_first_count = 0
- cross_down_first_count := cross_down_first ? cross_down_first_count[1] +1 : cross_down_first_count[1]
- // count_to_last_up = 0.0
- // count_to_last_up := cross_up_first or cross_down_first ? 0 : count_to_last_up[1] + 1
- // count_to_last_down = 0.0
- // count_to_last_down := cross_down_first or cross_up_first ? 0 : count_to_last_down[1] + 1
- highest_after_last_cross = 0.0
- highest_after_last_cross := cross_down_first or cross_up_first? high : ( high > highest_after_last_cross[1] ? high : highest_after_last_cross[1])
- lowest_after_last_cross = 0.0
- lowest_after_last_cross := cross_up_first or cross_down_first ? low : ( low < lowest_after_last_cross[1] ? low : lowest_after_last_cross[1])
- highest_bn_last_offset = 0.0
- highest_bn_last_offset := cross_up_first or cross_down_first ? 0 : ( high == highest_after_last_cross ? 0 : highest_bn_last_offset[1] + 1 )
- lowest_bn_last_offset = 0.0
- lowest_bn_last_offset := cross_down_first or cross_up_first ? 0 : ( low == lowest_after_last_cross ? 0 : lowest_bn_last_offset[1] + 1 )
- offset_h = round(highest_bn_last_offset)
- offset_l = round(lowest_bn_last_offset)
- o_h = -offset_h[1]
- o_l = -offset_l[1]
- // as we have large loops, lets divide the functions (so, less if/else in checking). also, create offsets to save time
- crosser_high(which_arrow, start_offset) =>
- x=0
- cross_counter=0
- for i=start_offset to start_offset+4999
- if (cross_down_first[i])
- cross_counter := cross_counter+1
- if (cross_counter==which_arrow)
- x := - i + o_h[i] -1
- break
- x
- crosser_low(which_arrow, start_offset) =>
- x=0
- cross_counter=0
- for i=start_offset to start_offset+4999
- if (cross_up_first[i])
- cross_counter := cross_counter+1
- if (cross_counter==which_arrow)
- x := - i + o_l[i] -1
- break
- x
- start_offset_h = not barstate.islast ? 0 : -crosser_high( start_arrows_offset, 0 )
- start_offset_l = not barstate.islast ? 0 : -crosser_low( start_arrows_offset, 0 )
- ofs_h1= max_arrows < 1 ? 0 : crosser_high(1, start_offset_h)
- plotchar(barstate.islast and ofs_h1!=0 ? true:na, offset=ofs_h1, char="⬇", color=arrow_down_color, size=size.small, location=location.abovebar)
- ofs_l1= max_arrows < 1 ? 0 : crosser_low(1, start_offset_l)
- plotchar(barstate.islast and ofs_l1!=0 ? true:na, offset=ofs_l1, char="⬆", color=arrow_up_color, size=size.small, location=location.belowbar)
- ofs_h2= max_arrows < 2 ? 0 : crosser_high(2, start_offset_h)
- plotchar(barstate.islast and ofs_h2!=0 ? true:na, offset=ofs_h2, char="⬇", color=arrow_down_color, size=size.small, location=location.abovebar)
- ofs_l2= max_arrows < 2 ? 0 : crosser_low(2, start_offset_l)
- plotchar(barstate.islast and ofs_l2!=0 ? true:na, offset=ofs_l2, char="⬆", color=arrow_up_color, size=size.small, location=location.belowbar)
- ofs_h3= max_arrows < 3 ? 0 : crosser_high(3, start_offset_h)
- plotchar(barstate.islast and ofs_h3!=0 ? true:na, offset=ofs_h3, char="⬇", color=arrow_down_color, size=size.small, location=location.abovebar)
- ofs_l3= max_arrows < 3 ? 0 : crosser_low(3, start_offset_l)
- plotchar(barstate.islast and ofs_l3!=0 ? true:na, offset=ofs_l3, char="⬆", color=arrow_up_color, size=size.small, location=location.belowbar)
- ofs_h4= max_arrows < 4 ? 0 : crosser_high(4, start_offset_h)
- plotchar(barstate.islast and ofs_h4!=0 ? true:na, offset=ofs_h4, char="⬇", color=arrow_down_color, size=size.small, location=location.abovebar)
- ofs_l4= max_arrows < 4 ? 0 : crosser_low(4, start_offset_l)
- plotchar(barstate.islast and ofs_l4!=0 ? true:na, offset=ofs_l4, char="⬆", color=arrow_up_color, size=size.small, location=location.belowbar)
- ofs_h5= max_arrows < 5 ? 0 : crosser_high(5, start_offset_h)
- plotchar(barstate.islast and ofs_h5!=0 ? true:na, offset=ofs_h5, char="⬇", color=arrow_down_color, size=size.small, location=location.abovebar)
- ofs_l5= max_arrows < 5 ? 0 : crosser_low(5, start_offset_l)
- plotchar(barstate.islast and ofs_l5!=0 ? true:na, offset=ofs_l5, char="⬆", color=arrow_up_color, size=size.small, location=location.belowbar)
- ofs_h6= max_arrows < 6 ? 0 : crosser_high(6, start_offset_h)
- plotchar(barstate.islast and ofs_h6!=0 ? true:na, offset=ofs_h6, char="⬇", color=arrow_down_color, size=size.small, location=location.abovebar)
- ofs_l6= max_arrows < 6 ? 0 : crosser_low(6, start_offset_l)
- plotchar(barstate.islast and ofs_l6!=0 ? true:na, offset=ofs_l6, char="⬆", color=arrow_up_color, size=size.small, location=location.belowbar)
- ofs_h7= max_arrows < 7 ? 0 : crosser_high(7, start_offset_h)
- plotchar(barstate.islast and ofs_h7!=0 ? true:na, offset=ofs_h7, char="⬇", color=arrow_down_color, size=size.small, location=location.abovebar)
- ofs_l7= max_arrows < 7 ? 0 : crosser_low(7, start_offset_l)
- plotchar(barstate.islast and ofs_l7!=0 ? true:na, offset=ofs_l7, char="⬆", color=arrow_up_color, size=size.small, location=location.belowbar)
- ofs_h8= max_arrows < 8 ? 0 : crosser_high(8, start_offset_h)
- plotchar(barstate.islast and ofs_h8!=0 ? true:na, offset=ofs_h8, char="⬇", color=arrow_down_color, size=size.small, location=location.abovebar)
- ofs_l8= max_arrows < 8 ? 0 : crosser_low(8, start_offset_l)
- plotchar(barstate.islast and ofs_l8!=0 ? true:na, offset=ofs_l8, char="⬆", color=arrow_up_color, size=size.small, location=location.belowbar)
- ofs_h9= max_arrows < 9 ? 0 : crosser_high(9, start_offset_h)
- plotchar(barstate.islast and ofs_h9!=0 ? true:na, offset=ofs_h9, char="⬇", color=arrow_down_color, size=size.small, location=location.abovebar)
- ofs_l9= max_arrows < 9 ? 0 : crosser_low(9, start_offset_l)
- plotchar(barstate.islast and ofs_l9!=0 ? true:na, offset=ofs_l9, char="⬆", color=arrow_up_color, size=size.small, location=location.belowbar)
- ofs_h10= max_arrows < 10 ? 0 : crosser_high(10, start_offset_h)
- plotchar(barstate.islast and ofs_h10!=0 ? true:na, offset=ofs_h10, char="⬇", color=arrow_down_color, size=size.small, location=location.abovebar)
- ofs_l10= max_arrows < 10 ? 0 : crosser_low(10, start_offset_l)
- plotchar(barstate.islast and ofs_l10!=0 ? true:na, offset=ofs_l10, char="⬆", color=arrow_up_color, size=size.small, location=location.belowbar)
Add Comment
Please, Sign In to add comment