Why ExpAverage() work but MovingAverage() doesn't on the tick chart?

oldyoungguy

New member
VIP
On the tick chart, I am trying to get EMA crossing points. I found

def baseTF_mve9 = ExpAverage(priceType[-displace], emaLen9);

works properly but

def baseTF_mve9 = MovingAverage(averageType, close(period = baseTF), emaLen9);

doesn't work.

Why? There is no MTF.

The entire test code is here:

Code:
##################################################################
# On tick chart:
# It works if ExpAverage(priceType[-displace], emaLen9) is used. Arrows show.
# It doesn't work if MovingAverage(averageType, close(period = baseTF), emaLen9) is used. Nothing show up.
##################################################################

def emaLen9 = 9;
def emaLen3= 3;
def priceType = close;
def averageType = AverageType.EXPONENTIAL;
def averageTypeSMA = AverageType.SIMPLE;
def baseTF = GetAggregationPeriod();
input displace = 0;


#def baseTF_mve9 = ExpAverage(priceType[-displace], emaLen9);#works, arrows are showing
#def baseTF_mve3 = ExpAverage(priceType[-displace], emaLen3);#works, arrows are showing
def baseTF_mve9 = MovingAverage(averageType, close(period = baseTF), emaLen9);#doesn't work, no arrow showing
def baseTF_mve3 = MovingAverage(averageType, close(period = baseTF), emaLen3);#doesn't work, no arrow showing

def baseTF_isCrossAbove = baseTF_mve3 crosses above baseTF_mve9;
def baseTF_isCrossBelow = baseTF_mve3 crosses below baseTF_mve9;

def baseTFBuyCondition = baseTF_isCrossAbove;
def buyConditions = baseTFBuyCondition;
plot plotBuy = buyConditions;
plotBuy.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plotBuy.SetDefaultColor(Color.CYAN);

def baseTFSellCondition = baseTF_isCrossBelow;
def sellConditions = baseTFSellCondition;
plot plotSell = sellConditions;
plotSell.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
plotSell.SetDefaultColor(Color.YELLOW);
 
Solution
On the tick chart, I am trying to get EMA crossing points. I found

def baseTF_mve9 = ExpAverage(priceType[-displace], emaLen9);

works properly but

def baseTF_mve9 = MovingAverage(averageType, close(period = baseTF), emaLen9);

doesn't work.

Why? There is no MTF.

The entire test code is here:

Code:
##################################################################
# On tick chart:
# It works if ExpAverage(priceType[-displace], emaLen9) is used. Arrows show.
# It doesn't work if MovingAverage(averageType, close(period = baseTF), emaLen9) is used. Nothing show up.
##################################################################

def emaLen9 = 9;
def emaLen3= 3;
def priceType = close;
def averageType =...
On the tick chart, I am trying to get EMA crossing points. I found

def baseTF_mve9 = ExpAverage(priceType[-displace], emaLen9);

works properly but

def baseTF_mve9 = MovingAverage(averageType, close(period = baseTF), emaLen9);

doesn't work.

Why? There is no MTF.

The entire test code is here:

Code:
##################################################################
# On tick chart:
# It works if ExpAverage(priceType[-displace], emaLen9) is used. Arrows show.
# It doesn't work if MovingAverage(averageType, close(period = baseTF), emaLen9) is used. Nothing show up.
##################################################################

def emaLen9 = 9;
def emaLen3= 3;
def priceType = close;
def averageType = AverageType.EXPONENTIAL;
def averageTypeSMA = AverageType.SIMPLE;
def baseTF = GetAggregationPeriod();
input displace = 0;


#def baseTF_mve9 = ExpAverage(priceType[-displace], emaLen9);#works, arrows are showing
#def baseTF_mve3 = ExpAverage(priceType[-displace], emaLen3);#works, arrows are showing
def baseTF_mve9 = MovingAverage(averageType, close(period = baseTF), emaLen9);#doesn't work, no arrow showing
def baseTF_mve3 = MovingAverage(averageType, close(period = baseTF), emaLen3);#doesn't work, no arrow showing

def baseTF_isCrossAbove = baseTF_mve3 crosses above baseTF_mve9;
def baseTF_isCrossBelow = baseTF_mve3 crosses below baseTF_mve9;

def baseTFBuyCondition = baseTF_isCrossAbove;
def buyConditions = baseTFBuyCondition;
plot plotBuy = buyConditions;
plotBuy.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plotBuy.SetDefaultColor(Color.CYAN);

def baseTFSellCondition = baseTF_isCrossBelow;
def sellConditions = baseTFSellCondition;
plot plotSell = sellConditions;
plotSell.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
plotSell.SetDefaultColor(Color.YELLOW);
I would guess it doesn't like the syntax you are using. You are still using a time period even if you are trying to grab the current one. Try removing that part like so:
def baseTF_mve9 = MovingAverage(averageType, close, emaLen9);
 
Solution

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