Difference between moving average and price labels

traderintheroom

traderintheroom

Member
I am looking for a label script for the following:

Different between Current Price and the 200 day Simple Moving Average
100 divided by (the above number plus 15%) = What I am looking to be displayed.

I am sure this is simple, but I am struggling. Thanks for the help! I also would like this in a watch list column
 
Last edited:
traderintheroom

traderintheroom

Member
Here's what I got without luck...

plot simpleMovingAvg200 = simpleMovingAvg(close, 200);
simpleMovingAvg200.setdefaultColor(color.RED);
AddLabel(1, "SMA Price Difference: " + Round(simpleMovingAvg200-priceType.LAST, 2), color.RED);
 
traderintheroom

traderintheroom

Member
Thanks for reply. This is close, I think the way I wrote out the data I was looking for wasn't clear. Here is an example:

These are made up numbers/Stock ABC

Current Price: $120
200 SMA: $119
Difference between the two: $1
Difference + 15% = $1.15
100 divided by 1.15 = 87 (rounded)

87 formula is the # I would like displayed in a chart label
 
traderintheroom

traderintheroom

Member
And if it is easier, a chart label that just shows the difference between current price and the 200 SMA (in # not %) would be sufficient
 
C

cacososa

New member
Hello

I'm really new to thinkOrSwim and ThinkScript.
I would like to create a a custom script to add a column in my SP500 watch list that indicates the SYMB whos current price is between SMA20 and SMA40 (timeframe would be in the hourly format). Any recommendation on good tutorials on how I can accomplish this task would be greatly appreciated

Thanks

CES.
 
G

gbears96

New member
Hello everyone,

I'm wondering if someone can help me with the code for 2 TOS watchlist column that do the following:

1. Column that shows the % difference between the Last candle closing price and the 4 EMA.

2. Column that shows the % difference between Mark and the 4 EMA.

Thank you in advance!
 
BenTen

BenTen

Administrative
Staff
VIP
@gbears96 This should give you the difference between the closing price and the 4 EMA:

Code:
# Display % difference between close and exponentialDeviationBands moving average

input length = 4;
def ema = ExpAverage(close, length);
def diff = absValue(close - ema) * 100 / close;
plot value = diff;
 

Similar threads

Top