I want to create a skew / skewness indicator that will show the skew of a certain length of stock prices both on a lower timeframe, (ex 1 minute) and also an upper timeframe (ex 30 minute). However I would like the timeframes to be customizable (1m,5m,15m,30m,60m,1d,1w,1m) as well as the length/period of lookback. I have written the following code, but I don't know if it is accurate?? There are probably mistakes in it! In addition, a good option to have in this indicator would be to set the price SOURCE data to use either MOMENTUM (price change/difference) or ROC (% price change), instead of the prices. this is too complex for me right now. any help is appreciated and thank you.
//@version=5
indicator(title="skew", shorttitle="skew", overlay=true, timeframe="", timeframe_gaps=true)
src = input(close, title="Source")
downcycle = input.int(300, title="downcycle period")
upcycle = input.int(10, title="upcycle period")
skew1m = request.security(ticker,"1",(src, downcycle))
skew5m = request.security(ticker,"5",(src, downcycle))
skew15m = request.security(ticker,"15",(src, downcycle))
skew30m = request.security(ticker,"30",(src, upcycle))
skew1h = request.security(ticker,"60",(src,upcycle))
skew1D = request.security(ticker,"D",(src,upcycle))
skew1W = request.security(ticker,"W",(src, upcycle))
// skew lower time frame
skewness(skew1m, downcycle) =>
avg = ta.sma(src, downcycle)
stdv = ta.stdev(src, downcycle)
sum = math.pow(src - avg, 3)
for i = 1 to downcycle - 1
sum := sum + math.pow(src[i] - avg, 3)
((sum / downcycle) / math.pow(stdv, 3))
skew = skewness(src, downcycle)
plot(skew, color=color.orange, linewidth=1)
// skew higher time frame
skewness2(skew20m, upcycle) =>
avg2 = ta.sma(src, upcycle)
stdv2 = ta.stdev(src, upcycle)
sum2 = math.pow(src - avg, 3)
for i2 = 1 to downcycle - 1
sum2 := sum2 + math.pow(src[i2] - avg2, 3)
((sum2 / upcycle) / math.pow(stdv2, 3))
skew2 = skewness2(src, upcycle)
plot(skew2, color=color.blue, linewidth=1)