ERHorner
New member
Good Afternoon,
This seemed like an easy script to create, but I can't seem to get it to adjust when I switch time frames. I was hoping to have an addlabel created that shows the average price based on whatever timeframe I'm looking at. For example: If I'm on a 30D:30M chart and the highest price is 90 and the lowest price is 0, than the average price is 45; and the addlabel would show 45. If I switched to a 90D:1H chart and the average price was 60, than the addlabel would update to 60. Below is the script I created, but I'm afraid I am not smart enough to trouble shoot. Any help is appreciated.
# Calculate Average Price based on Highest and Lowest Prices
declare lower;
input timeFrame = AggregationPeriod.DAY;
input priceInterval = AggregationPeriod.MIN;
def highPrice = high(period = timeFrame)[1];
def lowPrice = low(period = timeFrame)[1];
def averagePrice = (highPrice + lowPrice) / 2;
AddLabel(yes, "Average Price: " + AsPrice(averagePrice), color.white);
This seemed like an easy script to create, but I can't seem to get it to adjust when I switch time frames. I was hoping to have an addlabel created that shows the average price based on whatever timeframe I'm looking at. For example: If I'm on a 30D:30M chart and the highest price is 90 and the lowest price is 0, than the average price is 45; and the addlabel would show 45. If I switched to a 90D:1H chart and the average price was 60, than the addlabel would update to 60. Below is the script I created, but I'm afraid I am not smart enough to trouble shoot. Any help is appreciated.
# Calculate Average Price based on Highest and Lowest Prices
declare lower;
input timeFrame = AggregationPeriod.DAY;
input priceInterval = AggregationPeriod.MIN;
def highPrice = high(period = timeFrame)[1];
def lowPrice = low(period = timeFrame)[1];
def averagePrice = (highPrice + lowPrice) / 2;
AddLabel(yes, "Average Price: " + AsPrice(averagePrice), color.white);