C

#### Craighaber71

##### Member

**2019 Donor**

**Warehouse**

**VIP**

Thanks

C

Thanks

Code:

```
# Price crossing above or below 9 EMA and VWAP
# By BenTen of useThinkScript.com
declare upper;
# Moving Average
input priceMA = close;
input lengthMA = 9;
input displace = 0;
input showBreakoutSignals = yes;
input price = close;
def EMA = ExpAverage(priceMA[-displace], lengthMA);
def UpSignal = priceMA crosses above EMA;
def DownSignal = priceMA crosses below EMA;
# VWAP
input numDevDn = -2.0;
input numDevUp = 2.0;
input timeFrame = {default DAY, WEEK, MONTH};
def cap = GetAggregationPeriod();
def errorInAggregation =
timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or
timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH;
Assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");
def yyyyMmDd = GetYYYYMMDD();
def periodIndx;
switch (timeFrame) {
case DAY:
periodIndx = yyyyMmDd;
case WEEK:
periodIndx = Floor((DaysFromDate(First(yyyyMmDd)) + GetDayOfWeek(First(yyyyMmDd))) / 7);
case MONTH:
periodIndx = RoundDown(yyyyMmDd / 100, 0);
}
def isPeriodRolled = CompoundValue(1, periodIndx != periodIndx[1], yes);
def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;
if (isPeriodRolled) {
volumeSum = volume;
volumeVwapSum = volume * vwap;
volumeVwap2Sum = volume * Sqr(vwap);
} else {
volumeSum = CompoundValue(1, volumeSum[1] + volume, volume);
volumeVwapSum = CompoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap);
volumeVwap2Sum = CompoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap));
}
def priceVWAP = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(priceVWAP), 0));
def VWAP = priceVWAP;
#plot UpperBand = priceVWAP + numDevUp * deviation;
#plot LowerBand = priceVWAP + numDevDn * deviation;
def UpVWAP = price > VWAP;
def DownVWAP = price < VWAP;
def bullish_signal = UpSignal and UpVWAP;
def bearish_signal = DownSignal and DownVWAP;
# Plot Signals
plot bullish = bullish_signal;
bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish.SetDefaultColor(Color.CYAN);
bullish.SetLineWeight(3);
plot bearish = bearish_signal;
bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish.SetDefaultColor(Color.CYAN);
bearish.SetLineWeight(3);
```

C

Awesome...Will that work in a watch list

Any VWAP Cross Over Indicator with Moving Average.

Please explain more detail of what you want. Not sure what you asked makes much sense.

Thanks to all, I thinks that script above resolve my question

B

T

Code:

```
def lookback = 0;
def EMA = ExpAverage(close, 9);
def vwapValue = VWAP()[lookback];
plot scan = EMA crosses vwapValue;
```

L

i saw a post to mark bullish and bearish when price move above and below vwap but i would like to leave rage that to identify vwap upper and lower band cross also with different coloring so that it will be easy for us to watch the stock when it reaches those levels.

P

@BenTen @tomsk , or anyone else available to help, I was wondering if I could get some help to finish up this TOS code for watch-list that I was trying to complete, to show green when 9 ema crosses above vwap within last 3 bars, customizable for timeframes, and opposite as well, if 9 ema crosses below vwap within last 3 bars; Here is what I have gotten started:

input maLengthOne = 9;

input maType=AverageType, EXPONENTIAL

input timeFrame = {default DAY, WEEK, MONTH};

def vwapValue = reference VWAP(-2, 2, timeFrame)."VWAP";

def ma = MovingAverage(maType, vwapValue, maLength);

inputbarsAfterCross = 3;

def crossAbove = maLengthOne > vwap

def crossBelow = maLengthOne < vwap

diff.AssignValueColor(if ma == vwap then Color.CURRENT else Color.BLACK);

AssignBackgroundColor(if diff > 0 then Color. GREEN else if diff < 0 then Color.RED else Color.CURRENT);

Thank you

Papa

P

I am getting the messages invalid statements at the certain lines 2, 7 and 10.

If anyone could advise would be great, I am not a coder, but attempted to piece together what I could;

Thanks in advance @BenTen @tomsk @horserider @netarchitech or anyone else who can help me with this!

input maLengthOne = 9;

input maType=AverageType, EXPONENTIAL

input timeFrame = {default DAY, WEEK, MONTH};

def vwapValue = reference VWAP(-2, 2, timeFrame)."VWAP";

def ma = MovingAverage(maType, vwapValue, maLength);

inputbarsAfterCross = 3;

def crossAbove = maLengthOne > vwap

def crossBelow = maLengthOne < vwap

diff.AssignValueColor(if ma == vwap then Color.CURRENT else Color.BLACK);

AssignBackgroundColor(if diff > 0 then Color. GREEN else if diff < 0 then Color.RED else Color.CURRENT)

Invalid statement: input at 2:1

Invalid statement: def at 7:1

Invalid statement: AssignBackgroundC... at 10:1

THIS ONES GREAT I LOVE IT

T

@PapaBear10 Your code had several syntax errors. Here is my version of a VWAP Watchlist that is painted green when 9 ema crosses above vwap within last 3 bars. It is painted red when 9 ema crosses below vwap within last 3 bars. Remember to select the aggregation period you are interested in when configuring this watchlist

Code:

```
# VWAP Watchlist
# tomsk
# 1.25.2020
# Watchlist that is painted green when 9 ema crosses above vwap within last 3 bars
# It is painted red when 9 ema crosses below vwap within last 3 bars
input length = 9;
def ema = ExpAverage(close, length);
def vwapValue = reference VWAP();
def crossUp = ema crosses above vwapValue within 3 bars;
def crossDn = ema crosses below vwapValue within 3 bars;
AddLabel(1, if crossUp then "X Up" else if crossDn then "X Down" else " ", Color.Black);
AssignBackgroundColor(if ema crosses above vwapValue then Color.GREEN
else if ema crosses below vwapValue then Color.RED
else Color.Gray);
# End VWAP Watchlist
```

Last edited:

P

Thank you so much for your help!

S

Tom, what would I change here to track price crossing? I've got the following; how to I blend them together? I really like the 3-bars approach, so that it will disappear after the cross happens. I've tried swapping out the input length, etc.Your code had several syntax errors. Here is my version of a VWAP Watchlist that is painted green when 9 ema crosses above vwap within last 3 bars.

plot vwap = vwap();

AssignBackgroundColor(if close > vwap then Color.DARK_GREEN else if close < vwap then Color.DARK_RED else Color.Dark_ORANGE);

H