0

I am trying to create a stock indicator that will calculate lower timeframe bars as a % of their total Higher time bar. The idea is that this is a type of volatility indicator to gauge how large the % change/ROC of any single lower stockchart timeframe (1min, 5min, 10m, 15m, 30m, 1hour) is in a ratio of the total Higher timeframe ROC to which it belongs (30min to 1 hour; 1 hour to 1day; 1 day to 1 week etc....). example take (1) 5min bar (F) and each of its (5) 1min (N) bars, then calculate and plot N/F for each 1 min bar. OR take a 1 hour bar (H) and plot a ratio of each of its (2) 30m (T) bars, calculating T/H for both bars. I do understand that there is no way to calculate these ratios for the initial lower time frames until each Higher time frame is completed (the higher time frame is constantly repainting until its formed). Therefore, I believe it to be a good idea to have this indicator ALSO plot a second readout that creates this ratio of each lower time frame divided by the PREVIOUS Higher timeframe bar (two different readouts one for current bar and one past bar). Being able to choose via input which time frames you want to compare would be most useful, to not have them all onscreen at the same time. This indicator is too complex for me so I only have a few starting ideas coded below. Please Help and thank you!!

//@version=5
indicator(title="DownCycle/UPCycle", shorttitle="Dn/Up", format=format.price, precision=4, timeframe="", timeframe_gaps=true)
//??
//downcycle =input.timeframe("30")
//upcycle =input.timeframe("1")

//??
downcycle = request.security_lower_tf(syminfo.tickerid, "5", close)
str = ""
len = array.size(downcycle)
if (len > 0)
    for i=0 to len-1
        str := str + str.tostring(array.get(downcycle, i)) + '\n'

if barstate.islast
    label.new(bar_index, high, str)


lvbx9
  • 39
  • 1
  • 8
  • The easiest way to achieve this will be to use [`request.security_lower_tf()`](https://www.tradingview.com/pine-script-reference/v5/#fun_request{dot}security_lower_tf) because it returns an array of intrabar values. Have a look at how [Polarity Divergences](https://www.tradingview.com/script/84Sr3GS4-Polarity-Divergences/) from the [TradingView](https://www.tradingview.com/u/TradingView/#published-scripts) account works, and keep an eye on its next script publication which should be out soon. It will explore a concept similar to what you are describing. gl! – PineCoders-LucF Nov 06 '22 at 19:35

0 Answers0