Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=2
- study("Flag Pattern",overlay=true)
- length3 = 100
- conditionSeries3 = 0
- movingAvg = sma(close, length3)
- sum3 = 0
- for i3 = 0 to length3-1
- if (close[i3] > movingAvg[i3])
- sum3 := sum3 + 1
- conditionSeries3 := sum3>66?1:0
- ////
- length6 = 100
- conditionSeries6 = 0
- movingAvg6 = sma(close, length6)
- sum6 = 0
- for i6 = 0 to length6-1
- if (close[i6] < movingAvg[i6])
- sum6 := sum6 + 1
- conditionSeries6 := sum6>66?1:0
- ////
- start = 0.02
- increment = 0.02
- maximum = 0.2
- out = sar(start, increment, maximum)
- ////
- zlength = 20
- conditionSeries = 0
- zsum = 0
- for i = 0 to zlength-1
- if (close[i] > out[i])
- zsum := zsum + 1
- conditionSeries := zsum>12?1:0
- /// var2
- length7 = 20
- conditionSeries7 = 0
- sum7 = 0
- for i7 = 0 to length7-1
- if (close[i7] < out[i7])
- sum7 := sum7 + 1
- conditionSeries7 := sum7>12?1:0
- ///
- length1 = 5
- conditionSeries1 = 0
- sum1 = 0
- for i1 = 0 to length1-1
- if (close[i1] < out[i1])
- sum1 := sum1 + 1
- conditionSeries1 := sum1>2?1:0
- ///
- length8 = 5
- conditionSeries8 = 0
- sum8 = 0
- for i8 = 0 to length8-1
- if (close[i8] > out[i8])
- sum8 := sum8 + 1
- conditionSeries8 := sum8>2?1:0
- ///
- zx1 = conditionSeries
- zx2 = close < out
- zx3 = conditionSeries1
- zx4 = conditionSeries3
- zx5 = not close <= lowest(close,10)
- zx6 = close > sma(close,20)
- zx0 = zx1 and zx2 and zx3 and zx4 and zx6
- zx = zx0 and not zx0[1] and not zx0[2] and not zx0[3] and not zx0[4] and not zx0[5] and not zx0[6] and not zx0[7] and not zx0[8] and not zx0[9] and not zx0[10]
- zv1 = conditionSeries6
- zv2 = close > out
- zv3 = conditionSeries7
- zv4 = conditionSeries8
- zv5 = not close >= highest(close,10)
- zv6 = close < sma(close,20)
- zv0 = zv1 and zv2 and zv3 and zv4 and zv6
- zv = zv0 and not zv0[1] and not zv0[2] and not zv0[3] and not zv0[4] and not zv0[5] and not zv0[6] and not zv0[7] and not zv0[8] and not zv0[9] and not zv0[10]
- plotshape(zx, text='Bull Flag', style=shape.labelup,title="Bull Flag", location=location.belowbar, color=green, textcolor=white, offset=0)
- plotshape(zv, text='Bear Flag', style=shape.labeldown,title="Bear Flag", location=location.abovebar, color=red, textcolor=white, offset=0)
- alertcondition(zv, title='Bear Flag Pattern', message='Bear Flag Pattern Formed!')
- alertcondition(zx, title='Bull Flag Pattern', message='Bull Flag Pattern Formed!')
Add Comment
Please, Sign In to add comment