Smoothed Moving Average Crossover scan (TOS)


Category:
0
0

Hi Mr. Hahn, thank you for all that you do. I have a request for  Smooth Moving Average(SMMA) (https://mahifx.com/mfxtrade/indicators/smoothed-moving-average-smma)  crossover scan. I would like to scan for stock with smma crossovers were it show only stocks with only  6  candle sticks above or below the crossover.  SMA please.

Marked as spam
Posted by (Questions: 5, Answers: 7)
Asked on March 19, 2017 12:25 am
2936 views
0

I need to clarify a few things before proceeding with the solution. You did not mention the length of the SMMA you want to use. Unless specified, I will use a length of 21. You are asking for a ”crossover scan”. A crossover scan is typically constructed using 2 moving averages. But you don’t give a length for the slow and fast moving averages. It is possible that when you ask for a crossover scan you are actually talking about the price crossing over the SMMA. You will need to explain this so we can proceed. The last bit of details we lack is how you define ”6 candles sticks above or below the crossover”. Perhaps after you answer the previous points, this one will become obvious.

( at March 19, 2017 11:20 am)
0

Sorry my mind is like the matrix so my stock lingo is off.
I would like to scan for smma(close, 8) crossed above smma(close, 4). I want the scan not to pick up the stocks right at the crossover, but maybe 3 bars or candles after the cross.

I hope this make sense and I apologize for the confusion.

( at March 19, 2017 9:59 pm)
0

Perfect explanation. You have provided the details needed to proceed. I will respond in the morning. Thank you.

( at March 19, 2017 10:24 pm)
0
Private answer

Wow, spent way to much time on this. This one really took me down a rabbit hole. Almost didn’t make it back out.

So I found that TradingView has this SMMA as a built in study. I’ve worked with that code before and it was super easy to port that over to Thinkorswim. Only problem, the charts didn’t match. Even after I updated the code to match the formula found in the link you provided, no match. I was about to throw in the towel and decided to do a quick Google search and found this: https://futures.io/ninjatrader-programming/8358-smoothed-moving-average-smma-how-avoid.html

It basically describes someone else trying to get this thing working on the NinjaTrader platform. Eventually they decide this SMMA is only good for the garbage bin (their words, not mine). In this post they describe one version was very close to an exponential moving average. Well that got me thinking.

So I ran through all the different types of moving averages available on Thinkorswim. When I got to the Wilders Smoothing I found an exact match for the SMMA on TradingView.com. I have no idea if this matches the SMMA on other platforms. But from that post on futures.io I gather this SMMA varies from platform to platform. If it does, stay away. Far, far away.

Before presenting the code I will mention that in your clarification you stated you wanted to scan for the 8 SMMA crossing above the 4 SMMA. When defining moving average crossovers the industry standard lexicon is to always define the shorter moving average crossing the longer moving average. In the code provided here, I define a crossAbove as being when the 4 period moving average crosses above the 8 period moving average.

So, here is my solution to your question, using Wilders Smoothing in place of the failed code for the SMMA:

#
# TD Ameritrade IP Company, Inc. (c) 2008-2017
#
input price = close;
input length1 = 4;
input length2 = 8;
input barsAfterCross = 3;
def ws1 = WildersAverage(price, length1);
def ws2 = WildersAverage(price, length2);
def crossAbove = ws1[1] < ws2[1] and ws1 > ws2;
def crossBelow = ws1[1] > ws2[1] and ws1 < ws2; # use this to scan for ws1 crossing above ws2 plot scan = crossAbove[barsAfterCross - 1] and ws1 > ws2;
# use this to scan for ws1 crossing below ws2
#plot scan = crossBelow[barsAfterCross - 1] and ws1 < ws2;

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on March 20, 2017 9:56 am
0

Sorry for the late reply to your code message. I found out my wife was having a baby(excitement) and my mind went numb for weeks and dang near lost everything LOL. THANK You so much for your time in working on this. Now that I am somewhat coherent again , I will start testing this.

( at April 15, 2017 4:32 pm)
0

Well congratulations!

( at April 15, 2017 5:08 pm)