Advertisement
PineCoders

midtown repaint

May 19th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. //@version=4
  2. study("Usage of a Function within security(expression=) ", "security()", true)
  3. // 1D (one minute sampling interval) charts provides rapid repainting visibility
  4.  
  5. source = input( hl2, "Source", input.source )
  6. RESOLUTION = input( "5", "Resolution", input.resolution)
  7. repaint = input("Prevent", "Indicator Repainting", input.string , options=["Prevent","Permit"])
  8. period = input( 1, "SMA Period", input.integer , minval=1)
  9.  
  10. ExpressionFunction(Source, Period, Index) => // Function provided to security(expression=)
  11. //====== Algorithms/Filtration Below
  12. SMA_low = sma( low[Index], Period)
  13. SMA_high = sma( high[Index], Period)
  14. SMA_open = sma( open[Index], Period)
  15. SMA_close = sma( close[Index], Period)
  16. SMA_source = sma(Source[Index], Period)
  17. [SMA_low, SMA_high, SMA_open, SMA_close, SMA_source] // Return tuple from security()
  18.  
  19. var TICKER_ID = tickerid(syminfo.prefix, syminfo.ticker, syminfo.session)
  20. var PERMIT_REPAINTING = "Permit" == repaint
  21. [L0, H0, O0, C0, S0] = security(TICKER_ID, RESOLUTION, ExpressionFunction(source, period, 1), lookahead=barmerge.lookahead_on)
  22. [L1, H1, O1, C1, S1] = security(TICKER_ID, RESOLUTION, ExpressionFunction(source, period, 0))
  23. L = L0, H = H0, O = O0, C = C0, S = S0
  24. if PERMIT_REPAINTING or bar_index == 0
  25. L := L1
  26. H := H1
  27. O := O1
  28. C := C1
  29. S := S1
  30.  
  31. plot(L, color=#00FF00ff, linewidth=2)
  32. plot(H, color=#FF0000ff, linewidth=2)
  33. plot(S, color=#C0C000ff, linewidth=2)
  34. plot(O, color=#FF00FF99, linewidth=5)
  35. plot(C, color=#FFFFFF99, linewidth=5)
  36.  
  37. if(barstate.islast)
  38. labelLow = label.new(bar_index, L, "Low", color=#00FF0099, textcolor=#FFFFFFff, style=label.style_label_up )
  39. labelHigh = label.new(bar_index, H, "High", color=#FF000099, textcolor=#FFFFFFff, style=label.style_label_down)
  40. labelOpen = label.new(bar_index, O, "Open", color=#FF00FF99, textcolor=#FFFFFFff, style=label.style_label_left)
  41. labelClose = label.new(bar_index, C, "Close", color=#FFFFFF99, textcolor=#000000ff, style=label.style_label_left)
  42. labelSource = label.new(bar_index, S, "Source", color=#C0C00099, textcolor=#000000ff, style=label.style_label_left)
  43. label.delete(labelLow [1])
  44. label.delete(labelHigh [1])
  45. label.delete(labelOpen [1])
  46. label.delete(labelClose [1])
  47. label.delete(labelSource[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement