# Average Price Movements
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/eHhGyI6R-CD-Average-Daily-Range-Zones-highs-and-lows-of-the-day/
# Made Scannable by Ramon DV aka Pelonsax
def dayrange = (high - low);
def r1 = dayrange[1];
def r2 = dayrange[2];
def r3 = dayrange[3];
def r4 = dayrange[4];
def r5 = dayrange[5];
def r6 = dayrange[6];
def r7 = dayrange[7];
def r8 = dayrange[8];
def r9 = dayrange[9];
def r10 = dayrange[10];
def adr_10 = (r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 + r9 + r10) / 10;
def adr_5 = (r1 + r2 + r3 + r4 + r5) / 5;
def hl1 = (open + (adr_10 / 2));
def ll1 = (open - (adr_10 / 2));
def hl2 = (open + (adr_5 / 2));
def ll2 = (open - (adr_5 / 2));
def h1 = hl1;
def l1 = ll1;
def h2 = hl2;
def l2 = ll2;
plot ADRH = if h1 > h2 then h1 else if h1 < h2 then h2 else h1;
plot ADRL = if l1 > l2 then l2 else if l1 < l2 then l1 else l2;
https://usethinkscript.com/threads/...icator-for-thinkorswim.1230/page-2#post-45894Hello @BenTen , Thanks for this wonderful indicator.
For daytrading do we need to use "1Day" Aggregation or "1Week" for best 'of this.
Thanks in advance,
Hi I need help with this indicator
https://usethinkscript.com/threads/average-price-movements-indicator-for-thinkorswim.1230/
pls. What I need is the zones it creates is fine and everything works fine also but I also want the zones from yesterday to be plotted today also. They could just be grey zones not any color. Can you please help. Thanks
# Average Price Movements
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/eHhGyI6R-CD-Average-Daily-Range-Zones-highs-and-lows-of-the-day/
input aggregationPeriod = AggregationPeriod.DAY;
def open = open(period = aggregationPeriod);
def high = high(period = aggregationPeriod);
def low = low(period = aggregationPeriod);
def dayrange = (high - low);
def r1 = dayrange[1];
def r2 = dayrange[2];
def r3 = dayrange[3];
def r4 = dayrange[4];
def r5 = dayrange[5];
def r6 = dayrange[6];
def r7 = dayrange[7];
def r8 = dayrange[8];
def r9 = dayrange[9];
def r10 = dayrange[10];
def adr_10 = (r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 + r9 + r10) / 10;
def adr_5 = (r1 + r2 + r3 + r4 + r5) / 5;
def hl1 = (OPEN + (adr_10 / 2));
def ll1 = (OPEN - (adr_10 / 2));
def hl2 = (OPEN + (adr_5 / 2));
def ll2 = (OPEN - (adr_5 / 2));
plot h1 = hl1;
plot l1 = ll1;
plot h2 = hl2;
plot l2 = ll2;
addCloud(h1, h2, color.RED, color.RED);
addCloud(l1, l2, color.GREEN, color.GREEN);
h1.SetDefaultColor(Color.dark_red);
h2.SetDefaultColor(Color.dark_red);
l1.SetDefaultColor(Color.dark_green);
l2.SetDefaultColor(Color.dark_green);
Code:# Average Price Movements # Assembled by BenTen at useThinkScript.com # Converted from https://www.tradingview.com/script/eHhGyI6R-CD-Average-Daily-Range-Zones-highs-and-lows-of-the-day/ script pricemove { input daysago = 0; input aggregationPeriod = AggregationPeriod.DAY; def open = open(period = aggregationPeriod)[daysago]; def high = high(period = aggregationPeriod)[daysago]; def low = low(period = aggregationPeriod)[daysago]; def dayrange = (high - low); def r1 = dayrange[1]; def r2 = dayrange[2]; def r3 = dayrange[3]; def r4 = dayrange[4]; def r5 = dayrange[5]; def r6 = dayrange[6]; def r7 = dayrange[7]; def r8 = dayrange[8]; def r9 = dayrange[9]; def r10 = dayrange[10]; def adr_10 = (r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 + r9 + r10) / 10; def adr_5 = (r1 + r2 + r3 + r4 + r5) / 5; def hl1 = (OPEN + (adr_10 / 2)); def ll1 = (OPEN - (adr_10 / 2)); def hl2 = (OPEN + (adr_5 / 2)); def ll2 = (OPEN - (adr_5 / 2)); plot h1 = hl1; plot l1 = ll1; plot h2 = hl2; plot l2 = ll2; } #End of pricemove script input showtodayonly = yes; #Current Days plot ph1 = if showtodayonly and getday()!=getlastday() then double.nan else pricemove(0).h1; plot ph2 = if showtodayonly and getday()!=getlastday() then double.nan else pricemove(0).h2; plot pl1 = if showtodayonly and getday()!=getlastday() then double.nan else pricemove(0).l1; plot pl2 = if showtodayonly and getday()!=getlastday() then double.nan else pricemove(0).l2; ph1.SetDefaultColor(Color.dark_red); ph2.SetDefaultColor(Color.dark_red); pl1.SetDefaultColor(Color.dark_green); pl2.SetDefaultColor(Color.dark_green); addCloud(ph1, ph2, color.RED, color.RED, showBorder = Yes); addCloud(pl1, pl2, color.GREEN, color.GREEN, showBorder = Yes); #Previous Days plot ph11 = if showtodayonly and getday()!=getlastday() then double.nan else pricemove(1).h1; plot ph21 = if showtodayonly and getday()!=getlastday() then double.nan else pricemove(1).h2; plot pl11 = if showtodayonly and getday()!=getlastday() then double.nan else pricemove(1).l1; plot pl21 = if showtodayonly and getday()!=getlastday() then double.nan else pricemove(1).l2; ph11.SetDefaultColor(Color.gray); ph21.SetDefaultColor(Color.gray); pl11.SetDefaultColor(Color.gray); pl21.SetDefaultColor(Color.gray); addCloud(ph11, ph21, color.gray, color.gray); addCloud(pl11, pl21, color.gray, color.gray);
If the scripts were identical and your chart timeframe and set ups are identical. Then results would be similar.@BenTen I used same indicator in Thinkorswim and Tradingview and getting different ranges. May I know what is causing this difference and how can I fix this ?
input aggregationPeriod = AggregationPeriod.DAY;
def open = open(period = aggregationPeriod);
def high = high(period = aggregationPeriod);
def low = low(period = aggregationPeriod);
def dayrange = (high - low);
def adr_10 = average(dayrange,10);
def adr_5 = average(dayrange,5);
def hl1 = (OPEN + (adr_10 / 2));
def ll1 = (OPEN - (adr_10 / 2));
def hl2 = (OPEN + (adr_5 / 2));
def ll2 = (OPEN - (adr_5 / 2));
plot upper2 = hl1;
plot lower1 = ll2;
plot upper1 = hl2;
plot lower2 = ll1;
addCloud(upper2, upper1, color.RED, color.RED);
addCloud(lower1, lower2, color.GREEN, color.GREEN);
upper1.SetDefaultColor(Color.dark_red);
upper2.SetDefaultColor(Color.dark_red);
lower1.SetDefaultColor(Color.dark_green);
lower2.SetDefaultColor(Color.dark_green);
I've been using something similar after modding a @tomsk indicator. It has a wider range than the one posted but will sometimes provide reversal points if the price breaks out from the posted indicator.
@Topas if you change the agg period on this code to hourly or two hour it will sometimes provide signals similar to the volatility box. As you can see in the last image, sometimes the volatility indicators work, sometimes they don't.
Code:# ATR Daily Range # tomsk # 12.17.2019 # V1.0 - 12.16.2019 - tomsk - Initial release ATR Daily Range # V1.1 - 12.16.2019 - tomsk - Added performance relative to ATR range # V1.2 - 12.17.2019 - tomsk - Added plot lines for ATR High/Low on the chart # Displays ATR High/Low thresholds relative to daily open input length = 14; input averageType = AverageType.WILDERS; def o = open(period = AggregationPeriod.DAY); def h = high(period = AggregationPeriod.DAY); def l = low(period = AggregationPeriod.DAY); def c = close(period = AggregationPeriod.DAY); def R = (c - l) / (h - l); def ATRD = MovingAverage(averageType, TrueRange(h, c, l), length); def ATRH = o + ATRD; def ATRL = o - ATRD; AddLabel(1, "ATR Daily High/Low Level = [ " + Round(ATRH,2) + " / " + Round(ATRL,2) + " ]", Color.PINK); AddLabel(1, "Current Close = " + close + " [ " + AsPercent(R) + " ]", Color.YELLOW); def LBN = if isNaN(close[-1]) and !isNaN(close) then barnumber() else Double.NaN; #plot ATR_High = if barNumber() >= highestAll(LBN) # then highestAll(if isNaN(close[-1]) then ATRH else Double.NaN) # else Double.NaN; #ATR_High.SetLineWeight(2); #ATR_High.SetDefaultColor(Color.Cyan); #plot ATR_Low = if barNumber() >= highestAll(LBN) # then highestAll(if isNaN(close[-1]) then ATRL else Double.NaN) else Double.NaN; #ATR_Low.SetLineWeight(2); #ATR_Low.SetDefaultColor(Color.Yellow); # End ATR Daily Range ##DeusMecanicus Mod def ATRHH = o + (ATRD * 1.1); def ATRLL = o - (ATRD * 1.1); plot ATR_High = ATRH; ATR_High.SetLineWeight(2); ATR_High.SetDefaultColor(Color.CYAN); plot ATR_Low = ATRL; ATR_Low.SetLineWeight(2); ATR_Low.SetDefaultColor(Color.MAGENTA); plot ATR_High1 = ATRHH; ATR_High.SetLineWeight(2); ATR_High.SetDefaultColor(Color.CYAN); plot ATR_Low1 = ATRLL; ATR_Low.SetLineWeight(2); ATR_Low.SetDefaultColor(Color.MAGENTA); AddCloud(ATR_High, ATR_High1, Color.CYAN, Color.CYAN, yes); AddCloud(ATR_Low, ATR_Low1, Color.MAGENTA, Color.MAGENTA, yes); input showBreakoutSignals = yes; plot DownSignal = high crosses above ATR_High; plot UpSignal = low crosses below ATR_Low; UpSignal.SetHiding(!showBreakoutSignals); DownSignal.SetHiding(!showBreakoutSignals); UpSignal.SetDefaultColor(Color.UPTICK); UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); DownSignal.SetDefaultColor(Color.DOWNTICK); DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); Alert(UpSignal, "Buy", Alert.Bar, Sound.Chimes); Alert(DownSignal, "Sell", Alert.bar, Sound.Chimes);
Looking at the pricing of the instrument it seems your ToS chart is calculating off a different price than your tradingview chart is. Follow the gear icon on your chart, check the equities tab. I'm not familiar enough with tradingview to know which price the indicator is calculating from but it looks as though it may be bid or ask.@BenTen I used same indicator in Thinkorswim and Tradingview and getting different ranges. May I know what is causing this difference and how can I fix this ?
Good morning @SleepyZ, I was wondering if the function to select day, week, and month could be added to the indicator, thanks for your help.This uses the script function to be able to better control the coloring of clouds and show the current and previous day's high/low just on the current day when showtodayonly is selected.
The image in the upper panel is the current day in red/green and the previous day in gray clouds when showtodayonly is set to yes. The lower panel is when showtodayonly is set to no.
Good morning @SleepyZ, I was wondering if the function to select day, week, and month could be added to the indicator, thanks for your help.
Code:# Average Price Movements # Assembled by BenTen at useThinkScript.com # Converted from https://www.tradingview.com/script/eHhGyI6R-CD-Average-Daily-Range-Zones-highs-and-lows-of-the-day/ # Added Aggperiods DAY, WEEK, MONTH script pricemove { input periodsago = 0; input aggregationPeriod = AggregationPeriod.DAY; def open = open(period = aggregationPeriod)[periodsago]; def high = high(period = aggregationPeriod)[periodsago]; def low = low(period = aggregationPeriod)[periodsago]; def periodrange = (high - low); def r1 = periodrange[1]; def r2 = periodrange[2]; def r3 = periodrange[3]; def r4 = periodrange[4]; def r5 = periodrange[5]; def r6 = periodrange[6]; def r7 = periodrange[7]; def r8 = periodrange[8]; def r9 = periodrange[9]; def r10 = periodrange[10]; def adr_10 = (r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 + r9 + r10) / 10; def adr_5 = (r1 + r2 + r3 + r4 + r5) / 5; def hl1 = (open + (adr_10 / 2)); def ll1 = (open - (adr_10 / 2)); def hl2 = (open + (adr_5 / 2)); def ll2 = (open - (adr_5 / 2)); plot h1 = hl1; plot l1 = ll1; plot h2 = hl2; plot l2 = ll2; } #End of pricemove script input showlastperiodonly = no; input aggPeriod = {default "DAY", "WEEK", "MONTH"}; def agg_basis = if aggPeriod == aggPeriod."DAY" then GetDay() != GetLastDay() else if aggPeriod == aggPeriod."WEEK" then GetWeek() != GetLastWeek() else GetMonth() != GetLastMonth(); #Current Periods plot ph1 = if showlastperiodonly and agg_basis then Double.NaN else pricemove(0, aggPeriod).h1; plot ph2 = if showlastperiodonly and agg_basis then Double.NaN else pricemove(0, aggPeriod).h2; plot pl1 = if showlastperiodonly and agg_basis then Double.NaN else pricemove(0, aggPeriod).l1; plot pl2 = if showlastperiodonly and agg_basis then Double.NaN else pricemove(0, aggPeriod).l2; ph1.SetDefaultColor(Color.DARK_RED); ph2.SetDefaultColor(Color.DARK_RED); pl1.SetDefaultColor(Color.DARK_GREEN); pl2.SetDefaultColor(Color.DARK_GREEN); AddCloud(ph1, ph2, Color.RED, Color.RED, showBorder = yes); AddCloud(pl1, pl2, Color.GREEN, Color.GREEN, showBorder = yes); #Previous Periods plot ph11 = if showlastperiodonly and agg_basis then Double.NaN else pricemove(1, aggPeriod).h1; plot ph21 = if showlastperiodonly and agg_basis then Double.NaN else pricemove(1, aggPeriod).h2; plot pl11 = if showlastperiodonly and agg_basis then Double.NaN else pricemove(1, aggPeriod).l1; plot pl21 = if showlastperiodonly and agg_basis then Double.NaN else pricemove(1, aggPeriod).l2; ph11.SetDefaultColor(Color.GRAY); ph21.SetDefaultColor(Color.GRAY); pl11.SetDefaultColor(Color.GRAY); pl21.SetDefaultColor(Color.GRAY); AddCloud(ph11, ph21, Color.GRAY, Color.GRAY); AddCloud(pl11, pl21, Color.GRAY, Color.GRAY); #
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.