dusun1

CC INDICATOR Add

Dec 10th, 2022
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.70 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. // © Frien_dd
  3.  
  4.  
  5. //@version=4
  6. study("MTF Key Levels - Support and Resistance", shorttitle="MTF Levels - S/R", overlay=true)
  7.  
  8. // Daily Lines
  9. showdOpen = input(true, title=". O", group="Daily Levels", inline = "1")
  10. showdHigh = input(true, title=". H", group="Daily Levels", inline = "1")
  11. showdLow = input(true, title=". L", group="Daily Levels", inline = "1")
  12.  
  13. showpdOpen = input(true, title=". pO", group="Daily Levels", inline = "1")
  14. showpdHigh = input(true, title=". pH", group="Daily Levels", inline = "1")
  15. showpdLow = input(true, title=". pL", group="Daily Levels", inline = "1")
  16. showpdEQ = input(true, title=". pEQ", group="Daily Levels", inline = "1", tooltip="p = previous, O = Open, H = High, L = Low, EQ = Equilibrium (50%)")
  17.  
  18.  
  19. // Weekly Lines
  20. showwOpen = input(true, title=". O", group="Weekly Levels", inline = "1")
  21. showwHigh = input(true, title=". H", group="Weekly Levels", inline = "1")
  22. showwLow = input(true, title=". L", group="Weekly Levels", inline = "1")
  23.  
  24. showpwOpen = input(true, title=". pO", group="Weekly Levels", inline = "1")
  25. showpwHigh = input(true, title=". pH", group="Weekly Levels", inline = "1")
  26. showpwLow = input(true, title=". pL", group="Weekly Levels", inline = "1")
  27. showpwEQ = input(true, title=". pEQ", group="Weekly Levels", inline = "1", tooltip="p = previous, O = Open, H = High, L = Low, EQ = Equilibrium (50%)")
  28.  
  29.  
  30. // Monthly Lines
  31. showmOpen = input(true, title="- O", group="Monthly Levels", inline = "1")
  32. showmHigh = input(true, title="- H", group="Monthly Levels", inline = "1")
  33. showmLow = input(true, title="- L", group="Monthly Levels", inline = "1")
  34.  
  35. showpmOpen = input(true, title=". pO", group="Monthly Levels", inline = "1")
  36. showpmHigh = input(true, title=". pH", group="Monthly Levels", inline = "1")
  37. showpmLow = input(true, title=". pL", group="Monthly Levels", inline = "1", tooltip="p = previous, O = Open, H = High, L = Low")
  38.  
  39.  
  40. // Yealy Lines
  41. showyOpen = input(true, title=". O", group="Yearly Levels", inline = "1")
  42. showyHigh = input(true, title=". H", group="Yearly Levels", inline = "1")
  43. showyLow = input(true, title=". L", group="Yearly Levels", inline = "1", tooltip="O = Open, H = High, L = Low")
  44.  
  45.  
  46. // VWAPS
  47. show_DVWAPs = input(true, title = "Daily", group = "Standard VWAPS - Daily, Weekly, Monthly", type = input.bool, inline = "VWAP1")
  48. show_WVWAPs = input(true, title = "Weekly", group = "Standard VWAPS - Daily, Weekly, Monthly", type = input.bool, inline = "VWAP1")
  49. show_MVWAPs = input(true, title = "Monthly", group = "Standard VWAPS - Daily, Weekly, Monthly", type = input.bool, inline = "VWAP1")
  50. show_YVWAPs = input(true, title = "Yearly", group = "Standard VWAPS - Daily, Weekly, Monthly", type = input.bool, inline = "VWAP1", tooltip="M-VWAP and Y-VWAP only shows on higher time frames")
  51.  
  52.  
  53. var DSpaces = " "
  54. var DPSpaces = " "
  55. var DNoSpaces = " "
  56. var DPNoSpaces = " "
  57.  
  58.  
  59. var WSpaces = " "
  60. var WPSpaces = " "
  61. var WNoSpaces = " "
  62. var WPNoSpaces = " "
  63.  
  64.  
  65. var MSpaces = " "
  66. var MPSpaces = " "
  67. var MNoSpaces = " "
  68. var MPNoSpaces = " "
  69.  
  70.  
  71. var YSpaces = " "
  72. var YPSpaces = " "
  73. var YNoSpaces = " "
  74. var YPNoSpaces = " "
  75.  
  76. x1= valuewhen(barstate.islast, bar_index, 0)
  77.  
  78. D_extend_length = input(25, title="Extend Daily short line", group="Line Options", inline = "1")
  79. D_x2 = x1 + D_extend_length
  80.  
  81. W_extend_length = input(35, title="Extend Weekly short line", group="Line Options", inline = "1")
  82. W_x2 = x1 + W_extend_length
  83.  
  84. M_extend_length = input(45, title="Extend Monthly short line", group="Line Options", inline = "1")
  85. M_x2 = x1 + M_extend_length
  86.  
  87. Y_extend_length = input(55, title="Extend Yearly short line", group="Line Options", inline = "1")
  88. Y_x2 = x1 + Y_extend_length
  89.  
  90.  
  91. //Round of Line Value
  92. f_round_up_to_tick(x, mintick)=>
  93. mult = 1 / mintick
  94. value = ceil(x*mult)/mult
  95.  
  96. // Line Options
  97. extend = extend.none
  98. exnone = input(true, title="Short Line", group="Line Options", inline = "2")
  99. exboth = input(false, title="Line Across Screen", group="Line Options", inline = "3")
  100. exright = input(false, title="Line To Right", group="Line Options", inline = "3")
  101. showPrice = input(false, title="Show Level Prices", group="Line Options", inline = "4")
  102. showVPrice = input(false, title="Show VWAP Prices", group="Line Options", inline = "4")
  103.  
  104. extend := exnone ? extend.none : exboth ? extend.both : exright ? extend.right : extend
  105.  
  106. D_x2loc = D_x2
  107. D_x2loc := exnone ? D_x2 : exboth ? bar_index : exright ? bar_index : D_x2loc
  108.  
  109. W_x2loc = W_x2
  110. W_x2loc := exnone ? W_x2 : exboth ? bar_index : exright ? bar_index : W_x2loc
  111.  
  112. M_x2loc = M_x2
  113. M_x2loc := exnone ? M_x2 : exboth ? bar_index : exright ? bar_index : M_x2loc
  114.  
  115.  
  116. Y_x2loc = Y_x2
  117. Y_x2loc := exnone ? Y_x2 : exboth ? bar_index : exright ? bar_index : Y_x2loc
  118.  
  119.  
  120. DailySpaces = DNoSpaces
  121. DailySpaces := exnone ? DNoSpaces : exboth ? DSpaces : exright ? DSpaces : DailySpaces
  122. DailyPSpaces = DPNoSpaces
  123. DailyPSpaces := exnone ? DPNoSpaces : exboth ? DPSpaces : exright ? DPSpaces : DailyPSpaces
  124.  
  125. WeeklySpaces = WNoSpaces
  126. WeeklySpaces := exnone ? WNoSpaces : exboth ? WSpaces : exright ? WSpaces : WeeklySpaces
  127. WeeklyPSpaces = WPNoSpaces
  128. WeeklyPSpaces := exnone ? WPNoSpaces : exboth ? WPSpaces : exright ? WPSpaces : WeeklyPSpaces
  129.  
  130. MonthlySpaces = MNoSpaces
  131. MonthlySpaces := exnone ? MNoSpaces : exboth ? MSpaces : exright ? MSpaces : MonthlySpaces
  132. MonthlyPSpaces = MPNoSpaces
  133. MonthlyPSpaces := exnone ? MPNoSpaces : exboth ? MPSpaces : exright ? MPSpaces : MonthlyPSpaces
  134.  
  135. YearlySpaces = YNoSpaces
  136. YearlySpaces := exnone ? YNoSpaces : exboth ? YSpaces : exright ? YSpaces : YearlySpaces
  137. YearlyPSpaces = YPNoSpaces
  138. YearlyPSpaces := exnone ? YPNoSpaces : exboth ? YPSpaces : exright ? YPSpaces : YearlyPSpaces
  139.  
  140. //Line Colors
  141. DailyInputColor = input(color.blue, title="Daily", group = "User Selectable Line Colors", inline = "Input 0")
  142. WeeklyInputColor = input(color.yellow, title="Weekly", group = "User Selectable Line Colors", inline = "Input 0")
  143. MonthlyInputColor = input(color.purple, title="Monthly", group = "User Selectable Line Colors", inline = "Input 1")
  144. YearlyInputColor = input(color.red, title="Yearly", group = "User Selectable Line Colors", inline = "Input 1")
  145.  
  146. show_DVWAPs_color = show_DVWAPs ? DailyInputColor : na
  147. show_WVWAPs_color = show_WVWAPs ? WeeklyInputColor : na
  148. show_MVWAPs_color = show_MVWAPs ? MonthlyInputColor : na
  149. show_YVWAPs_color = show_YVWAPs ? YearlyInputColor : na
  150.  
  151.  
  152. //////////////////////////////////////
  153. /////Previous Day Values//////////////
  154. //////////////////////////////////////
  155.  
  156.  
  157. // Previous Day Open
  158. // showpdOpen = input(true, title="- pdOpen", group="pd Values", inline = "Daily")
  159. pdOpen = security(syminfo.tickerid, "D", open[1], lookahead=true)
  160. var line pdOpenLine = na
  161. var label pdOpenLabel = na
  162. if showpdOpen
  163. pdOpenLine := line.new(x1=x1, y1=pdOpen, x2=D_x2, y2=pdOpen, xloc=xloc.bar_index, width=1, color=DailyInputColor, style=line.style_dashed, extend=extend)
  164. pdOpenLabel := label.new(D_x2loc, pdOpen, text = DailySpaces+"pdOpen", color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  165. line.delete(pdOpenLine[1])
  166. label.delete(pdOpenLabel[1])
  167.  
  168.  
  169.  
  170. var label pdOpenLabelPrice = na
  171. if showpdOpen and showPrice
  172. pdOpenLabelPrice := label.new(D_x2loc, pdOpen, text = DailyPSpaces+tostring(f_round_up_to_tick(pdOpen, syminfo.mintick)), color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  173. label.delete(pdOpenLabelPrice[1])
  174.  
  175. i_text1 = ("₿ - Scripts by Frien_dd - ₿")
  176.  
  177.  
  178. // Previous Day High
  179. // showpdHigh = input(true, title="- pdHigh", group="pd Values", inline = "Daily")
  180. pdHigh = security(syminfo.tickerid, "D", high[1], lookahead=true)
  181. var line pdHighLine = na
  182. var label pdHighLabel = na
  183. if showpdHigh
  184. pdHighLine := line.new(x1=x1, y1=pdHigh, x2=D_x2, y2=pdHigh, xloc=xloc.bar_index, width=1, color=DailyInputColor, style=line.style_dashed, extend=extend)
  185. pdHighLabel := label.new(D_x2loc, pdHigh, text = DailySpaces+"pdHigh", color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  186. line.delete(pdHighLine[1])
  187. label.delete(pdHighLabel[1])
  188.  
  189. var label pdHighLabelPrice = na
  190. if showpdHigh and showPrice
  191. pdHighLabelPrice := label.new(D_x2loc, pdHigh, text = DailyPSpaces+tostring(f_round_up_to_tick(pdHigh, syminfo.mintick)), color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  192. label.delete(pdHighLabelPrice[1])
  193.  
  194.  
  195. // Previous Day Low
  196. // showpdLow = input(true, title="- pdLow", group="pd Values", inline = "Daily")
  197. pdLow = security(syminfo.tickerid, "D", low[1], lookahead=true)
  198. var line pdLowLine = na
  199. var label pdLowLabel = na
  200. if showpdLow
  201. pdLowLine := line.new(x1=x1, y1=pdLow, x2=D_x2, y2=pdLow, xloc=xloc.bar_index, width=1, color=DailyInputColor, style=line.style_dashed, extend=extend)
  202. pdLowLabel := label.new(D_x2loc, pdLow, text = DailySpaces+"pdLow", color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  203. line.delete(pdLowLine[1])
  204. label.delete(pdLowLabel[1])
  205.  
  206. var label pdLowLabelPrice = na
  207. if showpdLow and showPrice
  208. pdLowLabelPrice := label.new(D_x2loc, pdLow, text = DailyPSpaces+tostring(f_round_up_to_tick(pdLow, syminfo.mintick)), color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  209. label.delete(pdLowLabelPrice[1])
  210.  
  211.  
  212. // Previous Day EQ
  213. // showpdEQ = input(true, title="- pdEQ", group="pd Values", inline = "Daily")
  214. pdEQ = (pdHigh + pdLow) / 2
  215. var line pdEQLine = na
  216. var label pdEQLabel = na
  217. if showpdEQ
  218. pdEQLine := line.new(x1=x1, y1=pdEQ, x2=D_x2, y2=pdEQ, xloc=xloc.bar_index, width=1, color=DailyInputColor, style=line.style_dashed, extend=extend)
  219. pdEQLabel := label.new(D_x2loc, pdEQ, text = DailySpaces+"pdEQ", color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  220. line.delete(pdEQLine[1])
  221. label.delete(pdEQLabel[1])
  222.  
  223. var label pdEQLabelPrice = na
  224. if showpdEQ and showPrice
  225. pdEQLabelPrice := label.new(D_x2loc, pdEQ, text = DailyPSpaces+tostring(f_round_up_to_tick(pdEQ, syminfo.mintick)), color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  226. label.delete(pdEQLabelPrice[1])
  227.  
  228.  
  229. //////////////////////////////////////
  230. /////Previous Week Values//////////////
  231. //////////////////////////////////////
  232.  
  233. // Previous Week Open
  234. // showpwOpen = input(true, title="- pwOpen", group="pw Values", inline = "Weekly")
  235. pwOpen = security(syminfo.tickerid, "W", open[1], lookahead = barmerge.lookahead_on)
  236. var line pwOpenLine = na
  237. var label pwOpenLabel = na
  238. if showpwOpen
  239. pwOpenLine := line.new(x1=x1, y1=pwOpen, x2=W_x2, y2=pwOpen, xloc=xloc.bar_index, width=1, color=WeeklyInputColor, style=line.style_dashed, extend=extend)
  240. pwOpenLabel := label.new(W_x2loc, pwOpen, text = WeeklySpaces+"pwOpen", color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  241. line.delete(pwOpenLine[1])
  242. label.delete(pwOpenLabel[1])
  243.  
  244. var label pwOpenLabelPrice = na
  245. if showpwOpen and showPrice
  246. pwOpenLabelPrice := label.new(W_x2loc, pwOpen, text = WeeklyPSpaces+tostring(f_round_up_to_tick(pwOpen, syminfo.mintick)), color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  247. label.delete(pwOpenLabelPrice[1])
  248.  
  249.  
  250. // Previous Week High
  251. // showpwHigh = input(true, title="- pwHigh", group="pw Values", inline = "Weekly")
  252. pwHigh = security(syminfo.tickerid, "W", high[1], lookahead=true)
  253. var line pwHighLine = na
  254. var label pwHighLabel = na
  255. if showpwHigh
  256. pwHighLine := line.new(x1=x1, y1=pwHigh, x2=W_x2, y2=pwHigh, xloc=xloc.bar_index, width=1, color=WeeklyInputColor, style=line.style_dashed, extend=extend)
  257. pwHighLabel := label.new(W_x2loc, pwHigh, text = WeeklySpaces+"pwHigh", color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  258. line.delete(pwHighLine[1])
  259. label.delete(pwHighLabel[1])
  260.  
  261. var label pwHighLabelPrice = na
  262. if showpwHigh and showPrice
  263. pwHighLabelPrice := label.new(W_x2loc, pwHigh, text = WeeklyPSpaces+tostring(f_round_up_to_tick(pwHigh, syminfo.mintick)), color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  264. label.delete(pwHighLabelPrice[1])
  265.  
  266.  
  267. // Previous Week Low
  268. // showpwLow = input(true, title="- pwLow", group="pw Values", inline = "Weekly")
  269. pwLow = security(syminfo.tickerid, "W", low[1], lookahead=true)
  270. var line pwLowLine = na
  271. var label pwLowLabel = na
  272. if showpwLow
  273. pwLowLine := line.new(x1=x1, y1=pwLow, x2=W_x2, y2=pwLow, xloc=xloc.bar_index, width=1, color=WeeklyInputColor, style=line.style_dashed, extend=extend)
  274. pwLowLabel := label.new(W_x2loc, pwLow, text = WeeklySpaces+"pwLow", color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  275. line.delete(pwLowLine[1])
  276. label.delete(pwLowLabel[1])
  277.  
  278. var label pwLowLabelPrice = na
  279. if showpwLow and showPrice
  280. pwLowLabelPrice := label.new(W_x2loc, pwLow, text = WeeklyPSpaces+tostring(f_round_up_to_tick(pwLow, syminfo.mintick)), color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  281. label.delete(pwLowLabelPrice[1])
  282.  
  283.  
  284. // Previous Week EQ
  285. // showpwEQ = input(true, title="- pwEQ", group="pw Values", inline = "Weekly")
  286. pwEQ = (pwHigh + pwLow) / 2
  287. var line pwEQLine = na
  288. var label pwEQLabel = na
  289. if showpwEQ
  290. pwEQLine := line.new(x1=x1, y1=pwEQ, x2=W_x2, y2=pwEQ, xloc=xloc.bar_index, width=1, color=WeeklyInputColor, style=line.style_dashed, extend=extend)
  291. pwEQLabel := label.new(W_x2loc, pwEQ, text = WeeklySpaces+"pwEQ", color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  292. line.delete(pwEQLine[1])
  293. label.delete(pwEQLabel[1])
  294.  
  295. var label pwEQLabelPrice = na
  296. if showpwEQ and showPrice
  297. pwEQLabelPrice := label.new(W_x2loc, pwEQ, text = WeeklyPSpaces+tostring(f_round_up_to_tick(pwEQ, syminfo.mintick)), color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  298. label.delete(pwEQLabelPrice[1])
  299.  
  300.  
  301. ///////////////////////////////////////
  302. /////Weekly Open-High-Low/////////////
  303. //////////////////////////////////////
  304.  
  305. // Current Monthly Open
  306. // showwOpen = input(true, title=". wOpen", group="Weekly Levels", inline = "1")
  307. wOpen = security(syminfo.tickerid, "W", open, lookahead = barmerge.lookahead_on)
  308. var line wOpenLine = na
  309. var label wOpenLabel = na
  310. if showwOpen
  311. wOpenLine := line.new(x1=x1, y1=wOpen, x2=W_x2, y2=wOpen, xloc=xloc.bar_index, width=1, color=WeeklyInputColor, style=line.style_dashed, extend=extend)
  312. wOpenLabel := label.new(W_x2loc, wOpen, text = WeeklySpaces+"wOpen", color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  313. line.delete(wOpenLine[1])
  314. label.delete(wOpenLabel[1])
  315.  
  316. var label wOpenLabelPrice = na
  317. if showwOpen and showPrice
  318. wOpenLabelPrice := label.new(W_x2loc, wOpen, text = WeeklyPSpaces+tostring(f_round_up_to_tick(wOpen, syminfo.mintick)), color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  319. label.delete(wOpenLabelPrice[1])
  320.  
  321.  
  322. // Weekly Low High Levels
  323. var LastWeek = 0
  324. var WeeklyHigh = 0.0
  325. var WeeklyLow = 0.0
  326.  
  327. ThisWeek = time('W')
  328. CheckWeek = ThisWeek!=LastWeek
  329. LastWeek := ThisWeek
  330. WeeklyHigh := CheckWeek or high>WeeklyHigh ? high[0] : WeeklyHigh
  331. WeeklyLow := CheckWeek or low<WeeklyLow ? low[0] : WeeklyLow
  332.  
  333.  
  334. var line wLowLine = na
  335. var label wLowLabel = na
  336. // showwLow = input(true, title=". wLow", group="Weekly Levels", inline = "1")
  337. if showwLow
  338. wLowLine := line.new(x1=x1, y1=WeeklyLow, x2=W_x2, y2=WeeklyLow, xloc=xloc.bar_index, width=1, color=WeeklyInputColor, style=line.style_solid, extend=extend)
  339. wLowLabel := label.new(W_x2loc, WeeklyLow, text = MonthlySpaces+"wLow", color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  340. line.delete(wLowLine[1])
  341. label.delete(wLowLabel[1])
  342.  
  343. var label wLowLabelPrice = na
  344. if showwLow and showPrice
  345. wLowLabelPrice := label.new(W_x2loc, WeeklyLow, text = WeeklyPSpaces+tostring(f_round_up_to_tick(WeeklyLow, syminfo.mintick)), color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  346. label.delete(wLowLabelPrice[1])
  347.  
  348.  
  349. var line wHighLine = na
  350. var label wHighLabel = na
  351. // showwHigh = input(true, title=". wHigh", group="Weekly Levels", inline = "1")
  352. if showwHigh
  353. wHighLine := line.new(x1=x1, y1=WeeklyHigh, x2=W_x2, y2=WeeklyHigh, xloc=xloc.bar_index, width=1, color=WeeklyInputColor, style=line.style_solid, extend=extend)
  354. wHighLabel := label.new(W_x2loc, WeeklyHigh, text = WeeklySpaces+"wHigh", color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  355. line.delete(wHighLine[1])
  356. label.delete(wHighLabel[1])
  357.  
  358. var label wHighLabelPrice = na
  359. if showwHigh and showPrice
  360. wHighLabelPrice := label.new(W_x2loc, WeeklyHigh, text = WeeklyPSpaces+tostring(f_round_up_to_tick(WeeklyHigh, syminfo.mintick)), color=WeeklyInputColor, textcolor=WeeklyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  361. label.delete(wHighLabelPrice[1])
  362.  
  363.  
  364. //////////////////////////////////////
  365. /////Previous Month Values////////////
  366. //////////////////////////////////////
  367.  
  368. // Previous Month Open
  369. // showpmOpen = input(true, title="- pmOpen", group="pm Values", inline = "Monthly")
  370. pmOpen = security(syminfo.tickerid, "M", open[1], lookahead = barmerge.lookahead_on)
  371. var line pmOpenLine = na
  372. var label pmOpenLabel = na
  373. if showpmOpen
  374. pmOpenLine := line.new(x1=x1, y1=pmOpen, x2=M_x2, y2=pmOpen, xloc=xloc.bar_index, width=1, color=MonthlyInputColor, style=line.style_dashed, extend=extend)
  375. pmOpenLabel := label.new(M_x2loc, pmOpen, text = MonthlySpaces+"pmOpen", color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  376. line.delete(pmOpenLine[1])
  377. label.delete(pmOpenLabel[1])
  378.  
  379. var label pmOpenLabelPrice = na
  380. if showpmOpen and showPrice
  381. pmOpenLabelPrice := label.new(M_x2loc, pmOpen, text = MonthlyPSpaces+tostring(f_round_up_to_tick(pmOpen, syminfo.mintick)), color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  382. label.delete(pmOpenLabelPrice[1])
  383.  
  384.  
  385.  
  386. // Previous Month High
  387. // showpmHigh = input(true, title="- pmHigh", group="pm Values", inline = "Monthly")
  388. pmHigh = security(syminfo.tickerid, "M", high[1], lookahead=true)
  389. var line pmHighLine = na
  390. var label pmHighLabel = na
  391. if showpmHigh
  392. pmHighLine := line.new(x1=x1, y1=pmHigh, x2=M_x2, y2=pmHigh, xloc=xloc.bar_index, width=1, color=MonthlyInputColor, style=line.style_dashed, extend=extend)
  393. pmHighLabel := label.new(M_x2loc, pmHigh, text = MonthlySpaces+"pmHigh", color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  394. line.delete(pmHighLine[1])
  395. label.delete(pmHighLabel[1])
  396.  
  397. var label pmHighLabelPrice = na
  398. if showpmHigh and showPrice
  399. pmHighLabelPrice := label.new(M_x2loc, pmHigh, text = MonthlyPSpaces+tostring(f_round_up_to_tick(pmHigh, syminfo.mintick)), color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  400. label.delete(pmHighLabelPrice[1])
  401.  
  402.  
  403. // Previous Month Low
  404. // showpmLow = input(true, title="- pmLow", group="pm Values", inline = "Monthly")
  405. pmLow = security(syminfo.tickerid, "M", low[1], lookahead=true)
  406. var line pmLowLine = na
  407. var label pmLowLabel = na
  408. if showpmLow
  409. pmLowLine := line.new(x1=x1, y1=pmLow, x2=M_x2, y2=pmLow, xloc=xloc.bar_index, width=1, color=MonthlyInputColor, style=line.style_dashed, extend=extend)
  410. pmLowLabel := label.new(M_x2loc, pmLow, text = MonthlySpaces+"pmLow", color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  411. line.delete(pmLowLine[1])
  412. label.delete(pmLowLabel[1])
  413.  
  414. var label pmLowLabelPrice = na
  415. if showpmLow and showPrice
  416. pmLowLabelPrice := label.new(M_x2loc, pmLow, text = MonthlyPSpaces+tostring(f_round_up_to_tick(pmLow, syminfo.mintick)), color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  417. label.delete(pmLowLabelPrice[1])
  418.  
  419.  
  420. //////////////////////////////////////
  421. /////Daily Open///////////////////////
  422. //////////////////////////////////////
  423. // showdOpen = input(true, title="- dOpen", group="Current Daily", inline = "Daily")
  424. dOpen = security(syminfo.tickerid, "D", open, lookahead=true)
  425. var line dOpenLine = na
  426. var label dOpenLabel = na
  427. if showdOpen
  428. dOpenLine := line.new(x1=x1, y1=dOpen, x2=D_x2, y2=dOpen, xloc=xloc.bar_index, width=1, color=DailyInputColor, style=line.style_dashed, extend=extend)
  429. dOpenLabel := label.new(D_x2loc, dOpen, text = DailySpaces+"dOpen", color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  430. line.delete(dOpenLine[1])
  431. label.delete(dOpenLabel[1])
  432.  
  433. var label dOpenLabelPrice = na
  434. if showdOpen and showPrice
  435. dOpenLabelPrice := label.new(D_x2loc, dOpen, text = DailyPSpaces+tostring(f_round_up_to_tick(dOpen, syminfo.mintick)), color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  436. label.delete(dOpenLabelPrice[1])
  437.  
  438. // Daily Low High Levels
  439. var LastDay = 0
  440. var DailyHigh = 0.0
  441. var DailyLow = 0.0
  442.  
  443. ThisDay = time('D')
  444. CheckDay = ThisDay!=LastDay
  445. LastDay := ThisDay
  446. DailyHigh := CheckDay or high>DailyHigh ? high[0] : DailyHigh
  447. DailyLow := CheckDay or low<DailyLow ? low[0] : DailyLow
  448.  
  449. // Daily Low and High
  450. var line dLowLine = na
  451. var label dLowLabel = na
  452. // showdLow = input(true, title=". dLow", group="Daily Levels", inline = "1")
  453. if showdLow
  454. dLowLine := line.new(x1=x1, y1=DailyLow, x2=D_x2, y2=DailyLow, xloc=xloc.bar_index, width=1, color=DailyInputColor, style=line.style_solid, extend=extend)
  455. dLowLabel := label.new(D_x2loc, DailyLow, text = DailySpaces+"dLow", color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  456. line.delete(dLowLine[1])
  457. label.delete(dLowLabel[1])
  458.  
  459. var label dLowLabelPrice = na
  460. if showdLow and showPrice
  461. dLowLabelPrice := label.new(D_x2loc, DailyLow, text = DailyPSpaces+tostring(f_round_up_to_tick(DailyLow, syminfo.mintick)), color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  462. label.delete(dLowLabelPrice[1])
  463.  
  464.  
  465. var line dHighLine = na
  466. var label dHighLabel = na
  467. // showdHigh = input(true, title=". dHigh", group="Daily Levels", inline = "1")
  468. if showdHigh
  469. dHighLine := line.new(x1=x1, y1=DailyHigh, x2=D_x2, y2=DailyHigh, xloc=xloc.bar_index, width=1, color=DailyInputColor, style=line.style_solid, extend=extend)
  470. dHighLabel := label.new(D_x2loc, DailyHigh, text = DailySpaces+"dHigh", color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  471. line.delete(dHighLine[1])
  472. label.delete(dHighLabel[1])
  473.  
  474. var label dHighLabelPrice = na
  475. if showdHigh and showPrice
  476. dHighLabelPrice := label.new(D_x2loc, DailyHigh, text = DailyPSpaces+tostring(f_round_up_to_tick(DailyHigh, syminfo.mintick)), color=DailyInputColor, textcolor=DailyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  477. label.delete(dHighLabelPrice[1])
  478.  
  479. ///////////////////////////////////////
  480. /////Monthly Open-High-Low/////////////
  481. //////////////////////////////////////
  482.  
  483. // Current Monthly Open
  484. // showmOpen = input(true, title="- mOpen", group="Current Monthly", inline = "Monthly")
  485. mOpen = security(syminfo.tickerid, "M", open, lookahead = barmerge.lookahead_on)
  486. var line mOpenLine = na
  487. var label mOpenLabel = na
  488. if showmOpen
  489. mOpenLine := line.new(x1=x1, y1=mOpen, x2=M_x2, y2=mOpen, xloc=xloc.bar_index, width=1, color=MonthlyInputColor, style=line.style_dashed, extend=extend)
  490. mOpenLabel := label.new(M_x2loc, mOpen, text = MonthlySpaces+"mOpen", color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  491. line.delete(mOpenLine[1])
  492. label.delete(mOpenLabel[1])
  493.  
  494. var label mOpenLabelPrice = na
  495. if showmOpen and showPrice
  496. mOpenLabelPrice := label.new(M_x2loc, mOpen, text = MonthlyPSpaces+tostring(f_round_up_to_tick(mOpen, syminfo.mintick)), color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  497. label.delete(mOpenLabelPrice[1])
  498.  
  499.  
  500.  
  501. // Current Monthly High
  502. //Current Day High Low
  503. var LastMonth = 0
  504. var MonthlyHigh = 0.0
  505. var MonthlyLow = 0.0
  506.  
  507. ThisMonth = time('M')
  508. CheckMonth = ThisMonth!=LastMonth
  509. LastMonth := ThisMonth
  510. MonthlyHigh := CheckMonth or high>MonthlyHigh ? high[0] : MonthlyHigh
  511. MonthlyLow := CheckMonth or low<MonthlyLow ? low[0] : MonthlyLow
  512.  
  513.  
  514. var line mLowLine = na
  515. var label mLowLabel = na
  516. // showmLow = input(true, title="- mLow", group="Current Monthly", inline = "Monthly")
  517. if showmLow
  518. mLowLine := line.new(x1=x1, y1=MonthlyLow, x2=M_x2, y2=MonthlyLow, xloc=xloc.bar_index, width=1, color=MonthlyInputColor, style=line.style_solid, extend=extend)
  519. mLowLabel := label.new(M_x2loc, MonthlyLow, text = MonthlySpaces+"mLow", color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  520. line.delete(mLowLine[1])
  521. label.delete(mLowLabel[1])
  522.  
  523. var label mLowLabelPrice = na
  524. if showmLow and showPrice
  525. mLowLabelPrice := label.new(M_x2loc, MonthlyLow, text = MonthlyPSpaces+tostring(f_round_up_to_tick(MonthlyLow, syminfo.mintick)), color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  526. label.delete(mLowLabelPrice[1])
  527.  
  528.  
  529. var line mHighLine = na
  530. var label mHighLabel = na
  531. // showmHigh = input(true, title="- mHigh", group="Current Monthly", inline = "Monthly")
  532. if showmHigh
  533. mHighLine := line.new(x1=x1, y1=MonthlyHigh, x2=M_x2, y2=MonthlyHigh, xloc=xloc.bar_index, width=1, color=MonthlyInputColor, style=line.style_solid, extend=extend)
  534. mHighLabel := label.new(M_x2loc, MonthlyHigh, text = MonthlySpaces+"mHigh", color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  535. line.delete(mHighLine[1])
  536. label.delete(mHighLabel[1])
  537.  
  538. var label mHighLabelPrice = na
  539. if showmHigh and showPrice
  540. mHighLabelPrice := label.new(M_x2loc, MonthlyHigh, text = MonthlyPSpaces+tostring(f_round_up_to_tick(MonthlyHigh, syminfo.mintick)), color=MonthlyInputColor, textcolor=MonthlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  541. label.delete(mHighLabelPrice[1])
  542.  
  543. i_tableYpos = ("bottom")
  544.  
  545. ///////////////////////////////////////
  546. /////Yearly Open-High-Low/////////////
  547. //////////////////////////////////////
  548.  
  549. // Current Yearly Open
  550. // showyOpen = input(true, title="- yOpen", group="Current Yearly", inline = "Yearly")
  551. yOpen = security(syminfo.tickerid, "12M", open, lookahead = barmerge.lookahead_on)
  552. var line yOpenLine = na
  553. var label yOpenLabel = na
  554. if showyOpen
  555. yOpenLine := line.new(x1=x1, y1=yOpen, x2=Y_x2, y2=yOpen, xloc=xloc.bar_index, width=1, color=YearlyInputColor, style=line.style_dashed, extend=extend)
  556. yOpenLabel := label.new(Y_x2loc, yOpen, text = YearlySpaces+"yOpen", color=YearlyInputColor, textcolor=YearlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  557. line.delete(yOpenLine[1])
  558. label.delete(yOpenLabel[1])
  559.  
  560. var label yOpenLabelPrice = na
  561. if showyOpen and showPrice
  562. yOpenLabelPrice := label.new(Y_x2loc, yOpen, text = YearlyPSpaces+tostring(f_round_up_to_tick(yOpen, syminfo.mintick)), color=YearlyInputColor, textcolor=YearlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  563. label.delete(yOpenLabelPrice[1])
  564.  
  565.  
  566. // Current Yearly High Low
  567. var LastYear = 0
  568. var YearlyHigh = 0.0
  569. var YearlyLow = 0.0
  570.  
  571. ThisYear = time('12M')
  572. CheckYear = ThisYear!=LastYear
  573. LastYear := ThisYear
  574. YearlyHigh := CheckYear or high>YearlyHigh ? high[0] : YearlyHigh
  575. YearlyLow := CheckYear or low<YearlyLow ? low[0] : YearlyLow
  576. i_tableXpos = ("right")
  577.  
  578.  
  579. var line yLowLine = na
  580. var label yLowLabel = na
  581. if showyLow
  582. yLowLine := line.new(x1=x1, y1=YearlyLow, x2=Y_x2, y2=YearlyLow, xloc=xloc.bar_index, width=1, color=YearlyInputColor, style=line.style_solid, extend=extend)
  583. yLowLabel := label.new(Y_x2loc, YearlyLow, text = YearlySpaces+"yLow", color=YearlyInputColor, textcolor=YearlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  584. line.delete(yLowLine[1])
  585. label.delete(yLowLabel[1])
  586.  
  587. var label yLowLabelPrice = na
  588. if showyLow and showPrice
  589. yLowLabelPrice := label.new(Y_x2loc, YearlyLow, text = YearlyPSpaces+tostring(f_round_up_to_tick(YearlyLow, syminfo.mintick)), color=YearlyInputColor, textcolor=YearlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  590. label.delete(yLowLabelPrice[1])
  591.  
  592. var line yHighLine = na
  593. var label yHighLabel = na
  594. if showyHigh
  595. yHighLine := line.new(x1=x1, y1=YearlyHigh, x2=Y_x2, y2=YearlyHigh, xloc=xloc.bar_index, width=1, color=YearlyInputColor, style=line.style_solid, extend=extend)
  596. yHighLabel := label.new(Y_x2loc, YearlyHigh, text = YearlySpaces+"yHigh", color=YearlyInputColor, textcolor=YearlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  597. line.delete(yHighLine[1])
  598. label.delete(yHighLabel[1])
  599.  
  600. var label yHighLabelPrice = na
  601. if showyHigh and showPrice
  602. yHighLabelPrice := label.new(Y_x2loc, YearlyHigh, text = YearlyPSpaces+tostring(f_round_up_to_tick(YearlyHigh, syminfo.mintick)), color=YearlyInputColor, textcolor=YearlyInputColor, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  603. label.delete(yHighLabelPrice[1])
  604.  
  605. i_height = (7)
  606. i_width = (15)
  607. i_c_text = (color.new(color.white, 50))
  608.  
  609. //Daily VWAP
  610. is_today = year == year(timenow) and month == month(timenow) and dayofmonth == dayofmonth(timenow)
  611. roundedVWAP = f_round_up_to_tick(vwap, syminfo.mintick)
  612. VWAP = roundedVWAP
  613. plot(VWAP, "D-VWAP", is_today ? show_DVWAPs_color : na, offset = 0)
  614.  
  615. var label VWAPLabel = na
  616. if VWAP
  617. VWAPLabel := label.new(bar_index, VWAP, text = " D-VWAP", color=show_DVWAPs_color, textcolor=show_DVWAPs_color, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  618. label.delete(VWAPLabel[1])
  619.  
  620. var label VWAPPLabel = na
  621. if VWAP and showVPrice
  622. VWAPPLabel := label.new(bar_index, VWAP, text = " "+tostring(VWAP), color=show_DVWAPs_color, textcolor=show_DVWAPs_color, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  623. label.delete(VWAPPLabel[1])
  624.  
  625. //Weeekly VWAP
  626. src = hlc3
  627. wt = time("W")
  628.  
  629. wstart = na(wt[1]) or wt > wt[1]
  630.  
  631. wsumSrc = src * volume
  632. wsumVol = volume
  633. wsumSrc := wstart ? wsumSrc : wsumSrc + wsumSrc[1]
  634. wsumVol := wstart ? wsumVol : wsumVol + wsumVol[1]
  635.  
  636. WVWAP=(wsumSrc / wsumVol)
  637. wvw = f_round_up_to_tick(WVWAP, syminfo.mintick)
  638.  
  639. plot(timeframe.isintraday ? wvw : na, title="W-VWAP", color=show_WVWAPs_color)
  640.  
  641. var label wVWAPLabel = na
  642. if wvw
  643. wVWAPLabel := label.new(bar_index, wvw, text = " W-VWAP", color=show_WVWAPs_color, textcolor=show_WVWAPs_color, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  644. label.delete(wVWAPLabel[1])
  645.  
  646. var label wVWAPPLabel = na
  647. if wvw and showVPrice
  648. wVWAPPLabel := label.new(bar_index, wvw, text = " "+tostring(wvw), color=show_WVWAPs_color, textcolor=show_WVWAPs_color, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  649. label.delete(wVWAPPLabel[1])
  650.  
  651. i_textSize = ("normal")
  652. i_c_bg = (color.new(color.blue, 80))
  653.  
  654. //Monthly VWAP
  655. var float vwapsum = na
  656. var float volumesum = na
  657.  
  658. newSession = change(time('M'))
  659. vwapsum := newSession ? hl2*volume : hl2*volume + vwapsum[1]
  660. volumesum := newSession ? volume : volume + volumesum[1]
  661.  
  662. MVWAP = vwapsum/volumesum
  663. mvw = f_round_up_to_tick(MVWAP, syminfo.mintick)
  664.  
  665. plot(newSession ? na : mvw , title="M-VWAP", color=show_MVWAPs_color, style=plot.style_linebr)
  666.  
  667. var label mVWAPLabel = na
  668. if mvw
  669. mVWAPLabel := label.new(bar_index, mvw, text = " M-VWAP", color=show_MVWAPs_color, textcolor=show_MVWAPs_color, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  670. label.delete(mVWAPLabel[1])
  671.  
  672. var label mVWAPPLabel = na
  673. if mvw and showVPrice
  674. mVWAPPLabel := label.new(bar_index, mvw, text = " "+tostring(mvw), color=show_MVWAPs_color, textcolor=show_MVWAPs_color, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  675. label.delete(mVWAPPLabel[1])
  676.  
  677. var table watermark = table.new(i_tableYpos + "_" + i_tableXpos, 1, 1)
  678.  
  679. //Yearly VWAP
  680. var float yvwapsum = na
  681. var float yvolumesum = na
  682.  
  683. ynewSession = change(time('12M'))
  684. yvwapsum := ynewSession ? hl2*volume : hl2*volume + yvwapsum[1]
  685. yvolumesum := ynewSession ? volume : volume + yvolumesum[1]
  686.  
  687. YVWAP = yvwapsum/yvolumesum
  688. yvw = f_round_up_to_tick(YVWAP, syminfo.mintick)
  689.  
  690. table.cell(watermark, 0, 0, i_text1, i_width, i_height, i_c_text, text_size = i_textSize, bgcolor = i_c_bg)
  691.  
  692. plot(newSession ? na : yvw , title="Y-VWAP", color=show_YVWAPs_color, style=plot.style_linebr)
  693.  
  694. var label yVWAPLabel = na
  695. if yvw
  696. yVWAPLabel := label.new(bar_index, yvw, text = " Y-VWAP", color=show_YVWAPs_color, textcolor=show_YVWAPs_color, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  697. label.delete(yVWAPLabel[1])
  698.  
  699. var label yVWAPPLabel = na
  700. if yvw and showVPrice
  701. yVWAPPLabel := label.new(bar_index, yvw, text = " "+tostring(yvw), color=show_YVWAPs_color, textcolor=show_YVWAPs_color, style=label.style_none, size=size.normal, xloc=xloc.bar_index, textalign=text.align_right)
  702. label.delete(yVWAPPLabel[1])
  703.  
  704.  
  705.  
  706.  
Advertisement
Add Comment
Please, Sign In to add comment