Distance between crossover and 200 EMA

mosdef213

New member
I found that a crossover of the 13 EMA and 21 EMA that occurs very near or at the 200 EMA produces very nice results for trend trading. Can anyone code a script for a watchlist that can identify when this crossover occurs and is say less than 1% away from the 200 EMA? Thanks so much for your help!
 
you didn't specify if it crosses up or crosses down and which one crosses which.
@XeoNoX Just spit-balling but it would be a rare occurrence for the longer MA to cross the faster MA so I'd assume that @mosdef213 wants to know when the 13 crosses the 21 within 1% of the 200 - most likely in both directions... Sounds like an impending squeeze/convergence to me...
 
@XeoNoX Just spit-balling but it would be a rare occurrence for the longer MA to cross the faster MA so I'd assume that @mosdef213 wants to know when the 13 crosses the 21 within 1% of the 200 - most likely in both directions... Sounds like an impending squeeze/convergence to me...
What you stated @rad14733 is exactly right. I’m looking for a way to identify the 13 ema crossing the 21 ema up or down, and when that cross takes place less than 1% away from the 200 ema. If I could identify when this happens through a watch list, it would be really helpful. These instances can really make for high quality set ups.
 
The way the code works is:

the 13 and 21 will Always be crossed up or down, so that cancels that out and is now irrelevant
that leaves you with 1% away from 200ema
% away from MA code can be found on here somewhere
 
This is the script I came up with for the watchlist after piecing things together from this site. I changed the fast EMA from 13 to 8, so the alerts are more responsive, but users can change their settings. They can also modify the distance the cross takes place from the 200 EMA by changing the "s" value. My goal is to use this to scalp options. I'm doing some stress testing on this today, but so far, it looks promising.

Code:
input lookback = 50;
input ema1_len = 8;
input ema2_len = 21;
input averageType = AverageType.EXPONENTIAL;

def ema1 = MovAvgExponential(length=ema1_len);
def ema2 = MovAvgExponential(length=ema2_len);

def bull_cross = ema1 crosses above ema2;
def bear_cross = ema1 crosses below ema2;

def bull_lookback = highest(bull_cross, lookback);
def bear_lookback = highest(bear_cross, lookback);

def ma = MovAvgExponential(close,200);
def s = ma*0.003;

plot signal = if bull_lookback then 2 else if bear_lookback then 1 else 0;
signal.AssignValueColor(if signal == 2 then Color.Black else if signal == 1 then Color.Black else Color.BLACK);
AssignBackgroundCOlor(if signal == 2 then Color.Black else if signal == 1 then Color.Black else Color.BLACK);

def myvariable = absvalue(close - ma) is less than or equal to s;
AssignBackgroundColor(if myvariable and bull_cross or myvariable and bear_cross then Color.RED else Color.Black);
 
How do you define bull/bear scan? I entered it as a custom study in the scanner, but I think it's doing both bull and bear. I entered it as a study and then selected the study in the scanner, and now it appears I still can't define it as bull or bear, and on the right side maybe I have to pick 'signal line' crosses above 200 ema, but that didn't bring back anything. I would think there could be a drop down in the scanner where you select bull or bear. thoughts?
 

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