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
 
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
 
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.
 
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
 
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
 
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
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.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
307 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top