Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- //The Target Price is according The Rule of Price Movement
- //Use as TP for Intraday / Short-term Trader
- //With three categories of price: Price less than 0.2, Price in between 0.2-1, and Price higher than 1
- //Each with TP1, TP2, TP3
- //This rule I learn from traders in group, but I found it inconvenience that I have to calculate every times for every trades.
- //Then I will be trading alot of error if i do so.
- //Thus I think of to make this rule to an indicator to conveninet use.
- //Pro: Other than Using BB, Support and Resistant, Fibbonaci and so on as Target Price, this may be a good reference
- //Con: Stock Price which is extremely high may not work well ,because the categories of price is only till price higher than 1.
- //It may need some adjustment for higher stock price as TP
- //Author: sxw6329 ; Date:27/02/21
- //Thanks to @RozaniGhani-RG helped tidy up the code
- indicator('Auto Target Price', shorttitle='Auto Target Price', overlay=true)
- offline = input(defval=true, title='SHOW TARGET PRICE LINE/LABEL')
- AA = input(defval=close, title='Buy Price')
- Ab = input(defval=false, title='Or')
- Ac = input(defval=0.1, title='Other Price')
- A = Ab ? Ac : AA
- //TP1
- c1 = A < 0.2
- tp1 = A + 0.005
- tp1e = A + 0.010
- tp2 = A + 0.015
- tp2e = A + 0.020
- tp3 = A + 0.025
- tp3e = A + 0.040
- //TP2
- c2 = A >= 0.2 and A <= 1
- btp1 = A + 0.015
- btp1e = A + 0.025
- btp2 = A + 0.030
- btp2e = A + 0.050
- btp3 = A + 0.060
- btp3e = A + 0.100
- //TP3
- c3 = A > 1
- ctp1 = A + 0.03
- ctp1e = A + 0.06
- ctp2 = A + 0.07
- ctp2e = A + 0.12
- ctp3 = A + 0.13
- ctp3e = A + 0.24
- colorlabel = c1 ? color.new(color.black, 15) : c2 ? color.new(color.black, 15) : c3 ? color.new(color.black, 15) : na
- fun(_cond, _val1, _val2, _val3, _val4, _val5, _val6) =>
- fun1 = offline ? _cond ? _val1 : na : na
- fun2 = offline ? _cond ? _val2 : na : na
- fun3 = offline ? _cond ? _val3 : na : na
- fun4 = offline ? _cond ? _val4 : na : na
- fun5 = offline ? _cond ? _val5 : na : na
- fun6 = offline ? _cond ? _val6 : na : na
- [fun1, fun2, fun3, fun4, fun5, fun6]
- [cctp1, cctp2, cctp3, cctp4, cctp5, cctp6] = fun(c1, tp1, tp1e, tp2, tp2e, tp3, tp3e)
- [cctp7, cctp8, cctp9, cctp10, cctp11, cctp12] = fun(c2, btp1, btp1e, btp2, btp2e, btp3, btp3e)
- [cctp13, cctp14, cctp15, cctp16, cctp17, cctp18] = fun(c3, ctp1, ctp1e, ctp2, ctp2e, ctp3, ctp3e)
- fun_line(_y) =>
- var line _id = na
- line.delete(_id)
- _id := line.new(bar_index, _y, bar_index - 1, _y, color=color.green, extend=extend.right, style=line.style_dotted)
- _id
- fun_line2(_y) =>
- var line _id = na
- line.delete(_id)
- _id := line.new(bar_index, _y, bar_index - 1, _y, color=color.blue, extend=extend.right, style=line.style_dotted)
- _id
- fun_line3(_y) =>
- var line _id = na
- line.delete(_id)
- _id := line.new(bar_index, _y, bar_index - 1, _y, color=color.red, extend=extend.right, style=line.style_dotted)
- _id
- s1 = fun_line(cctp1)
- s2 = fun_line(cctp2)
- s3 = fun_line2(cctp3)
- s4 = fun_line2(cctp4)
- s5 = fun_line3(cctp5)
- s6 = fun_line3(cctp6)
- s7 = fun_line(cctp7)
- s8 = fun_line(cctp8)
- s9 = fun_line2(cctp9)
- s10 = fun_line2(cctp10)
- s11 = fun_line3(cctp11)
- s12 = fun_line3(cctp12)
- s13 = fun_line(cctp13)
- s14 = fun_line(cctp14)
- s15 = fun_line2(cctp15)
- s16 = fun_line2(cctp16)
- s17 = fun_line3(cctp17)
- s18 = fun_line3(cctp18)
- fun_text(_x1, _x2) =>
- 'TP' + str.tostring(_x1) + ': ' + str.tostring(_x2, '#0.000')
- text1 = fun_text(1, cctp1)
- text2 = fun_text(1, cctp2)
- text3 = fun_text(2, cctp3)
- text4 = fun_text(2, cctp4)
- text5 = fun_text(3, cctp5)
- text6 = fun_text(3, cctp6)
- text7 = fun_text(1, cctp7)
- text8 = fun_text(1, cctp8)
- text9 = fun_text(2, cctp9)
- text10 = fun_text(2, cctp10)
- text11 = fun_text(3, cctp11)
- text12 = fun_text(3, cctp12)
- text13 = fun_text(1, cctp13)
- text14 = fun_text(1, cctp14)
- text15 = fun_text(2, cctp15)
- text16 = fun_text(2, cctp16)
- text17 = fun_text(3, cctp17)
- text18 = fun_text(3, cctp18)
- fun_cond(_text1, _text2, _text3) =>
- c1 ? _text1 : c2 ? _text2 : c3 ? _text3 : na
- ccc1 = fun_cond(text1, text7, text13)
- ccc2 = fun_cond(text2, text8, text14)
- ccc3 = fun_cond(text3, text9, text15)
- ccc4 = fun_cond(text4, text10, text16)
- ccc5 = fun_cond(text5, text11, text17)
- ccc6 = fun_cond(text6, text12, text18)
- ttt1 = fun_cond(cctp1, cctp7, cctp13)
- ttt2 = fun_cond(cctp2, cctp8, cctp14)
- ttt3 = fun_cond(cctp3, cctp9, cctp15)
- ttt4 = fun_cond(cctp4, cctp10, cctp16)
- ttt5 = fun_cond(cctp5, cctp11, cctp17)
- ttt6 = fun_cond(cctp6, cctp12, cctp18)
- fun_label(_y, _text, _color) =>
- var label id = na
- label.delete(id)
- 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)
- id
- sss1 = fun_label(ttt1, ccc1, color.green)
- sss2 = fun_label(ttt2, ccc2, color.green)
- sss3 = fun_label(ttt3, ccc3, color.blue)
- sss4 = fun_label(ttt4, ccc4, color.blue)
- sss5 = fun_label(ttt5, ccc5, color.red)
- sss6 = fun_label(ttt6, ccc6, color.red)
- fun_tp() =>
- n = '\n'
- d = ' - '
- texta = 'PRICE < 0.2 '
- textb = 'PRICE 0.2 - 1.0 '
- textc = 'PRICE > 1.0 '
- string title = na
- var float L1 = na
- var float H1 = na
- var float L2 = na
- var float H2 = na
- var float L3 = na
- var float H3 = na
- if c1
- L1 := tp1
- H1 := tp1e
- L2 := tp2
- H2 := tp2e
- L3 := tp3
- H3 := tp3e
- H3
- if c2
- L1 := btp1
- H1 := btp1e
- L2 := btp2
- H2 := btp2e
- L3 := btp3
- H3 := btp3e
- H3
- if c3
- L1 := ctp1
- H1 := ctp1e
- L2 := ctp2
- H2 := ctp2e
- L3 := ctp3
- H3 := ctp3e
- H3
- _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')
- var label id = na
- label.delete(id)
- 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)
- id
- sss = offline ? na : fun_tp()
- //End//
Advertisement
Add Comment
Please, Sign In to add comment