Distance between crossover and 200 EMA

mosdef213

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

rad14733

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

mosdef213

New member
VIP
@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.
 

XeoNoX

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

mosdef213

New member
VIP
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);
 

tome10

Member
VIP
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?
 

Similar threads

Top