• Memorial Day Sale! Claim the biggest discount of the year with $50 off VIP using code MEM50. Sign up here.

Adding AdaptiveEMA to this MovAvg Cloud indicator?


Active member
Is there anyone that can help make the FastMA set to be the AdaptiveEMA in the cloud for the code below? Also is there a way to make a MovAvg cloud between an AdaptiveEMA and VWAP? It would be fun to test out. Thanks!
# Moving Average Crossover With Arrows, Alerts, Crossing Count and Bubble at Cross
# Mobius
# Chat Room Request 01.25.2017
# Modified a bit by BenTen

input price = close;
input fastLength = 34;
input slowLength = 50;
input averageType = AverageType.EXPONENTIAL;

plot FastMA = MovingAverage(averageType, price, fastLength);
plot SlowMA = MovingAverage(averageType, price, slowLength);

plot ArrowUp = if FastMA crosses above SlowMA
               then low
               else double.nan;
plot ArrowDN = if FastMA crosses below SlowMA
               then high
               else double.nan;
Alert(ArrowUp, " ", Alert.Bar, Sound.Chimes);
Alert(ArrowDN, " ", Alert.Bar, Sound.Bell);

AddCloud(FastMA, SlowMA, Color.GREEN, Color.RED);
# End Code


Active member
Is there no way to do it guys and gals? It seemed simple, but my error occurs in line 9 with average type. I tried adding 2 lines to distinct 2 different types and it still rejects the AdaptiveEMA


Well-known member
I do not think adaptive is a choice in ToS. You may need to just do 2 of the adaptive moving average studies and call one slow or fast. Just change your inputs.


Active member
It will work. Just tried it for fun.
MA and VWAP should be easy. Just put in the same study and add cloud.
Getting an error around line 42 with "input price = close"... Any idea how to fix this? I know the code is just chopped and pasted together, which my be part of my issue (sorry I am literally just learning to code the last 24 hours haha)
# VWAP MovingAvgCrossover Cloud

#Created by TradebyDay

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 price = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));

input price = close;

plot VWAP = price;

input length = 9;
input displace = 0;

assert(length > 0, "'length' must be positive: " + length);

def EMA = compoundValue(1, EMA[1] + 2 / (length + 1) * (price[-displace] - EMA[1]), price[-displace]);

plot LegacyEMA = EMA;
AddCloud(LegacyEMA, VWAP, Color.GREEN, Color.RED);
# End Code


Active member
When I did that the Moving Avg was based on the same time aggregation as the VWAP, so would have been a daily EMA, which though not a bad thing, was not what I was trying to accomplish personally. But for anyone curious, by deleting line 42 in post #7 you could apply VWAP on weekly, get a weekly moving average and probably have an interesting higher time frame indicator like daily or 4hr for those trading stocks and options


I am trying to creat alert in tos when legacy ema goes above vwap in 5 minute chart for specific stock ?
I am still trying different studies in different times
For different stocks
Thanks for help in advance


Staff member
Add the following line to the bottom of the study found above to give you an alert:
Alert(LegacyEMA crosses above VWAP, " ", Alert.Bar, Sound.Bell);
Last edited:


Staff member
It would seem from reading this thread that the study in message #9 is the one that works.
If you google "TOS open shared item" you should find how to load it into your charts.
If you google "TOS watchlist video" you will find over a million results with the steps to set it up as a 5min watchlist.

Similar threads