Plot distance from moving average in thinkscript?

D

dj45

New member
I'm guessing someone has built this wheel before. Basically looking to plot the distance in % that close price is from a moving average. Since this plot will essentially oscillate, plotting horizontal lines to mark x% above and x% below makes it easy to see if price is overextended in either direction. So user defined inputs would be:
  1. length of MA
  2. simple or exponential
  3. values for horizontal lines
 
horserider

horserider

Well-known member
VIP
Code:
declare lower;

input price = close;
input length = 200;
input AverageType = {default Simple, Exponential};
input pdl = 3;
input ndl = -3;
def MA = MovingAverage(AverageType, ( price[0]), length);
plot DEV = (price / MA - 1 ) * 1000;

plot pdll = pdl;
plot ndll = ndl;
plot zero = 0;

DEV.SetDefaultColor(GetColor(1));

AddLabel(1, "Percentage from " + length + " MA: " + AsPercent(DEV * .01), if DEV > 0 then Color.GREEN else Color.PINK);
 
Last edited:
markos

markos

Well-known member
VIP
Here's another way to do it in a label:
Code:
# MA Distance Percentage
# Paris
# 4.13.2018
# Computes percentage the current close is above/below the 200 DSMA
# Displays on a lower chart

declare lower;

input length = 200;

def data = close;
def avg = Average(data, length);
def pct = (data/avg) - 1;

plot dist = pct;
plot zero = 0;

zero.SetDefaultColor(Color.WHITE);
zero.SetLineWeight(2);

AddLabel(1, "Percentage from " + length + " MA: " + AsPercent(pct), if pct > 0 then Color.GREEN else Color.PINK);
 
D

dj45

New member
Thanks guys, this looks great! And adding it to the label is a nice touch for quick scanning.
 
J

Johnny Cash

Member
[type = stock]
AND [country = US]
AND [Daily SMA(20,Daily Volume) > 500000]
AND [Daily SMA(50,Daily Close) > 10]
AND [PctChange(250,close) < -30]
AND [PctChange(32,close) > 10]
 
zeek

zeek

Active member
2019 Donor
As my titles says, i need a script that alerts me with audio notification and also a chart label when the price is close to 200EMA. And if it`s possible, i only need the alert to trigger if the price is in a downward direction towards the EMA.

I would like the alert to trigger 10 cents before hitting the EMA and the label should be active as long as price is within a 20 cents range from the EMA price. So for example, lets say 200EMA price is at 10,40 and then label should be active on chart between 10,30 - 10,50.

Can anyone help me code this?
Thanks in advance:)
 
E

Eli

New member
I'm looking for a script for finding stocks that the 10 EMA is above 3% from the 50 EMA in 5min chart.
TOS only has above or below.
 
L

luicius

New member
I am looking for a scan similar to this image where the overall security is trending downward and it's down by at least 20% from 200 periods ago - daily.


I thought something like this would work but it produces some results where the overall security is breaking the downward trend
Code:
input length = 200;
plot scan = Average(close, length) < Average(close, length)[length];
My goal is to have the overall security us trending down and it's down at least 20% 200 periods ago.
I would also be interested in one that is trending upward and up by at least 20% 200 periods ago.

Any help on how to achieve these desired results will greatly be appreciated.
 
1

111catalina

New member
I am looking for a scrip that can give me a signal when current price is 2% from EMA, Do you know where I can get it?
 
T

Trader_Vic

New member
VIP
I am looking for a scan similar to this image where the overall security is trending downward and it's down by at least 20% from 200 periods ago - daily.


I thought something like this would work but it produces some results where the overall security is breaking the downward trend
Code:
input length = 200;
plot scan = Average(close, length) < Average(close, length)[length];
My goal is to have the overall security us trending down and it's down at least 20% 200 periods ago.
I would also be interested in one that is trending upward and up by at least 20% 200 periods ago.

Any help on how to achieve these desired results will greatly be appreciated.
I would be interested in this as well. Let me know once you get this coded.
 
Ace78

Ace78

New member
Good Afternoon.
I'm looking for a 20 or 21 SMA that has the ability to change colors based on the candles % extended from the 20 SMA.
My Trading strategy, game plan, is to buy pullbacks to the 20 SMA and sell when over extended. To have a 20 SMA to change colors to alert me when I'm in a selling zone or buying zone would be great instead of using the measuring tool on ToS every time.

Idea of colors on the 20 SMA: Less than or equal to 4% from SMA is green; greater than 4% up to 8% orange, above 8% Red. Normal size width of the Line would be preferred, just like a regular SMA from ToS.
This would apply for both sides of the SMA. I would love to have this indicator if it does exist and would like to see if other people would be interested in it if it doesn't.
Any assistance would be greatly appreciated.
 
Top