esvafromdc
New member
I am attempting to create an hourly upper indicator similar to the "volatility box". I used BenTen's "Average Price Movements" as a guide (I'm not a programmer).
In this case, I am looking back each hour for 60 hourly periods, taking an average of the range and the high of each period and then projecting them. I feel like my calculations are correct but it clearly isn't displaying correctly. What it should do is find the low for the current 60-minute candle and add the average and upper price movement number to project the high. Conversely, it should find the high for the current 60-minute candle, and subtract the average and the upper price movement range for that hour to project the low. If anyone has any insight into this it would be greatly appreciated! Thank you in advance. Sorry I don't see where to insert an image without referencing a website. I have screenshots of this.
Code is as follows:
In this case, I am looking back each hour for 60 hourly periods, taking an average of the range and the high of each period and then projecting them. I feel like my calculations are correct but it clearly isn't displaying correctly. What it should do is find the low for the current 60-minute candle and add the average and upper price movement number to project the high. Conversely, it should find the high for the current 60-minute candle, and subtract the average and the upper price movement range for that hour to project the low. If anyone has any insight into this it would be greatly appreciated! Thank you in advance. Sorry I don't see where to insert an image without referencing a website. I have screenshots of this.
Code is as follows:
Code:
# HPMR 60-Period look-back
input aggregationPeriod = AggregationPeriod.HOUR;
def hourhigh = high(period = aggregationPeriod);
def hourlow = low(period = aggregationPeriod);
def houropen = open(period = aggregationPeriod);
def range = (hourhigh - hourlow);
# Median number of the range
def t1 = range[23]/2;
def t2 = range[46]/2;
def t3 = range[69]/2;
def t4 = range[92]/2;
def t5 = range[115]/2;
def t6 = range[138]/2;
def t7 = range[161]/2;
def t8 = range[184]/2;
def t9 = range[207]/2;
def t10 = range[230]/2;
def t11 = range[253]/2;
def t12 = range[276]/2;
def t13 = range[299]/2;
def t14 = range[322]/2;
def t15 = range[345]/2;
def t16 = range[368]/2;
def t17 = range[391]/2;
def t18 = range[414]/2;
def t19 = range[437]/2;
def t20 = range[460]/2;
def t21 = range[483]/2;
def t22 = range[506]/2;
def t23 = range[529]/2;
def t24 = range[552]/2;
def t25 = range[575]/2;
def t26 = range[598]/2;
def t27 = range[621]/2;
def t28 = range[644]/2;
def t29 = range[667]/2;
def t30 = range[690]/2;
def t31 = range[713]/2;
def t32 = range[736]/2;
def t33 = range[759]/2;
def t34 = range[782]/2;
def t35 = range[805]/2;
def t36 = range[828]/2;
def t37 = range[851]/2;
def t38 = range[874]/2;
def t39 = range[897]/2;
def t40 = range[920]/2;
def t41 = range[943]/2;
def t42 = range[966]/2;
def t43 = range[989]/2;
def t44 = range[1002]/2;
def t45 = range[1035]/2;
def t46 = range[1058]/2;
def t47 = range[1081]/2;
def t48 = range[1104]/2;
def t49 = range[1127]/2;
def t50 = range[1150]/2;
def t51 = range[1173]/2;
def t52 = range[1196]/2;
def t53 = range[1219]/2;
def t54 = range[1242]/2;
def t55 = range[1265]/2;
def t56 = range[1288]/2;
def t57 = range[1311]/2;
def t58 = range[1334]/2;
def t59 = range[1357]/2;
def t60 = range[1380]/2;
# Highs each period
def s1 = t1 * 2;
def s2 = t2 * 2;
def s3 = t3 * 2;
def s4 = t4 * 2;
def s5 = t5 * 2;
def s6 = t6 * 2;
def s7 = t7 * 2;
def s8 = t8 * 2;
def s9 = t9 * 2;
def s10 = t10 * 2;
def s11 = t11 * 2;
def s12 = t12 * 2;
def s13 = t13 * 2;
def s14 = t14 * 2;
def s15 = t15 * 2;
def s16 = t16 * 2;
def s17 = t17 * 2;
def s18 = t18 * 2;
def s19 = t19 * 2;
def s20 = t20 * 2;
def s21 = t21 * 2;
def s22 = t22 * 2;
def s23 = t23 * 2;
def s24 = t24 * 2;
def s25 = t25 * 2;
def s26 = t26 * 2;
def s27 = t27 * 2;
def s28 = t28 * 2;
def s29 = t29 * 2;
def s30 = t30 * 2;
def s31 = t31 * 2;
def s32 = t32 * 2;
def s33 = t33 * 2;
def s34 = t34 * 2;
def s35 = t35 * 2;
def s36 = t36 * 2;
def s37 = t37 * 2;
def s38 = t38 * 2;
def s39 = t39 * 2;
def s40 = t40 * 2;
def s41 = t41 * 2;
def s42 = t42 * 2;
def s43 = t43 * 2;
def s44 = t44 * 2;
def s45 = t45 * 2;
def s46 = t46 * 2;
def s47 = t47 * 2;
def s48 = t48 * 2;
def s49 = t49 * 2;
def s50 = t50 * 2;
def s51 = t51 * 2;
def s52 = t52 * 2;
def s53 = t53 * 2;
def s54 = t54 * 2;
def s55 = t55 * 2;
def s56 = t56 * 2;
def s57 = t57 * 2;
def s58 = t58 * 2;
def s59 = t59 * 2;
def s60 = t60 * 2;
def hpmr_avg = (t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 + t10 + t11 + t12 + t13 + t14 + t15 + t16 + t17 + t18 + t19 + t20 + t21 + t22 + t23 + t24 + t25 + t26 + t27 + t28 + t29 + t30 + t31 + t32 + t33 + t34 + t35 + t36 + t37 + t38 + t39 + t40 + t41 + t42 + t43 + t44 + t45 + t46 + t47 + t48 + t49 + t50 + t51 + t52 + t53 + t54 + t55 + t56 + t57 + t58 + t59 + t60) / 60;
def hpmr_high = (s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10 + s11 + s12 + s13 + s14 + s15 + s16 + s17 + s18 + s19 + s20 + s21 + s22 + s23 + s24 + s25 + s26 + s27 + s28 + s29 + s30 + s31 + s32 + s33 + s34 + s35 + s36 + s37 + s38 + s39 + s40 + s41 + s42 + s43 + s44 + s45 + s46 + s47 + s48 + s49 + s50 + s51 + s52 + s53 + s54 + s55 + s56 + s57 + s58 + s59 + s60) / 60;
def uppertopline = (hourlow + hpmr_high);
def upperlowerline = (hourlow + hpmr_avg);
def lowertopline = (hourhigh - hpmr_high);
def lowerlowerline = (hourhigh - hpmr_avg);
plot upperhigh = uppertopline;
plot upperlow = upperlowerline;
plot lowerhigh = lowertopline;
plot lowerlow = lowerlowerline;
addCloud(upperhigh, upperlow, color.RED, color.RED);
addCloud(lowerhigh, lowerlow, color.GREEN, color.GREEN);
upperhigh.SetDefaultColor(Color.red);
upperlow.SetDefaultColor(Color.red);
lowerhigh.SetDefaultColor(Color.green);
lowerlow.SetDefaultColor(Color.green);