Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © AlexSopa
- //@version=5
- indicator("Box Finder by AlexsOptions [STAT Trading]","AlexsOptions",overlay=true,max_bars_back = 10)
- var line upper_pivot = na
- var line lower_pivot = na
- var bars_since_range_exit = 0
- var bool inside_box = false
- var bool box_active = false
- var bool box_bullish = false
- var line active_line_upper = na
- var line active_line_lower = na
- use_motherbar = input(true)
- range_size = input.int(5)
- if use_motherbar and high[2] > high[1] and high[2] > high and low[2] < low[1] and low[2] < low and inside_box==false
- inside_box:= true
- line.delete(upper_pivot)
- upper_pivot:= line.new(bar_index[1],high[2],bar_index[0]+15,high[2],color=color.black,width=2)
- line.delete(lower_pivot)
- lower_pivot:= line.new(bar_index[1],low[2],bar_index[0]+15,low[2],color=color.black,width=2)
- float range_height = math.abs(upper_pivot.get_y1()-lower_pivot.get_y1())
- if inside_box
- if close > upper_pivot.get_y1()
- active_line_upper:= line.new(upper_pivot.get_x1(),upper_pivot.get_y1(),bar_index[0]+15,upper_pivot.get_y1(),color=color.black,style=line.style_dotted)
- active_line_lower:= line.new(lower_pivot.get_x1(),lower_pivot.get_y1(),bar_index[0]+15,lower_pivot.get_y1(),color=color.black,style=line.style_dotted)
- //line.new(lower_pivot.get_x1(),lower_pivot.get_y1()-range_height*1,bar_index[0]+15,lower_pivot.get_y1()-range_height*1,color=color.blue,style=line.style_solid)
- //line.new(lower_pivot.get_x1(),lower_pivot.get_y1()-range_height*2.5,bar_index[0]+15,lower_pivot.get_y1()-range_height*2.5,color=color.blue,style=line.style_dashed)
- //line.new(lower_pivot.get_x1(),lower_pivot.get_y1()-range_height*2.25,bar_index[0]+15,lower_pivot.get_y1()-range_height*2.25,color=color.blue,style=line.style_dashed)
- line.delete(lower_pivot)
- line.delete(upper_pivot)
- upper_pivot:=na
- lower_pivot:=na
- inside_box:=false
- box_active:=true
- box_bullish:=false
- if close < lower_pivot.get_y1()
- active_line_upper:= line.new(upper_pivot.get_x1(),upper_pivot.get_y1(),bar_index[0]+15,upper_pivot.get_y1(),color=color.black,style=line.style_dotted)
- active_line_lower:= line.new(lower_pivot.get_x1(),lower_pivot.get_y1(),bar_index[0]+15,lower_pivot.get_y1(),color=color.black,style=line.style_dotted)
- //line.new(upper_pivot.get_x1(),upper_pivot.get_y1()+range_height*1,bar_index[0]+15,upper_pivot.get_y1()+range_height*1,color=color.blue,style=line.style_solid)
- //line.new(upper_pivot.get_x1(),upper_pivot.get_y1()+range_height*2.5,bar_index[0]+15,upper_pivot.get_y1()+range_height*2.5,color=color.blue,style=line.style_dashed)
- //line.new(upper_pivot.get_x1(),upper_pivot.get_y1()+range_height*2.25,bar_index[0]+15,upper_pivot.get_y1()+range_height*2.25,color=color.blue,style=line.style_dashed)
- line.delete(lower_pivot)
- line.delete(upper_pivot)
- upper_pivot:=na
- lower_pivot:=na
- inside_box:=false
- box_active:=true
- box_bullish:=true
- short_signal = box_active and box_bullish == false and close < active_line_upper.get_y1()
- long_signal = box_active and box_bullish and close > active_line_lower.get_y1()
- plotshape(short_signal,'Signal Short',style=shape.arrowdown,location = location.abovebar,color=color.red,size=size.large)
- plotshape(long_signal,'Signal Long',style=shape.arrowup,location = location.belowbar,color=color.green,size=size.large)
- if short_signal or long_signal
- box_active:=false
- box_bullish:=false
- active_line_upper:=na
- active_line_lower:=na
Add Comment
Please, Sign In to add comment