AnthonyAlexander

Flag Pattern v0

Feb 8th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. //@version=2
  2. study("Flag Pattern",overlay=true)
  3.  
  4. length3 = 100
  5. conditionSeries3 = 0
  6. movingAvg = sma(close, length3)
  7. sum3 = 0
  8. for i3 = 0 to length3-1
  9. if (close[i3] > movingAvg[i3])
  10. sum3 := sum3 + 1
  11. conditionSeries3 := sum3>66?1:0
  12. ////
  13. length6 = 100
  14. conditionSeries6 = 0
  15. movingAvg6 = sma(close, length6)
  16. sum6 = 0
  17. for i6 = 0 to length6-1
  18. if (close[i6] < movingAvg[i6])
  19. sum6 := sum6 + 1
  20. conditionSeries6 := sum6>66?1:0
  21. ////
  22. start = 0.02
  23. increment = 0.02
  24. maximum = 0.2
  25. out = sar(start, increment, maximum)
  26.  
  27. ////
  28. zlength = 20
  29. conditionSeries = 0
  30. zsum = 0
  31. for i = 0 to zlength-1
  32. if (close[i] > out[i])
  33. zsum := zsum + 1
  34. conditionSeries := zsum>12?1:0
  35. /// var2
  36. length7 = 20
  37. conditionSeries7 = 0
  38. sum7 = 0
  39. for i7 = 0 to length7-1
  40. if (close[i7] < out[i7])
  41. sum7 := sum7 + 1
  42. conditionSeries7 := sum7>12?1:0
  43.  
  44.  
  45. ///
  46. length1 = 5
  47. conditionSeries1 = 0
  48. sum1 = 0
  49. for i1 = 0 to length1-1
  50. if (close[i1] < out[i1])
  51. sum1 := sum1 + 1
  52. conditionSeries1 := sum1>2?1:0
  53. ///
  54. length8 = 5
  55. conditionSeries8 = 0
  56. sum8 = 0
  57. for i8 = 0 to length8-1
  58. if (close[i8] > out[i8])
  59. sum8 := sum8 + 1
  60. conditionSeries8 := sum8>2?1:0
  61.  
  62.  
  63. ///
  64. zx1 = conditionSeries
  65. zx2 = close < out
  66. zx3 = conditionSeries1
  67. zx4 = conditionSeries3
  68. zx5 = not close <= lowest(close,10)
  69. zx6 = close > sma(close,20)
  70. zx0 = zx1 and zx2 and zx3 and zx4 and zx6
  71. 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]
  72.  
  73.  
  74. zv1 = conditionSeries6
  75. zv2 = close > out
  76. zv3 = conditionSeries7
  77. zv4 = conditionSeries8
  78. zv5 = not close >= highest(close,10)
  79. zv6 = close < sma(close,20)
  80. zv0 = zv1 and zv2 and zv3 and zv4 and zv6
  81. 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]
  82.  
  83.  
  84. plotshape(zx, text='Bull Flag', style=shape.labelup,title="Bull Flag", location=location.belowbar, color=green, textcolor=white, offset=0)
  85.  
  86.  
  87. plotshape(zv, text='Bear Flag', style=shape.labeldown,title="Bear Flag", location=location.abovebar, color=red, textcolor=white, offset=0)
  88.  
  89. alertcondition(zv, title='Bear Flag Pattern', message='Bear Flag Pattern Formed!')
  90. alertcondition(zx, title='Bull Flag Pattern', message='Bull Flag Pattern Formed!')
Add Comment
Please, Sign In to add comment