Parallel EMAs

CodeBee

New member
Is there a way to scan for a stock which has parellel EMAs. The EMAs could be 9, 21, 50. When these three EMAs are parellel to each other for some time then there is going to high parabolic move going to happen. This is similar to consolidation in price action.
 
Solution
I'm not sure how exactly parallel you are interested in scanning for. Adding a 'fudge factor' is a bit more involved, but for exactly matching slopes, it can be done this way:
Code:
input L1 = 9;
input L2 = 21;
input L3 =  50;
input lookback = 1;

def SMA1 = SimpleMovingAvg(price = CLOSE, length = L1);
def SMA2 = SimpleMovingAvg(price = CLOSE, length = L2);
def SMA3 = SimpleMovingAvg(price = CLOSE, length = L3);

def delta1 = SMA1 - SMA1[lookback];
def delta2 = SMA2 - SMA2[lookback];
def delta3 = SMA3 - SMA3[lookback];

plot eureka = if delta1 == delta2 and delta1 == delta3 then 1 else double.nan;
This code lets you specify the lengths for the three averages in bars, as well as the lookback -- the two bars to look at for difference calculation. It...
I'm not sure how exactly parallel you are interested in scanning for. Adding a 'fudge factor' is a bit more involved, but for exactly matching slopes, it can be done this way:
Code:
input L1 = 9;
input L2 = 21;
input L3 =  50;
input lookback = 1;

def SMA1 = SimpleMovingAvg(price = CLOSE, length = L1);
def SMA2 = SimpleMovingAvg(price = CLOSE, length = L2);
def SMA3 = SimpleMovingAvg(price = CLOSE, length = L3);

def delta1 = SMA1 - SMA1[lookback];
def delta2 = SMA2 - SMA2[lookback];
def delta3 = SMA3 - SMA3[lookback];

plot eureka = if delta1 == delta2 and delta1 == delta3 then 1 else double.nan;
This code lets you specify the lengths for the three averages in bars, as well as the lookback -- the two bars to look at for difference calculation. It defaults to 1 bar (looking at the two most recent bars). If the differences between the SMA for this bar and the last bar are equal for all three moving averages, the lines are parallel.

perhaps that's what you meant, perhaps not.

to do something with a fudge factor, you would need to do something like this:
Code:
input fudge_factor = 0.02; # this is in cents -- adjust as needed for your instrument e.g. 0.00002 for /6E etc...
plot eureka = if (delta1 <= (delta2 + fudge_factor)) or (delta1 >= (delta2 - fudge_factor)) and (delta1 <= (delta3 + fudge_factor)) or (delta1 >= (delta3 - fudge_factor)) then 1 else double.nan;
... I think. I'm just writing code in the text editor, not ThinkOrSwim.

-mashume
 
Solution
I'm not sure how exactly parallel you are interested in scanning for. Adding a 'fudge factor' is a bit more involved, but for exactly matching slopes, it can be done this way:
Code:
input L1 = 9;
input L2 = 21;
input L3 =  50;
input lookback = 1;

def SMA1 = SimpleMovingAvg(price = CLOSE, length = L1);
def SMA2 = SimpleMovingAvg(price = CLOSE, length = L2);
def SMA3 = SimpleMovingAvg(price = CLOSE, length = L3);

def delta1 = SMA1 - SMA1[lookback];
def delta2 = SMA2 - SMA2[lookback];
def delta3 = SMA3 - SMA3[lookback];

plot eureka = if delta1 == delta2 and delta1 == delta3 then 1 else double.nan;
This code lets you specify the lengths for the three averages in bars, as well as the lookback -- the two bars to look at for difference calculation. It defaults to 1 bar (looking at the two most recent bars). If the differences between the SMA for this bar and the last bar are equal for all three moving averages, the lines are parallel.

perhaps that's what you meant, perhaps not.

to do something with a fudge factor, you would need to do something like this:
Code:
input fudge_factor = 0.02; # this is in cents -- adjust as needed for your instrument e.g. 0.00002 for /6E etc...
plot eureka = if (delta1 <= (delta2 + fudge_factor)) or (delta1 >= (delta2 - fudge_factor)) and (delta1 <= (delta3 + fudge_factor)) or (delta1 >= (delta3 - fudge_factor)) then 1 else double.nan;
... I think. I'm just writing code in the text editor, not ThinkOrSwim.

-mashume
Thank you This works for me. Can you help me change this for EMAs? instead of SMAs? Also is there a way to scan for this breakout of this EMA parellal? Thanks in advance.
 
Thank you This works for me. Can you help me change this for EMAs? instead of SMAs? Also is there a way to scan for this breakout of this EMA parellal? Thanks in advance.
everywhere you see:
SimpleMovingAvg
change it to
MovAvgExponential
and it'lll be EMAs.

and it is set up as a scan. the plot returns 1 or NaN. just put the code in a custom scanner (directions around here somewhere), set your timeframe, and go. Be aware that this does not tell you whether the moving averages are trending up or down, just that they are in parallel.

-mashume
 
everywhere you see:
SimpleMovingAvg
change it to
MovAvgExponential
and it'lll be EMAs.

and it is set up as a scan. the plot returns 1 or NaN. just put the code in a custom scanner (directions around here somewhere), set your timeframe, and go. Be aware that this does not tell you whether the moving averages are trending up or down, just that they are in parallel.

-mashume
 

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