xmd79

Auto Target Price

Jan 2nd, 2023
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.18 KB | None | 0 0
  1. //@version=5
  2. //The Target Price is according The Rule of Price Movement
  3. //Use as TP for Intraday / Short-term Trader
  4. //With three categories of price: Price less than 0.2, Price in between 0.2-1, and Price higher than 1
  5. //Each with TP1, TP2, TP3
  6.  
  7. //This rule I learn from traders in group, but I found it inconvenience that I have to calculate every times for every trades.
  8. //Then I will be trading alot of error if i do so.
  9. //Thus I think of to make this rule to an indicator to conveninet use.
  10.  
  11. //Pro: Other than Using BB, Support and Resistant, Fibbonaci and so on as Target Price, this may be a good reference
  12. //Con: Stock Price which is extremely high may not work well ,because the categories of price is only till price higher than 1.
  13. //It may need some adjustment for higher stock price as TP
  14. //Author: sxw6329 ; Date:27/02/21
  15. //Thanks to @RozaniGhani-RG helped tidy up the code
  16.  
  17.  
  18. indicator('Auto Target Price', shorttitle='Auto Target Price', overlay=true)
  19. offline = input(defval=true, title='SHOW TARGET PRICE LINE/LABEL')
  20. AA = input(defval=close, title='Buy Price')
  21. Ab = input(defval=false, title='Or')
  22. Ac = input(defval=0.1, title='Other Price')
  23. A = Ab ? Ac : AA
  24.  
  25. //TP1
  26. c1 = A < 0.2
  27. tp1 = A + 0.005
  28. tp1e = A + 0.010
  29. tp2 = A + 0.015
  30. tp2e = A + 0.020
  31. tp3 = A + 0.025
  32. tp3e = A + 0.040
  33.  
  34. //TP2
  35. c2 = A >= 0.2 and A <= 1
  36. btp1 = A + 0.015
  37. btp1e = A + 0.025
  38. btp2 = A + 0.030
  39. btp2e = A + 0.050
  40. btp3 = A + 0.060
  41. btp3e = A + 0.100
  42.  
  43. //TP3
  44. c3 = A > 1
  45. ctp1 = A + 0.03
  46. ctp1e = A + 0.06
  47. ctp2 = A + 0.07
  48. ctp2e = A + 0.12
  49. ctp3 = A + 0.13
  50. ctp3e = A + 0.24
  51.  
  52.  
  53. colorlabel = c1 ? color.new(color.black, 15) : c2 ? color.new(color.black, 15) : c3 ? color.new(color.black, 15) : na
  54.  
  55. fun(_cond, _val1, _val2, _val3, _val4, _val5, _val6) =>
  56. fun1 = offline ? _cond ? _val1 : na : na
  57. fun2 = offline ? _cond ? _val2 : na : na
  58. fun3 = offline ? _cond ? _val3 : na : na
  59. fun4 = offline ? _cond ? _val4 : na : na
  60. fun5 = offline ? _cond ? _val5 : na : na
  61. fun6 = offline ? _cond ? _val6 : na : na
  62. [fun1, fun2, fun3, fun4, fun5, fun6]
  63.  
  64. [cctp1, cctp2, cctp3, cctp4, cctp5, cctp6] = fun(c1, tp1, tp1e, tp2, tp2e, tp3, tp3e)
  65. [cctp7, cctp8, cctp9, cctp10, cctp11, cctp12] = fun(c2, btp1, btp1e, btp2, btp2e, btp3, btp3e)
  66. [cctp13, cctp14, cctp15, cctp16, cctp17, cctp18] = fun(c3, ctp1, ctp1e, ctp2, ctp2e, ctp3, ctp3e)
  67.  
  68. fun_line(_y) =>
  69. var line _id = na
  70. line.delete(_id)
  71. _id := line.new(bar_index, _y, bar_index - 1, _y, color=color.green, extend=extend.right, style=line.style_dotted)
  72. _id
  73.  
  74. fun_line2(_y) =>
  75. var line _id = na
  76. line.delete(_id)
  77. _id := line.new(bar_index, _y, bar_index - 1, _y, color=color.blue, extend=extend.right, style=line.style_dotted)
  78. _id
  79.  
  80.  
  81. fun_line3(_y) =>
  82. var line _id = na
  83. line.delete(_id)
  84. _id := line.new(bar_index, _y, bar_index - 1, _y, color=color.red, extend=extend.right, style=line.style_dotted)
  85. _id
  86.  
  87. s1 = fun_line(cctp1)
  88. s2 = fun_line(cctp2)
  89. s3 = fun_line2(cctp3)
  90. s4 = fun_line2(cctp4)
  91. s5 = fun_line3(cctp5)
  92. s6 = fun_line3(cctp6)
  93. s7 = fun_line(cctp7)
  94. s8 = fun_line(cctp8)
  95. s9 = fun_line2(cctp9)
  96. s10 = fun_line2(cctp10)
  97. s11 = fun_line3(cctp11)
  98. s12 = fun_line3(cctp12)
  99. s13 = fun_line(cctp13)
  100. s14 = fun_line(cctp14)
  101. s15 = fun_line2(cctp15)
  102. s16 = fun_line2(cctp16)
  103. s17 = fun_line3(cctp17)
  104. s18 = fun_line3(cctp18)
  105.  
  106. fun_text(_x1, _x2) =>
  107. 'TP' + str.tostring(_x1) + ': ' + str.tostring(_x2, '#0.000')
  108.  
  109. text1 = fun_text(1, cctp1)
  110. text2 = fun_text(1, cctp2)
  111. text3 = fun_text(2, cctp3)
  112. text4 = fun_text(2, cctp4)
  113. text5 = fun_text(3, cctp5)
  114. text6 = fun_text(3, cctp6)
  115. text7 = fun_text(1, cctp7)
  116. text8 = fun_text(1, cctp8)
  117. text9 = fun_text(2, cctp9)
  118. text10 = fun_text(2, cctp10)
  119. text11 = fun_text(3, cctp11)
  120. text12 = fun_text(3, cctp12)
  121. text13 = fun_text(1, cctp13)
  122. text14 = fun_text(1, cctp14)
  123. text15 = fun_text(2, cctp15)
  124. text16 = fun_text(2, cctp16)
  125. text17 = fun_text(3, cctp17)
  126. text18 = fun_text(3, cctp18)
  127.  
  128. fun_cond(_text1, _text2, _text3) =>
  129. c1 ? _text1 : c2 ? _text2 : c3 ? _text3 : na
  130.  
  131. ccc1 = fun_cond(text1, text7, text13)
  132. ccc2 = fun_cond(text2, text8, text14)
  133. ccc3 = fun_cond(text3, text9, text15)
  134. ccc4 = fun_cond(text4, text10, text16)
  135. ccc5 = fun_cond(text5, text11, text17)
  136. ccc6 = fun_cond(text6, text12, text18)
  137.  
  138. ttt1 = fun_cond(cctp1, cctp7, cctp13)
  139. ttt2 = fun_cond(cctp2, cctp8, cctp14)
  140. ttt3 = fun_cond(cctp3, cctp9, cctp15)
  141. ttt4 = fun_cond(cctp4, cctp10, cctp16)
  142. ttt5 = fun_cond(cctp5, cctp11, cctp17)
  143. ttt6 = fun_cond(cctp6, cctp12, cctp18)
  144.  
  145. fun_label(_y, _text, _color) =>
  146. var label id = na
  147. label.delete(id)
  148. id := label.new(time + 10000, _y, _text, xloc.bar_time, yloc.price, size=size.small, color=color.new(color.blue, 100), style=label.style_label_left, textcolor=_color)
  149. id
  150.  
  151. sss1 = fun_label(ttt1, ccc1, color.green)
  152. sss2 = fun_label(ttt2, ccc2, color.green)
  153. sss3 = fun_label(ttt3, ccc3, color.blue)
  154. sss4 = fun_label(ttt4, ccc4, color.blue)
  155. sss5 = fun_label(ttt5, ccc5, color.red)
  156. sss6 = fun_label(ttt6, ccc6, color.red)
  157.  
  158. fun_tp() =>
  159. n = '\n'
  160. d = ' - '
  161. texta = 'PRICE < 0.2 '
  162. textb = 'PRICE 0.2 - 1.0 '
  163. textc = 'PRICE > 1.0 '
  164. string title = na
  165. var float L1 = na
  166. var float H1 = na
  167. var float L2 = na
  168. var float H2 = na
  169. var float L3 = na
  170. var float H3 = na
  171. if c1
  172. L1 := tp1
  173. H1 := tp1e
  174. L2 := tp2
  175. H2 := tp2e
  176. L3 := tp3
  177. H3 := tp3e
  178. H3
  179. if c2
  180. L1 := btp1
  181. H1 := btp1e
  182. L2 := btp2
  183. H2 := btp2e
  184. L3 := btp3
  185. H3 := btp3e
  186. H3
  187. if c3
  188. L1 := ctp1
  189. H1 := ctp1e
  190. L2 := ctp2
  191. H2 := ctp2e
  192. L3 := ctp3
  193. H3 := ctp3e
  194. H3
  195. _text = title + n + 'TP1: ' + str.tostring(L1, '#0.000') + d + str.tostring(H1, '#0.000') + n + 'TP2: ' + str.tostring(L2, '#0.000') + d + str.tostring(H2, '#0.000') + n + 'TP3: ' + str.tostring(L3, '#0.000') + d + str.tostring(H3, '#0.000')
  196. var label id = na
  197. label.delete(id)
  198.  
  199. id := label.new(time + 10000, close, _text, xloc.bar_time, yloc.price, size=size.small, color=colorlabel, style=label.style_label_left, textcolor=color.white)
  200. id
  201.  
  202. sss = offline ? na : fun_tp()
  203.  
  204. //End//
  205.  
  206.  
Advertisement
Add Comment
Please, Sign In to add comment