'convert formula to pinescript for tradingview
(c/c1>=1.04 and v>v1 and v>=100000) is the formula that I am trying to convert to pinescript but couldn't where
- latest close(price) is 4% more than the previous day price(rate of change ROC)
- latest volume is greater than previous day volume (relative volume)
- volume is greater than 100000
I cant put these together to get a bar on chart where if all conditions are met a bar appears. Attached below the separate formulas but I need a way to get it in pinescript where all conditions fulfill together.
//RVOL
RVOLlen = input(2, minval=1, title="RVOL Length")
av = sma(volume, RVOLlen)
RVOL = volume / av
plot(RVOL, title="RVol", color=color.yellow, linewidth=1, transp=100)
//ROC
ROClen = input(1, minval=1, title="ROC Length")
src = input(close, title="ROC Source")
roca = roc(src, ROClen)
plot(roca, title="RoC", color=color.yellow, linewidth=2, transp=0)
//Bands
hline(4, title="Level 0", color=color.white, linestyle=hline.style_solid, linewidth=1, editable=true)
hline(10, title="Level 1", color=color.white, linestyle=hline.style_dotted, linewidth=1, editable=true)
hline(-4, title="Level 2", color=color.white, linestyle=hline.style_solid, linewidth=1, editable=true)
Solution 1:[1]
You can use the security() function to request data from other timeframes.
//@version=5
indicator("My script")
[close_prev_day, vol_prev_day] = request.security(syminfo.tickerid, "1D", [close[1], volume[1]], lookahead=barmerge.lookahead_on)
x = ((close / close_prev_day) > 1.04) and (volume > vol_prev_day) and (volume > 100000)
plotshape(x)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | vitruvius |
