Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- study("Usage of a Function within security(expression=) ", "security()", true)
- // 1D (one minute sampling interval) charts provides rapid repainting visibility
- source = input( hl2, "Source", input.source )
- RESOLUTION = input( "5", "Resolution", input.resolution)
- repaint = input("Prevent", "Indicator Repainting", input.string , options=["Prevent","Permit"])
- period = input( 1, "SMA Period", input.integer , minval=1)
- ExpressionFunction(Source, Period, Index) => // Function provided to security(expression=)
- //====== Algorithms/Filtration Below
- SMA_low = sma( low[Index], Period)
- SMA_high = sma( high[Index], Period)
- SMA_open = sma( open[Index], Period)
- SMA_close = sma( close[Index], Period)
- SMA_source = sma(Source[Index], Period)
- [SMA_low, SMA_high, SMA_open, SMA_close, SMA_source] // Return tuple from security()
- var TICKER_ID = tickerid(syminfo.prefix, syminfo.ticker, syminfo.session)
- var PERMIT_REPAINTING = "Permit" == repaint
- [L0, H0, O0, C0, S0] = security(TICKER_ID, RESOLUTION, ExpressionFunction(source, period, 1), lookahead=barmerge.lookahead_on)
- [L1, H1, O1, C1, S1] = security(TICKER_ID, RESOLUTION, ExpressionFunction(source, period, 0))
- L = L0, H = H0, O = O0, C = C0, S = S0
- if PERMIT_REPAINTING or bar_index == 0
- L := L1
- H := H1
- O := O1
- C := C1
- S := S1
- plot(L, color=#00FF00ff, linewidth=2)
- plot(H, color=#FF0000ff, linewidth=2)
- plot(S, color=#C0C000ff, linewidth=2)
- plot(O, color=#FF00FF99, linewidth=5)
- plot(C, color=#FFFFFF99, linewidth=5)
- if(barstate.islast)
- labelLow = label.new(bar_index, L, "Low", color=#00FF0099, textcolor=#FFFFFFff, style=label.style_label_up )
- labelHigh = label.new(bar_index, H, "High", color=#FF000099, textcolor=#FFFFFFff, style=label.style_label_down)
- labelOpen = label.new(bar_index, O, "Open", color=#FF00FF99, textcolor=#FFFFFFff, style=label.style_label_left)
- labelClose = label.new(bar_index, C, "Close", color=#FFFFFF99, textcolor=#000000ff, style=label.style_label_left)
- labelSource = label.new(bar_index, S, "Source", color=#C0C00099, textcolor=#000000ff, style=label.style_label_left)
- label.delete(labelLow [1])
- label.delete(labelHigh [1])
- label.delete(labelOpen [1])
- label.delete(labelClose [1])
- label.delete(labelSource[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement