Crossover Scan Results

I hope everyone is having an amazing day. I have been trying to make a scan identify when the displacedEMA is greater than the VariableMA, on the 15min, EXT turned on. I already tried saving it as a study and then plugging it into the scan but it didn't work. It sounds so simple but when I tried to code it into the scan I keep getting no results back and cant figure out why. I will leave the 3 different codes I have been putting in the scan down below. I would greatly appreciate any help given.

-------------------Test 1--------------------
DisplacedEMA("length" = 20, "displace length" = -15) is greater than VariableMA("length" = 15)

------------------Test 2--------------------
#DISPLACEDEMA
input price = close;
input length = 20;
input DisplaceLength = -15;

def DisplacedEMA = ExpAverage(data = price[DisplaceLength], length = length);

#VMA
input vprice = close;
input vlength = 15;

def tmp1 = if vprice > vprice[1] then vprice - vprice[1] else 0;
def tmp2 = if vprice[1] > vprice then vprice[1] - vprice else 0;
def d2 = sum(tmp1, vlength);
def d4 = sum(tmp2, vlength);
def cond = d2 + d4 == 0;
def ad3 = if cond then 0 else (d2 - d4) / (d2 + d4) * 100;
def coeff = 2 / (vlength + 1) * AbsValue(ad3) / 100;
def asd = compoundValue("visible data" = coeff * vprice + (if IsNaN(asd[1]) then 0 else asd[1]) * (1 - coeff), "historical data" = vprice
);
def VMA = asd;

plot scan = DisplacedEMA is greater than VMA;

-------------------Test 3--------------------
CrossoverSTRAT() is true within 2 bars

I basically made the 2 codes above custom studies, and offset them 2 bars and still got no results back
Scan Photos

This is what I want the scanner to tell me. In this case when the displacedEMA (blue line) is greater than VariableEMA(purple line) add "AAPL" to the scan results
FTmevuk.png
 
Last edited:
Solution
@JeffryBatista So, this is what I have. Hopefully I have all this right.

The whole problem revolves around using the -15 value in the DisplacedEMA(). That input uses future data (in this case, 15 bars of it) that has not yet passed in time. Why is this important? Since the 15 bars of price data do not yet exist, there is no way that the scanner can find them. Trying to scan for these crossovers is the same as trying to scan for other studies that use future data such as the built-in TTM_ScalperAlert study, which uses 3 bars of future data (and always shows those perfect and untradeable arrows 3 or so bars after price has already passed that point). Even if the scanner would be able to find these crossovers, they would first show...
@JeffryBatista So, this is what I have. Hopefully I have all this right.

The whole problem revolves around using the -15 value in the DisplacedEMA(). That input uses future data (in this case, 15 bars of it) that has not yet passed in time. Why is this important? Since the 15 bars of price data do not yet exist, there is no way that the scanner can find them. Trying to scan for these crossovers is the same as trying to scan for other studies that use future data such as the built-in TTM_ScalperAlert study, which uses 3 bars of future data (and always shows those perfect and untradeable arrows 3 or so bars after price has already passed that point). Even if the scanner would be able to find these crossovers, they would first show on the scanner 15 price bars after the point of the crossover. If you watch the two moving averages on a chart during market hours, they will first cross 15 bars after their intersection point. By placing the DisplacedEMA() and a MovAvgExponential() on a chart with the same length settings, you can easily verify for yourself that the DisplacedEMA() study is delayed in plotting by 15 bars.

All that being said, the easiest way to scan for these crosses would be to offset both studies 15 bars forward (this eliminates the use of future data yet keeps the relationship of the two averages the same) and then scan for a crossover. I know that this is certainly not what you wanted; however, its the best that I have.
Since a DisplacedEMA() is simply a EMA offset back a certain number of bars, it can be changed to a regular EMA. Your scan would look like this: ExpAverage(20) > VariableMA(15)[15].

In this screenshot, the cyan arrow points to the crossover and the magenta arrow points to where price is trading at the time of the crossover. The orange arrow points to the spot where the two adjusted averages cross. You can see that scanning for either method should provide the same results.
example.png


If you can disprove my conclusion, I'll be glad to know it. Try this and see how it goes for you.
 
Solution
@JeffryBatista So, this is what I have. Hopefully I have all this right.

The whole problem revolves around using the -15 value in the DisplacedEMA(). That input uses future data (in this case, 15 bars of it) that has not yet passed in time. Why is this important? Since the 15 bars of price data do not yet exist, there is no way that the scanner can find them. Trying to scan for these crossovers is the same as trying to scan for other studies that use future data such as the built-in TTM_ScalperAlert study, which uses 3 bars of future data (and always shows those perfect and untradeable arrows 3 or so bars after price has already passed that point). Even if the scanner would be able to find these crossovers, they would first show on the scanner 15 price bars after the point of the crossover. If you watch the two moving averages on a chart during market hours, they will first cross 15 bars after their intersection point. By placing the DisplacedEMA() and a MovAvgExponential() on a chart with the same length settings, you can easily verify for yourself that the DisplacedEMA() study is delayed in plotting by 15 bars.

All that being said, the easiest way to scan for these crosses would be to offset both studies 15 bars forward (this eliminates the use of future data yet keeps the relationship of the two averages the same) and then scan for a crossover. I know that this is certainly not what you wanted; however, its the best that I have.
Since a DisplacedEMA() is simply a EMA offset back a certain number of bars, it can be changed to a regular EMA. Your scan would look like this: ExpAverage(20) > VariableMA(15)[15].

In this screenshot, the cyan arrow points to the crossover and the magenta arrow points to where price is trading at the time of the crossover. The orange arrow points to the spot where the two adjusted averages cross. You can see that scanning for either method should provide the same results.
example.png


If you can disprove my conclusion, I'll be glad to know it. Try this and see how it goes for you.
Very very interesting. Im defiantly going to try this out right now. whether it works or not I just want to thank you for all the time you have put into this. I know finding this solution must have taken a lot of thought and so I appreciate you so much for that @Pensar
 

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