Average Price Movements Indicator for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
Uses daily average ranges of 5 and 10 (most used) as buy (support) and highs (resistance) areas.




thinkScript Code

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);
 
Last edited:
S

Spriteman

New member
Hi Ben:

I wanted to ask you if there is a scan available for this indicator? Would love something that can be configured to find stocks within a certain dollar amount from either the high (h1) or low (l1)of their average price move and alert the user for a potential upcoming trade. I used this while watching my favorite stock DIS for four successful early morning trades on 3/27, 3/30, yesterday and today.

Appreciate your thoughts and help.

Best,

Spriteman
 
BenTen

BenTen

Administrative
Staff
VIP
@Spriteman You can use the crosses, crosses above, or crosses below as part of your scanner. There is no special configuration needed.
 
T

Topas

New member
Is it something like this ... ? Seems quite similar ... If yes ... then i could follow and test that strategy
 
S

Spriteman

New member
@Spriteman You can use the crosses, crosses above, or crosses below as part of your scanner. There is no special configuration needed.
@BenTen I was looking for a scan that could be configured to alert the user on a dollar amount or % prior to crossing h1 or l1 as a heads up to reaching either a resistence or support zone. do you think this is possible?
 
D

DeusMecanicus

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

K_O_Trader

New member
@Spriteman You can use the crosses, crosses above, or crosses below as part of your scanner. There is no special configuration needed.
@BenTen I"m not able to set up a scanner for this indicator like explained, It tells me its not allowed.
 
BenTen

BenTen

Administrative
Staff
VIP
@K_O_Trader Can you post a screenshot of the error?
 
BenTen

BenTen

Administrative
Staff
VIP
@K_O_Trader Oh I see. Unfortunately, ToS doesn't allow their scanner to work with this sort of indicator because it uses higher aggregation period.
 
K

K_O_Trader

New member
@K_O_Trader Oh I see. Unfortunately, ToS doesn't allow their scanner to work with this sort of indicator because it uses higher aggregation period.
I've tried all the aggregation periods, it denies all periods, is there a scanner out there that might be similar to telling me when the prices are in the zones?
 
fjr1300

fjr1300

Active member
VIP
Is it possible to AddChartBubble to each zone on the right or left of the screen right above or below the zone? I added them with my limited / non-existing coding experience and they repeat over and over.


AddChartBubble(h1 == h1 , h1 , "DAILY RESISTANCE" , Color.RED,no);

AddChartBubble(l2 == l2 , l2 , "DAILY SUPPORT" , Color.GREEN, yes);
 
P

Playstation

Active member
VIP
@fjr1300 took me about an hour to find out. here you go.

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

def h1 = hl1;
def l1 = ll1;
def h2 = hl2;
def 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);

#Edited By Playstation 23.05.2020
#You can set whether to show the bubbles. Change or add the h1,h2,l1,l2 values to your preference.

input showBubble = yes;
def SR = showBubble and !IsNaN(close) and IsNaN(close [-1] ) && HighestAll(BarNumber());

#This will show the price at the support and resistance levels.
AddChartBubble(SR,h2,Concat("R: ",Round(h2)),Color.RED);
AddChartBubble(SR,l2,Concat("S: ",Round(l2)),Color.GREEN);

#Swap hashtags if you want just the Resistance/Support words.
#AddChartBubble(SR, h2, "DAILY RESISTANCE", Color.RED);
#AddChartBubble(SR, l2, "DAILY SUPPORT", Color.GREEN);
 
fjr1300

fjr1300

Active member
VIP
Awesome. I am up since 3:00 AM ET This morning Studying my process. lol. I appreciate your effort. Perfect. It works great.

Question for you @Playstation. Is it possible to have conditional labels? ie.

[/URL]
 
Last edited by a moderator:
P

Playstation

Active member
VIP
I’ll see if i can do something about it. I’ma novice so no promises 😂
 
Top