Adding AdaptiveEMA to this MovAvg Cloud indicator?

tradebyday

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!
Code:
# 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);
FastMA.SetDefaultColor(GetColor(1));
SlowMA.SetDefaultColor(GetColor(2));

plot ArrowUp = if FastMA crosses above SlowMA
               then low
               else double.nan;
     ArrowUP.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
     ArrowUP.SetLineWeight(3);
     ArrowUP.SetDefaultColor(Color.Green);
plot ArrowDN = if FastMA crosses below SlowMA
               then high
               else double.nan;
     ArrowDN.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
     ArrowDN.SetLineWeight(3);
     ArrowDN.SetDefaultColor(Color.Red);
Alert(ArrowUp, " ", Alert.Bar, Sound.Chimes);
Alert(ArrowDN, " ", Alert.Bar, Sound.Bell);

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

tradebyday

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
 

horserider

Well-known member
VIP
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.
 

tradebyday

Active 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.
Alright I'll give that a shot. Any way to create the cloud between a moving average and VWAP?
 

horserider

Well-known member
VIP
It will work. Just tried it for fun.
MA and VWAP should be easy. Just put in the same study and add cloud.
 

tradebyday

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)
Code:
# 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;
VWAP.setDefaultColor(getColor(0));
LegacyEMA.SetDefaultColor(GetColor(1));
AddCloud(LegacyEMA, VWAP, Color.GREEN, Color.RED);
# End Code
 

horserider

Well-known member
VIP
Could have just deleted second price = close and used close in the second price spot. Anyway glad you got those working as you wished. Congrats.
 

tradebyday

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
 

Drmoh1800

New member
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
 

MerryDay

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

Drmoh1800

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


thank you
how to set it for 5 minutes chart
when you say above chart which one you mean ?
i am sorry i am new with writing script
 

MerryDay

Well-known member
VIP
@Drmoh1800
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

Top