Advertisement
xmd79

Dare_2_Trade magic

Jan 11th, 2023
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.89 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. // Β© saipranayvudatha
  3.  
  4. //@version=5
  5.  
  6. indicator(title='Dare_2_Trade magic', overlay=true, precision=4, linktoseries=false, max_bars_back=1000, max_lines_count=500)
  7.  
  8. // Color
  9. upcolor = color.new(#047e37, 0)
  10. downcolor = color.new(#ee2906, 0)
  11. themecolor = color.new(#000000, 0)
  12.  
  13.  
  14. turn = input(true, title='bulb', inline='bulbπŸ’‘')
  15. arrow = input(true, title='Arrow Confim', inline='scalp')
  16.  
  17. reversal = input(false, title='Reversal Zone')
  18.  
  19.  
  20.  
  21. rsiValue = ta.rsi(close, 7)
  22. isOverbought = rsiValue >= 65
  23. isOversold = rsiValue <= 35
  24.  
  25. rsiValue1 = ta.rsi(close, 15)
  26. isOverbought1 = rsiValue1 >= 65
  27. isOversold1 = rsiValue1 <= 35
  28.  
  29. rsiValue2 = ta.rsi(close, 15)
  30. isOverbought2 = rsiValue1 >= 65
  31. isOversold2 = rsiValue1 <= 35
  32.  
  33. // State of the last extreme 0 for initialization, 1 = overbought, 2 = oversold
  34. var laststate = 0
  35. var laststate1 = 0
  36. var laststate2 = 0
  37.  
  38. // Highest and Lowest prices since the last state change
  39. var hh = low
  40. var ll = high
  41. var hh1 = low
  42. var ll1 = high
  43. var hh2 = low
  44. var ll2 = high
  45.  
  46. // Labels
  47. var label labelll = na
  48. var label labelhh = na
  49. var label labelll1 = na
  50. var label labelhh1 = na
  51. var label labelll2 = na
  52. var label labelhh2 = na
  53.  
  54. // Swing lines
  55. var line line_up = na
  56. var line line_down = na
  57. var line line_up1 = na
  58. var line line_down1 = na
  59. var line line_up2 = na
  60. var line line_down2 = na
  61.  
  62. var last_actual_label_hh_price = 0.0
  63. var last_actual_label_ll_price = 0.0
  64. var last_actual_label_hh_price1 = 0.0
  65. var last_actual_label_ll_price1 = 0.0
  66. var last_actual_label_hh_price2 = 0.0
  67. var last_actual_label_ll_price2 = 0.0
  68.  
  69. // FUNCTIONS
  70. obLabelText1() =>
  71. if last_actual_label_hh_price1 < high
  72. 'Reversal Zone'
  73. else
  74. 'Reversal Zone'
  75.  
  76. osLabelText1() =>
  77. if last_actual_label_ll_price1 < low
  78. 'Reversal Zone'
  79. else
  80. 'Reversal Zone'
  81.  
  82.  
  83. // Create oversold or overbought label
  84. createOverBoughtLabel(isIt) =>
  85. if isIt
  86. label.new(x=bar_index, y=na, yloc=yloc.price, style=label.style_circle, color=color.new(downcolor, 50), size=size.tiny)
  87. else
  88. label.new(x=bar_index, y=na, yloc=yloc.price, style=label.style_circle, color=color.new(upcolor, 50), size=size.tiny)
  89.  
  90. createOverBoughtLabel1(isIt1) =>
  91. if isIt1
  92. label.new(x=bar_index, y=na, yloc=yloc.abovebar, style=label.style_label_down, color=downcolor, size=size.normal, text=obLabelText1(), textcolor=color.white)
  93. else
  94. label.new(x=bar_index, y=na, yloc=yloc.belowbar, style=label.style_label_up, color=upcolor, size=size.normal, text=osLabelText1(), textcolor=color.white)
  95.  
  96. createOverBoughtLabel2(isIt2) =>
  97. if isIt2
  98. label.new(x=bar_index, y=na, yloc=yloc.abovebar, style=label.style_triangledown, color=downcolor, size=size.tiny)
  99. else
  100. label.new(x=bar_index, y=na, yloc=yloc.belowbar, style=label.style_triangleup, color=upcolor, size=size.tiny)
  101.  
  102.  
  103. // Move the oversold swing and label
  104. moveOversoldLabel() =>
  105. label.set_x(labelll, bar_index)
  106. label.set_y(labelll, low)
  107. // label.set_text(labelll, osLabelText())
  108. line.set_x1(line_down, bar_index)
  109. line.set_y1(line_down, low)
  110.  
  111. moveOverBoughtLabel() =>
  112. label.set_x(labelhh, bar_index)
  113. label.set_y(labelhh, high)
  114. // label.set_text(labelhh, obLabelText())
  115. line.set_x1(line_up, bar_index)
  116. line.set_y1(line_up, high)
  117.  
  118. moveOversoldLabel1() =>
  119. label.set_x(labelll1, bar_index)
  120. label.set_y(labelll1, low)
  121. label.set_text(labelll1, osLabelText1())
  122. line.set_x1(line_down1, bar_index)
  123. line.set_y1(line_down1, low)
  124.  
  125. moveOverBoughtLabel1() =>
  126. label.set_x(labelhh1, bar_index)
  127. label.set_y(labelhh1, high)
  128. label.set_text(labelhh1, obLabelText1())
  129. line.set_x1(line_up1, bar_index)
  130. line.set_y1(line_up1, high)
  131.  
  132. moveOversoldLabel2() =>
  133. label.set_x(labelll2, bar_index)
  134. label.set_y(labelll2, low)
  135. line.set_x1(line_down2, bar_index)
  136. line.set_y1(line_down2, low)
  137.  
  138. moveOverBoughtLabel2() =>
  139. label.set_x(labelhh2, bar_index)
  140. label.set_y(labelhh2, high)
  141. line.set_x1(line_up2, bar_index)
  142. line.set_y1(line_up2, high)
  143.  
  144. // We go from oversold straight to overbought NEW DRAWINGS CREATED HERE
  145. if laststate == 2 and isOverbought and turn
  146. hh := high
  147. labelhh := createOverBoughtLabel(true)
  148. last_actual_label_ll_price := label.get_y(labelll)
  149. labelll_ts = label.get_x(labelll)
  150. labelll_price = label.get_y(labelll)
  151. // line_up := line.new(x1=bar_index, y1=high, x2=labelll_ts, y2=labelll_price, width=1)
  152. line_up
  153.  
  154. if laststate1 == 2 and isOverbought1 and reversal
  155. hh1 := high
  156. labelhh1 := createOverBoughtLabel1(true)
  157. last_actual_label_ll_price1 := label.get_y(labelll1)
  158. labelll_ts1 = label.get_x(labelll1)
  159. labelll_price1 = label.get_y(labelll1)
  160. line_up1 := line.new(x1=bar_index, y1=high, x2=labelll_ts1, y2=labelll_price1, width=1)
  161. line_up1
  162.  
  163. if laststate2 == 2 and isOverbought2 and arrow
  164. hh2 := high
  165. labelhh2 := createOverBoughtLabel2(true)
  166. last_actual_label_ll_price2 := label.get_y(labelll2)
  167. labelll_ts2 = label.get_x(labelll2)
  168. labelll_price2 = label.get_y(labelll2)
  169. // line_up2 := line.new(x1=bar_index, y1=high, x2=labelll_ts2, y2=labelll_price2, width=1)
  170. line_up2
  171.  
  172.  
  173. // We go from overbought straight to oversold NEW DRAWINGS CREATED HERE
  174. if laststate == 1 and isOversold and turn
  175. ll := low
  176. labelll := createOverBoughtLabel(false)
  177. last_actual_label_hh_price := label.get_y(labelhh)
  178. labelhh_ts = label.get_x(labelhh)
  179. labelhh_price = label.get_y(labelhh)
  180. // line_down := line.new(x1=bar_index, y1=high, x2=labelhh_ts, y2=labelhh_price, width=1)
  181. line_down
  182.  
  183. if laststate1 == 1 and isOversold1 and reversal
  184. ll1 := low
  185. labelll1 := createOverBoughtLabel1(false)
  186. last_actual_label_hh_price1 := label.get_y(labelhh1)
  187. labelhh_ts1 = label.get_x(labelhh1)
  188. labelhh_price1 = label.get_y(labelhh1)
  189. line_down1 := line.new(x1=bar_index, y1=high, x2=labelhh_ts1, y2=labelhh_price1, width=1)
  190. line_down1
  191.  
  192. if laststate2 == 1 and isOversold2 and arrow
  193. ll2 := low
  194. labelll2 := createOverBoughtLabel2(false)
  195. last_actual_label_hh_price2 := label.get_y(labelhh2)
  196. labelhh_ts2 = label.get_x(labelhh2)
  197. labelhh_price2 = label.get_y(labelhh2)
  198. // line_down2 := line.new(x1=bar_index, y1=high, x2=labelhh_ts2, y2=labelhh_price2, width=1)
  199. line_down2
  200.  
  201. // If we are overbought
  202. if isOverbought and turn
  203. if high >= hh
  204. hh := high
  205. moveOverBoughtLabel()
  206. laststate := 1
  207. laststate
  208.  
  209. if isOverbought1 and reversal
  210. if high >= hh1
  211. hh1 := high
  212. moveOverBoughtLabel1()
  213. laststate1 := 1
  214. laststate1
  215.  
  216. if isOverbought2 and arrow
  217. if high >= hh2
  218. hh2 := high
  219. moveOverBoughtLabel2()
  220. laststate2 := 1
  221. laststate2
  222.  
  223. // If we are oversold
  224. if isOversold and turn
  225. if low <= ll
  226. ll := low
  227. moveOversoldLabel()
  228. laststate := 2
  229. laststate
  230.  
  231. if isOversold1 and reversal
  232. if low <= ll1
  233. ll1 := low
  234. moveOversoldLabel1()
  235. laststate1 := 2
  236. laststate1
  237.  
  238. if isOversold2 and arrow
  239. if low <= ll2
  240. ll2 := low
  241. moveOversoldLabel2()
  242. laststate2 := 2
  243. laststate2
  244.  
  245. // If last state was overbought and we are overbought
  246. if laststate == 1 and isOverbought and turn
  247. if hh <= high
  248. hh := high
  249. moveOverBoughtLabel()
  250.  
  251. if laststate1 == 1 and isOverbought1 and reversal
  252. if hh1 <= high
  253. hh1 := high
  254. moveOverBoughtLabel1()
  255.  
  256. if laststate2 == 1 and isOverbought2 and arrow
  257. if hh2 <= high
  258. hh2 := high
  259. moveOverBoughtLabel2()
  260.  
  261. //If we are oversold and the last state was oversold, move the drawings to the lowest price
  262. if laststate == 2 and isOversold and turn
  263. if low <= ll
  264. ll := low
  265. moveOversoldLabel()
  266.  
  267. if laststate1 == 2 and isOversold1 and reversal
  268. if low <= ll1
  269. ll1 := low
  270. moveOversoldLabel1()
  271.  
  272. if laststate2 == 2 and isOversold2 and arrow
  273. if low <= ll2
  274. ll2 := low
  275. moveOversoldLabel2()
  276.  
  277. // If last state was overbought
  278. if laststate == 1 and turn
  279. if hh <= high
  280. hh := high
  281. moveOverBoughtLabel()
  282.  
  283. if laststate1 == 1 and reversal
  284. if hh1 <= high
  285. hh1 := high
  286. moveOverBoughtLabel1()
  287.  
  288. if laststate2 == 1 and arrow
  289. if hh2 <= high
  290. hh2 := high
  291. moveOverBoughtLabel2()
  292.  
  293. // If last stare was oversold
  294. if laststate == 2 and turn
  295. if ll >= low
  296. ll := low
  297. moveOversoldLabel()
  298.  
  299. if laststate1 == 2 and reversal
  300. if ll1 >= low
  301. ll1 := low
  302. moveOversoldLabel1()
  303.  
  304. if laststate2 == 2 and arrow
  305. if ll2 >= low
  306. ll2 := low
  307. moveOversoldLabel2()
  308.  
  309. //-------------------------------------------------------------------------------------------------------------------------
  310.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement