SHOW:
|
|
- or go back to the newest paste.
| 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ | |
| 2 | // © AlexSopa | |
| 3 | ||
| 4 | //@version=5 | |
| 5 | indicator("Box Finder by AlexsOptions [STAT Trading]","AlexsOptions",overlay=true,max_bars_back = 10)
| |
| 6 | ||
| 7 | var line upper_pivot = na | |
| 8 | var line lower_pivot = na | |
| 9 | ||
| 10 | var bars_since_range_exit = 0 | |
| 11 | ||
| 12 | var bool inside_box = false | |
| 13 | var bool box_active = false | |
| 14 | var bool box_bullish = false | |
| 15 | var line active_line_upper = na | |
| 16 | var line active_line_lower = na | |
| 17 | ||
| 18 | use_motherbar = input(true) | |
| 19 | range_size = input.int(5) | |
| 20 | ||
| 21 | ||
| 22 | 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 | |
| 23 | inside_box:= true | |
| 24 | line.delete(upper_pivot) | |
| 25 | upper_pivot:= line.new(bar_index[1],high[2],bar_index[0]+15,high[2],color=color.black,width=2) | |
| 26 | line.delete(lower_pivot) | |
| 27 | lower_pivot:= line.new(bar_index[1],low[2],bar_index[0]+15,low[2],color=color.black,width=2) | |
| 28 | ||
| 29 | float range_height = math.abs(upper_pivot.get_y1()-lower_pivot.get_y1()) | |
| 30 | ||
| 31 | if inside_box | |
| 32 | if close > upper_pivot.get_y1() | |
| 33 | 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) | |
| 34 | 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) | |
| 35 | //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) | |
| 36 | //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) | |
| 37 | //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) | |
| 38 | line.delete(lower_pivot) | |
| 39 | line.delete(upper_pivot) | |
| 40 | ||
| 41 | upper_pivot:=na | |
| 42 | lower_pivot:=na | |
| 43 | ||
| 44 | inside_box:=false | |
| 45 | box_active:=true | |
| 46 | box_bullish:=false | |
| 47 | if close < lower_pivot.get_y1() | |
| 48 | 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) | |
| 49 | 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) | |
| 50 | //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) | |
| 51 | //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) | |
| 52 | //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) | |
| 53 | line.delete(lower_pivot) | |
| 54 | line.delete(upper_pivot) | |
| 55 | ||
| 56 | upper_pivot:=na | |
| 57 | lower_pivot:=na | |
| 58 | ||
| 59 | inside_box:=false | |
| 60 | box_active:=true | |
| 61 | box_bullish:=true | |
| 62 | ||
| 63 | short_signal = box_active and box_bullish == false and close < active_line_upper.get_y1() | |
| 64 | long_signal = box_active and box_bullish and close > active_line_lower.get_y1() | |
| 65 | ||
| 66 | plotshape(short_signal,'Signal Short',style=shape.arrowdown,location = location.abovebar,color=color.red,size=size.large) | |
| 67 | plotshape(long_signal,'Signal Long',style=shape.arrowup,location = location.belowbar,color=color.green,size=size.large) | |
| 68 | ||
| 69 | if short_signal or long_signal | |
| 70 | box_active:=false | |
| 71 | box_bullish:=false | |
| 72 | active_line_upper:=na | |
| 73 | active_line_lower:=na | |
| 74 |