Average Price Movements Indicator for ThinkorSwim

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Ben, Merry Christmas! Please tell me which timeframe settings to use in the Indicator for a 5Day 5 minute chart. Thanks
 
@3AMBH There is no set of rules for this indicator. Default is set to D (daily). You can play around with the aggregation periods and see which one will complement the 5D 5M chart best.
 
I Made it scannable.

https://tos.mx/Y6Yo0Nb

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/
# 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;

KTDR6Wr.png


Enjoy!
 
HI,

Can anyone help me with the setup for scanning stocks with price below the Average price movement on monthly.
The scan should list the stock if the Mark price is below the Avergae Price Movement Line (monthly)

Thanks In Advance
 
@raghu4228
See the below scanner box:
  • In the left-hand column choose your definition of price. The choices are close, high, open, etc... Mark.price is not a choice.
  • In the middle column choose less than
  • In the right-hand column choose study and then highlight whatever you named your Average Price Movement study
    Screenshot (86).png
 
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);
 
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);

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.
Screenshot 2023-10-06 162453.png
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);
 
@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 ?
 

Attachments

  • AVG Price movement.png
    AVG Price movement.png
    217.9 KB · Views: 68
@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 ?
If the scripts were identical and your chart timeframe and set ups are identical. Then results would be similar.

If they are not, then you must have something different somewhere.
No, it would not be possible to guess where you or the scripts diverge.
 
@MerryDay

I am using same timeframe and setups are identical. Please find both ToS and TV codes.

Please find the both the codes, let me know if you can spot any difference

ToS 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/

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 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);




###############################################################################
TradingView's pine script

//CD
//Average Daily Range Levels - 10 day
study(title="CD_Average Daily Range Zones", shorttitle="CD_Daily High/Low Zones V01", overlay=true)

//dayHigh=security(tickerid, 'D', high[1])
OPEN=security(tickerid, 'D', open)
//ADR L
dayrange=(high - low)
r1 = security(tickerid, 'D', dayrange[1])
r2 = security(tickerid, 'D', dayrange[2])
r3 = security(tickerid, 'D', dayrange[3])
r4= security(tickerid, 'D', dayrange[4])
r5= security(tickerid, 'D', dayrange[5])
r6 = security(tickerid, 'D', dayrange[6])
r7 = security(tickerid, 'D', dayrange[7])
r8 = security(tickerid, 'D', dayrange[8])
r9= security(tickerid, 'D', dayrange[9])
r10= security(tickerid, 'D', dayrange[10])




adr_10 = (r1+r2+r3+r4+r5+r6+r7+r8+r9+r10) /10
adr_9 = (r1+r2+r3+r4+r5+r6+r7+r8+r9) /9
adr_8 = (r1+r2+r3+r4+r5+r6+r7+r8) /8
adr_7 = (r1+r2+r3+r4+r5+r6+r7) /7
adr_6 = (r1+r2+r3+r4+r5+r6) /6
adr_5 = (r1+r2+r3+r4+r5) /5
adr_4 = (r1+r2+r3+r4) /4
adr_3 = (r1+r2+r3) /3
adr_2= (r1+r2)/2
adr_1 = r1



//plot
adrhigh10=plot((OPEN+(adr_10/2)) , title="ADR High10",style=circles,color=red,linewidth=2)
adrlow10=plot((OPEN-(adr_10/2)), title="ADR LOW10",style=circles, color=green,linewidth=2)
//adrhigh9=plot((OPEN+(adr_9/2)) , title="ADR High9",style=circles,color=red,linewidth=2)
//adrlow9=plot((OPEN-(adr_9/2)), title="ADR LOW9",style=circles, color=green,linewidth=2)
//adrhigh8=plot((OPEN+(adr_8/2)) , title="ADR High8",style=circles,color=red,linewidth=2)
//adrlow8=plot((OPEN-(adr_8/2)), title="ADR LOW8",style=circles, color=green,linewidth=2)
//adrhigh7=plot((OPEN+(adr_7/2)) , title="ADR High7",style=circles,color=red,linewidth=2)
//adrlow7=plot((OPEN-(adr_7/2)), title="ADR LOW7",style=circles, color=green,linewidth=2)
//adrhigh6=plot((OPEN+(adr_6/2)) , title="ADR High6",style=circles,color=red,linewidth=2)
//adrlow6=plot((OPEN-(adr_6/2)), title="ADR LOW6",style=circles, color=green,linewidth=2)
adrhigh5=plot((OPEN+(adr_5/2)) , title="ADR High5",style=circles,color=red,linewidth=2)
adrlow5=plot((OPEN-(adr_5/2)), title="ADR LOW5",style=circles, color=green,linewidth=2)
//adrhigh4=plot((OPEN+(adr_4/2)) , title="ADR High4",style=circles,color=red,linewidth=2)
//adrlow4=plot((OPEN-(adr_4/2)), title="ADR LOW4",style=circles, color=green,linewidth=2)
//adrhigh3=plot((OPEN+(adr_3/2)) , title="ADR High3",style=circles,color=red,linewidth=2)
//adrlow3=plot((OPEN-(adr_3/2)), title="ADR LOW3",style=circles, color=green,linewidth=2)
//adrhigh2=plot((OPEN+(adr_2/2)) , title="ADR High2",style=circles,color=red,linewidth=2)
//adrlow2=plot((OPEN-(adr_2/2)), title="ADR LOW2",style=circles, color=green,linewidth=2)
//adrhigh1=plot((OPEN+(adr_1/2)) , title="ADR High1",style=circles,color=red,linewidth=2)
//adrlow1=plot((OPEN-(adr_1/2)), title="ADR LOW1",style=circles, color=green,linewidth=2)


fill(adrlow10,adrlow5,color=lime)
fill(adrhigh10,adrhigh5,color=maroon)
//fill(adrlow2,adrlow9,color=lime)
//fill(adrhigh2,adrhigh9,color=maroon)
//fill(adrlow3,adrlow8,color=lime)
//fill(adrhigh3,adrhigh8,color=maroon)
//fill(adrlow4,adrlow7,color=lime)
//fill(adrhigh4,adrhigh7,color=maroon)
//fill(adrlow6,adrlow2,color=lime)
//fill(adrhigh6,adrhigh2,color=maroon)
 
Another variant using a method I've used for average range for quite some time. I use this method so that you can adjust the duration of your average easily if you'd like to "poke around".

Code:
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);

Two differences here:

1) your added indicator measures for 14 periods vs. 5 or 10 which allows for the larger ranges of days to influence the average higher.

2) This is also calculating based on ATR (Average True Range) which incorporates the CLOSE along with high and low vs. just high and low.

Nothing wrong with the approach, just sharing the difference I'm seeing. Range simply contracts and expands over and over again. It is conceivable to histogram those adjustments and see cycles in contraction and expansion over longer periods of time.

You can also make a label that indicates what percentage of average range or ATR the price action of a particular period has achieved as well.
 
@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 ?
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.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
400 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

How do I get started?

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.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top