Help with SMA and VWAP distance labels

Jimmy

New member
Looking to put together a watch column/chart label that shows the following:
1) distance from the 9 sma both in percentage and actual price difference
2) distance from VWAP both in percentage and actual price difference.
Then label with percentage and actual price difference with the following conditions.
If price is above both the 9sma and VWAP label is green.
If price is below the 9 but above VWAP label is yellow.
If price is below VWAP but above the 9 label is orange
If price is below both the 9sma and VWAP label is red.
Would like to use on multiple time frames.
Example... daily, hourly, 10 min.

I can make individual labels showing percentage away from the 9 and VWAP but don't know the input for actual price or how to combine all the info into one label.
Thanks in advance for any insight,
Jimmy
 

tomsk

Well-known member
VIP
@Jimmy Here is the modified version to tack on SMA(9) to VWAP per your request.

Code:
# Distance from SMA and VWAP
# tomsk
# 12.15.2019

# Added distance from SMA(9) to VWAP as requested by @Jimmy

input length = 9;

def sma = Average(close, length);
def DistanceSMA = (close - sma);
def vwapValue = VWAP();
def DistanceVWAP = (close - vwapValue);

AddLabel(1, "Price to SMA(" + length + ") = " + AsText(DistanceSMA) + " (" + AsPercent(close/sma-1) + ")" + "    Price to VWAP = " + AsText(DistanceVWAP) + " (" + AsPercent(close/vwapValue-1) + ")" + "    SMA(" + length + ") to VWAP = " + AsText(sma-vwapValue) + " (" + AsPercent(sma/vwapValue-1) + ")", if close > sma and close > vwapValue then Color.GREEN else if close < sma and close < vwapValue then Color.RED else if close < sma and close > vwapValue then Color.YELLOW else if close > sma and close < vwapValue then Color.ORANGE else 
Color.WHITE);
# End Distance from SMA and VWAP
 

Egom31

New member
Hello, can you help me make a label that gives me the distance from the Current Price to Vwap in Amount and percent. I can figure it out. thanks!
 
Last edited:

bsdvs23

New member
Hello Community -

I'm looking to display labels on my charts and hoped to find someone with time and capable of helping.

Display Labels in upper corner.
1. Display whether the MACD Value line is "above or below" the MACD Average Line.
1b. For Daily Timeframe
1c. For active Intraday Timeframe

Display Label in upper corner.
2. Display the space between two averages (to determine how far apart they are).
2b. SMA(20) - SMA(50)

I hope the above was simple and concise enough for those reading.
 
Last edited:

wtf_dude

Active member
Hello Community -

I'm looking to display labels on my charts and hoped to find someone with time and capable of helping.

Display Labels in upper corner.
1. Display whether the MACD Value line is "above or below" the MACD Average Line.
1b. For Daily Timeframe
1c. For active Intraday Timeframe

Display Label in upper corner.
2. Display the space between two averages (to determine how far apart they are).
2b. SMA(20) - SMA(50)

I hope the above was simple and concise enough for those reading.
Don't say I never did nothin for ya

Code:
declare upper;

# bsdvs23 request on 5.3.21
# wtf_dude

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input AverageType = AverageType.EXPONENTIAL;
input MA_Length1 = 20;
input MA_Length2 = 50;
input AverageType2 = AverageType.simple;


def agg1 = aggregationPeriod.day;
def agg2 = getaggregationPeriod();

##### MACD Day label

def ValueDay = MovingAverage(averageType, close("period" =agg1), fastLength) - MovingAverage(averageType, close("period" =agg1), slowLength);
def AvgDay = MovingAverage(averageType, ValueDay, MACDLength);

addlabel(yes, "MACD Day: " + if valueday>avgday then "Above" else "Below", if valueday>avgday then color.green else color.red);

##### MACD current timeframe label

def Value = MovingAverage(averageType, close("period"=agg2), fastLength) - MovingAverage(averageType, close("period"=agg2), slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);

addlabel(yes, "MACD: " + if value>avg then "Above" else "Below", if value>avg then color.green else color.red);

##### Moving Average Label

def MovAvg = MovingAverage(averageType2, close, MA_Length1); 
def MovAvg2 = MovingAverage(averageType2, close, MA_Length2); 

def diff = (movavg - movavg2)/Movavg2;

addlabel(yes,"MA distance: " + aspercent(diff), if diff>0 then color.green else color.red);
 

DMacTrades

New member
Hi @wtf_dude . I saw your post above and would like to know if you have a solution for the following:

I would like to add a label to my charts that tell me how far extended (above or below), expressed as a percentage, the price is from the 1 hour 9EMA without having to switch to a 1 hour chart (regardless of what time-frame chart I am on).

I have been playing with a script by @tomsk (below), however I can't figure out how to deal with the aggregation period i.e. being able to specify the 1 hour 9EMA. Any help wold be really appreciated.

Code:
# Moving Average Distance
# tomsk
# 12.13.2019

input price = close;
input length = 50;

plot avg = ExpAverage(price, length);
AddLabel(1, "Distance from " + length + " EMA = " + AsDollars(price - avg), Color.YELLOW);
AddLabel(2, "Distance from " + length + " EMA = " + Aspercent((price - avg) / price), Color.YELLOW);
# End Moving Average Distance
 

wtf_dude

Active member
Hi @wtf_dude . I saw your post above and would like to know if you have a solution for the following:

I would like to add a label to my charts that tell me how far extended (above or below), expressed as a percentage, the price is from the 1 hour 9EMA without having to switch to a 1 hour chart (regardless of what time-frame chart I am on).

I have been playing with a script by @tomsk (below), however I can't figure out how to deal with the aggregation period i.e. being able to specify the 1 hour 9EMA. Any help wold be really appreciated.


# Moving Average Distance
# tomsk
# 12.13.2019

input price = close;
input length = 50;

plot avg = ExpAverage(price, length);
AddLabel(1, "Distance from " + length + " EMA = " + AsDollars(price - avg), Color.YELLOW);
AddLabel(2, "Distance from " + length + " EMA = " + Aspercent((price - avg) / price), Color.YELLOW);
# End Moving Average Distance
Ah the problem is that you cant use an aggregation period that's lower than the timeframe you're already on. So if you were in the minute charts, you could see the label BUT if you're in the daily charts you won't. Make sense? Really annoying, not sure why they still don't have a fix
 

DMacTrades

New member
Ah the problem is that you cant use an aggregation period that's lower than the timeframe you're already on. So if you were in the minute charts, you could see the label BUT if you're in the daily charts you won't. Make sense? Really annoying, not sure why they still don't have a fix

Thanks for the quick feedback. Got it.

I trade primarily off the 5 min chart and higher. Would it be possible to have what I've described appear on, for example, the 5 or 15 min chart? My goal is to know how much the price is extended (above or below) (as a %) the hourly 9EMA regardless of whether I'm on a 5min chart or lower. It wold be like what my chart setup is for the 9EMAs (the fact that I can see them on all of the various time-frames (here is a link to my chart setup: http://tos.mx/bybssEz).
 

wtf_dude

Active member
Thanks for the quick feedback. Got it.

I trade primarily off the 5 min chart and higher. Would it be possible to have what I've described appear on, for example, the 5 or 15 min chart? My goal is to know how much the price is extended (above or below) (as a %) the hourly 9EMA regardless of whether I'm on a 5min chart or lower. It wold be like what my chart setup is for the 9EMAs (the fact that I can see them on all of the various time-frames (here is a link to my chart setup: http://tos.mx/bybssEz).
Not sure if I get you, but give this a shot:

Code:
declare upper;

input price = close;
input length = 9;
input Agg= AggregationPeriod.HOUR;
input Avg_Type = averageType.EXPONENTIAL;


def MyPrice = close(period = Agg);
def avg = MovingAverage(Avg_Type, Myprice, length);

AddLabel(yes, "Dollar Dist. from " + length + " EMA = " + AsDollars(close - avg), Color.YELLOW);
AddLabel(yes, "Percent Dist. from " + length + " EMA = " + Aspercent((close - avg) / price), Color.YELLOW);
# End Moving Average Distance
 

DMacTrades

New member
Not sure if I get you, but give this a shot:

Code:
declare upper;

input price = close;
input length = 9;
input Agg= AggregationPeriod.HOUR;
input Avg_Type = averageType.EXPONENTIAL;


def MyPrice = close(period = Agg);
def avg = MovingAverage(Avg_Type, Myprice, length);

AddLabel(yes, "Dollar Dist. from " + length + " EMA = " + AsDollars(close - avg), Color.YELLOW);
AddLabel(yes, "Percent Dist. from " + length + " EMA = " + Aspercent((close - avg) / price), Color.YELLOW);
# End Moving Average Distance

You get me exactly! I really appreciate that. Thank you very much!
 

Similar threads

Top