Advertisement
xmd79

FOREX MASTER PATTERN Value Lines by nnam

Jan 11th, 2023
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.08 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © nnamdert
  3.  
  4. //@version=5
  5. indicator("FOREX MASTER PATTERN Value Lines by nnam", overlay=true, max_lines_count = 500)
  6. //BEGIN SCRIPT
  7. //HANDLES MAX_LINES_COUNTS ISSUE================================================================================================//
  8. lineLimitInput = input.int( //
  9. defval = 12, //
  10. minval = 1, //
  11. maxval = 499, //
  12. title = 'Max Lines to Show', //
  13. tooltip = 'Adjust this number to increase or decrease the total number of lines seen on the chart. (ONLY this indicator)', //
  14. group = 'Line Settings' //
  15. ) //
  16. if array.size(line.all) > lineLimitInput //
  17. for i = 0 to array.size(line.all) - lineLimitInput - 1 //
  18. line.delete(array.get(line.all, i)) //
  19. //BEGIN Get User Inputs=========================================================================================================//
  20. //BEGIN Get User Inputs - Line Settings //
  21. show_lines = input.bool( //
  22. defval = true, //
  23. title = 'Show Lines on chart', //
  24. group = 'Line Settings', //
  25. tooltip = 'Unchecking this box will hide ALL lines on the chart - NO LINES generated by this indicator will appear' //
  26. ) // //
  27. show_valuelines = input.bool( //
  28. defval = true, //
  29. title = 'Show Value Lines on chart', //
  30. group = 'Line Settings', //
  31. tooltip='Unchecking this box will hide the Forex Master Pattern Value Lines on the chart.' //
  32. ) //
  33. value_line_width_settings = input.int( //
  34. defval = 2, //
  35. title = 'Set Value Line Width', //
  36. group = 'Line Settings', //
  37. tooltip = 'Use this option to set the width of the Forex master Pattern Value Line (default is 1, max is 8)', //
  38. minval = 1, //
  39. maxval = 8 //
  40. ) //
  41. only_show_last_value_line = input.bool( //
  42. defval = false, //
  43. title = 'Only show last Value Line on Chart?', //
  44. group = 'Line Settings', //
  45. tooltip = 'If box is checked only most recent Value Line will be visible, even if most recent box is not in the same location' // //
  46. ) //
  47. showOnlyLastBox = input.bool( //
  48. defval = false, //
  49. title = 'show last box only', //
  50. group = 'Box Settings', //
  51. tooltip = 'If box is checked only the most recent contraction box will be shown on the chart' //
  52. ) //
  53. show_Expansion_Area = input.bool( //
  54. defval = false, //
  55. title = 'Show Expansion Area (coming soon)', //
  56. group = 'Expansion Area Settings (coming Soon!)', //
  57. tooltip = 'This feature is not implemented yet' //
  58. ) //
  59. show_expansion_guidelines = input.bool( //
  60. defval = false, //
  61. title = 'Show Expansion GuideLines on Chart (coming soon)', //
  62. group = 'Expansion Area Settings (coming Soon!)', //
  63. tooltip = 'This feature is not implemented yet' //
  64. ) //
  65. //END Get User Inputs - Line Settings===========================================================================================//
  66. //BEGIN Get User Inputs - BARS==================================================================================================//
  67. //BEGIN Get User Inputs - BAR COLORS //
  68. color_code_candles = input.bool( //
  69. defval=true, //
  70. title = 'Color Code the Candles', //
  71. tooltip = 'Turn on Color Coded Candles. Expansion. Contraction, Bullish and Bearish Candles will be shaded as listed below.', //
  72. group = 'Candle Colors' //
  73. ) //
  74. inside_bar_color = input.color( //
  75. defval = color.white, //
  76. title = 'Contraction Candles', //
  77. tooltip = 'This is the color of the Strat Inside Bar - otherwise known as 1', //
  78. group = 'Candle Colors', //
  79. inline = 'inside outside', //
  80. confirm = false) //
  81. outside_bar_color = input.color( //
  82. defval = color.yellow, //
  83. title = 'Expansion Candles', //
  84. tooltip = 'This is the color of the Strat Outside Bar - otherwise known as 3', //
  85. group = 'Candle Colors', //
  86. inline = 'inside outside', //
  87. confirm = false) //
  88. twoup_bar_color = input.color( //
  89. defval = color.lime, //
  90. title = 'Bullish Candle', //
  91. tooltip = 'This is the color of the Strat 2 UP Bar', //
  92. group = 'Candle Colors', //
  93. inline = 'twobars', //
  94. confirm = false) //
  95. twodown_bar_color = input.color( //
  96. defval = color.maroon, //
  97. title = 'Bearish Candle', //
  98. tooltip = 'This is the color of the Strat 2 DOWN Bar', //
  99. group = 'Candle Colors', //
  100. inline = 'twobars', //
  101. confirm = false) //
  102. bearish_engulfing_bar_color = input.color( //
  103. defval = #f57c00, //
  104. title = 'Bearish Engulfing Candle', //
  105. tooltip = 'This is the color of a Bearish Engulfing Candle', //
  106. group = 'Candle Colors', //
  107. inline = 'engulfing', //
  108. confirm = false) //
  109. bullish_engulfing_bar_color = input.color( //
  110. defval = #f57c00, //
  111. title = 'Bullish Engulfing Candle', //
  112. tooltip = 'This is the color of a Bullish Engulfing Candle', //
  113. group = 'Candle Colors', //
  114. inline = 'engulfing', //
  115. confirm = false) //
  116. //END Get User Inputs - BAR COLORS //
  117. //BEGIN Get User Inputs - ENGULFING BARS========================================================================================//
  118. show_engulfing_patterns = input.bool( //
  119. defval=true, //
  120. title = 'Show Engulfing Patterns?', //
  121. group = 'Engulfing Patterns' //
  122. ) //
  123. show_bullish_engulfing_patterns = input.bool( //
  124. defval=true, //
  125. title ='Show Bullish Engulfing Candles', //
  126. group = 'Engulfing Patterns') //
  127. show_bearish_engulfing_patterns = input.bool( //
  128. defval=true, //
  129. title ='Show Bearish Engulfing Candles', //
  130. group = 'Engulfing Patterns') //
  131. //END Get User Inputs - ENGULFING BARS==========================================================================================//
  132. //BEGIN STRAT SCENARIO INDENTIFIERS=============================================================================================//
  133. atr = ta.atr(14) //
  134. bar_green = close >= open //
  135. bar_red = close < open //
  136. bar_inside = (high <= high[1]) and (low >= low[1]) //
  137. bar_twoup = (high > high[1]) and (low >= low[1]) //
  138. bar_twodown = (high <= high[1]) and (low < low[1]) //
  139. bar_outside = (high > high[1]) and (low < low[1]) //
  140. bar_openTime = time //
  141. bar_lowPrice = low //
  142. bar_highPrice = high //
  143. bar_two_up_green = bar_twoup and bar_green //
  144. bar_two_up_red = bar_twoup and bar_red //
  145. bar_two_down_red = bar_twodown and bar_red //
  146. bar_inside_green = bar_inside and bar_green //
  147. bar_outside_green = bar_outside and bar_green //
  148. bar_outside_red = bar_outside and bar_red //
  149. bar_continuation_green = open[1] <= low and bar_green //
  150. //END STRAT SCENARIO INDENTIFIERS===============================================================================================//
  151. //BEGIN BEARISH ENGULFING DEFINITION+===========================================================================================//
  152. bar_bearish_engulfing = //
  153. //CLOSE Price of the CURRENT Engulfing candle /session must be (less than) the OPEN Price of PREVIOUS session //
  154. close < open[1] //
  155. //OPEN Price of the CURRENT Engulfing candle /session must be (greater than) the CLOSE Price of PREVIOUS session //
  156. and open > close[1] //
  157. //Previous Session (before the engulfing candle) - the candle /session being Engulfed MUST be a GREEN candle /session //
  158. and (close[1] >= open[1]) //
  159. //OPEN and CLOSE of the CURRENT Engulfing Session is (greater than or equal to) the previous candle /session being Engulfed and //
  160. //is LARGER by a factor of 2 - (or basically twice as big) - ENGULFING CANDLE MUST BE RED [open - close = RED] //
  161. and (open - close) >= ((close[1] - open[1]) * 6) //
  162. //CURRENT Engulfing candle /session needs to be (greater than) the atr //
  163. and (open - close) >= atr //
  164. //END BEARISH ENGULFING DEFINITION==============================================================================================//
  165. //BEGIN BULLISH ENGULFING DEFINITION============================================================================================//
  166. bar_bullish_engulfing = //
  167. close > open[1] //
  168. and open < close[1] //
  169. and (close[1] <= open[1]) //
  170. and (close - open) >= ((open[1] - close[1]) * 6) //
  171. and (close - open) >= atr //
  172. //END BULLISH ENGULFING DEFINITION==============================================================================================//
  173. //Begin Bar Colors==============================================================================================================//
  174. //Expansion Candle also known as Strat 3 Outside Bar //
  175. barcolor( //
  176. not bar_bearish_engulfing //
  177. and not bar_bullish_engulfing //
  178. and color_code_candles //
  179. and (high > high[1] //
  180. and low < low[1]) ? //
  181. color.new(outside_bar_color, 0) : na, title = '3 Outside Bar') //
  182. barcolor( //
  183. not bar_bullish_engulfing //
  184. and not bar_bearish_engulfing //
  185. and color_code_candles //
  186. and (high > high[1] //
  187. and low >= low[1]) ? //
  188. color.new(twoup_bar_color, 0) : na, title = '2 up') //
  189. barcolor( //
  190. not bar_bullish_engulfing //
  191. and not bar_bearish_engulfing //
  192. and color_code_candles //
  193. and (high <= high[1] //
  194. and low < low[1]) ? //
  195. color.new(twodown_bar_color, 0) : na, title = '2 down') //
  196. barcolor( //
  197. not bar_bullish_engulfing //
  198. and not bar_bearish_engulfing //
  199. and color_code_candles //
  200. and (high <= high[1] //
  201. and low >= low[1]) ? //
  202. color.new(inside_bar_color, 0) : na, title = '1 Inside Bar') //
  203. barcolor( //
  204. bar_bullish_engulfing //
  205. and show_bullish_engulfing_patterns //
  206. and show_engulfing_patterns ? //
  207. color.new(bullish_engulfing_bar_color, 0) : na, title = 'Bullish Engulfing') //
  208. barcolor( //
  209. bar_bearish_engulfing //
  210. and show_bearish_engulfing_patterns //
  211. and show_engulfing_patterns ? //
  212. color.new(bearish_engulfing_bar_color, 0) : na, title = 'Bearish Engulfing') //
  213. //bear_candle = open > close //
  214. //bull_candle = close > open //
  215. //plotcandle(bull_candle ? open : na, bull_candle ? high: na, bull_candle ? low: na, bull_candle ? close: na, //
  216. // wickcolor=color.new(color.lime, 0), //
  217. // bordercolor=color.new(color.lime, 0) //
  218. // ) //
  219. //plotcandle(bear_candle ? open: na, bear_candle ? high: na, bear_candle ? low: na, bear_candle ? close: na, //
  220. // wickcolor=color.new(color.red, 0), //
  221. // bordercolor=color.new(color.red, 0) //
  222. // ) //
  223. //End Bar Colors================================================================================================================//
  224. // //
  225. //BEGIN CONTRACTION BOXES=======================================================================================================//
  226. //showOnlyLastBox = input.bool(false, title = 'show last box only') //is above in global inputs leaving here for //
  227. //standalone box script if required //
  228. // variables //
  229. var box myBox = na //
  230.  
  231. var float boxHigh = na //
  232. var float boxLow = na //
  233.  
  234. varip int barIndex = 1 //
  235. varip bool f = false //
  236. //
  237. oneone = bar_inside //request.security(syminfo.tickerid, 'D', bar_inside) // not recommended as it can cause issues //
  238. if oneone == true
  239. 1
  240. else
  241. na
  242. //
  243. if oneone and not oneone[1] and barstate.isconfirmed //
  244. boxHigh := high[1] // was high[1]
  245. boxLow := low[1] // was high[1]
  246. f := true
  247.  
  248. if showOnlyLastBox
  249. box.delete(id=myBox[1])
  250.  
  251. myBox := box.new(bar_index-1, high, bar_index, low, bgcolor=color.new(#405fcf, 70), border_width=1) // high and low were [1]
  252. barIndex := barIndex+1
  253.  
  254. else if oneone and oneone[1] and barstate.isconfirmed //
  255. box.set_right(myBox[1], bar_index)
  256. barIndex := barIndex+1
  257.  
  258. else if oneone[1] and not oneone and barstate.isconfirmed //
  259. box.set_right(myBox[1], bar_index)
  260. barIndex := barIndex
  261.  
  262. else if not oneone[1] and not oneone //
  263. f := false
  264. //END CONTRACTION BOXES=========================================================================================================//
  265. //lines //
  266. //midline //
  267. //EmaCross = ta.crossover(shortest, short) (future use) //
  268. var float middleBody = na
  269. //midline = line.new(bar_index[1], middleBody, bar_index+100, middleBody, width = value_line_width_settings) //, extend=extend.right)
  270.  
  271. if oneone and oneone[1] and show_lines and not only_show_last_value_line
  272. middleBody := (((high + high[1]) / 2) + ((low + low[1]) / 2)) / 2 //was (open + close) / 2 or (high + low) / 2
  273. midline = line.new(bar_index[1], middleBody, bar_index+100, middleBody, width = value_line_width_settings) //, extend=extend.right)
  274.  
  275. else
  276. if oneone and oneone[1] and show_lines and only_show_last_value_line
  277. middleBody := (((high + high[1]) / 2) + ((low + low[1]) / 2)) / 2 //was (open + close) / 2 or (high + low) / 2
  278. midline = line.new(bar_index[1], middleBody, bar_index+100, middleBody, width = value_line_width_settings) //, extend=extend.right)
  279. line.delete(midline[1])
  280.  
  281. NotValid = not oneone
  282. if NotValid
  283. middleBody := na
  284.  
  285.  
  286. //plot(middleBody, color=color.lime, style=plot.style_linebr, trackprice=true)
  287. //END MIDLINE SCRIPT=========================================================================================================================//
  288. //ALERTS
  289. alertcondition(
  290. bar_bullish_engulfing,
  291. title = 'Bullish Engulfing Alert',
  292. message = 'Bullish Engulfing Pattern Identified'
  293. )
  294. alertcondition(
  295. bar_bearish_engulfing,
  296. title = 'Bearish Engulfing Alert',
  297. message = 'Bearish Engulfing Pattern Identified'
  298. )
  299. //===========
  300. //PLOTS
  301. //plotshape(series, title, style, location, color, offset, text, textcolor, editable, size, show_last, display) → void
  302. //show_engulfing_patterns and show_bullish_engulfing_patterns ?
  303. plotshape(not show_engulfing_patterns or not show_bullish_engulfing_patterns ? na :
  304. bar_bullish_engulfing,
  305. title = 'Bullish Engulfing Plot',
  306. style = shape.arrowup,
  307. location = location.belowbar,
  308. color = color.new(#f57c00,0),
  309. size = size.large,
  310. show_last = 2000)
  311. //show_engulfing_patterns and show_bearish_engulfing_patterns ?
  312. plotshape(not show_engulfing_patterns or not show_bearish_engulfing_patterns ? na :
  313. bar_bearish_engulfing,
  314. title = 'Bearish Engulfing Plot',
  315. style = shape.arrowdown,
  316. location = location.abovebar,
  317. color = color.new(#f57c00,0),
  318. size = size.large,
  319. show_last = 2000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement