Real Motion For ThinkOrSwim

samport

New member
I have recently visited the Market Gauge website to gain some really good insight into the overall market structure. I took interest in their Real Motion indicator as a way to use momentum of price and compare it to price. They provide several formulas and a nice description of how the indicator is supposed to function. I then decided to code my own version of this indicator and see if I could replicate the results. Please take a look at the code submitted and let me know what you think. The only challenge I am facing is applying the standard deviation to the fast average (blue line). It is supposed to be set at 1 SD while the upper chart uses a 20 period 2 SD bollinger band. In order to get it to match the most current RealMotion of SPY, I have it set at 50 length with 2 SD. Other than that, I think it is nearly spot on. Enjoy!


Code:
# RealMotion indicator based off of description from Market Gauge website.
#//RealMotion indicator as explained by Market Gauge
#//"The brown dots are a dot plot of the individual values of the RealMotion variable.
#//Essentially, they divide the equity price by the moving average of that price (here 200 period).
#//We then subtract one and multiply that value by 100.
#//This centers the indicator at zero (when price = moving average then RealMotion will equal zero).
#//Furthermore, by multiplying by 100 we make it so that when RealMotion = 5.0
#//we can say that the price is 5% greater than the reference moving average."
#PrimaryAveragePlot=Average[PrimaryAverage](close)
#RealMotion=(close/PrimaryAveragePlot - 1)*100

declare lower;

input lengthfast = 50;
input lengthslow = 200;
input averageType = AverageType. SIMPLE;

def pAVERAGE = movingaverage(averageType, close, lengthslow);
def rMOTION = (close / pAVERAGE -1) * 100;
def sAVG = movingaverage(averageType,rMOTION, lengthslow);
def fAVG = movingaverage(averageType,rMOTION, lengthfast);

plot RM = rMOTION;
plot AVGs = sAVG;
plot AVGf = fAVG;


plot zeroline = 0;
zeroline.setDefaultColor(color.white);

def price = rMOTION;
input displace = 0;
input length = 50;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;


def sDev = StDev(price, length);

plot MidLine = AVGf;
plot LowerBand = MidLine + num_Dev_Dn * sDev;
plot UpperBand = MidLine + num_Dev_Up * sDev;

LowerBand.SetDefaultColor(GetColor(0));
MidLine.SetDefaultColor(GetColor(1));
UpperBand.SetDefaultColor(GetColor(5));


GJD39XA.png


https://marketgauge.com/charts/bv/bv-chart22a-mktwx.jpg
 
Last edited:
I have recently visited the Market Gauge website to gain some really good insight into the overall market structure. I took interest in their Real Motion indicator as a way to use momentum of price and compare it to price. They provide several formulas and a nice description of how the indicator is supposed to function. I then decided to code my own version of this indicator and see if I could replicate the results. Please take a look at the code submitted and let me know what you think. The only challenge I am facing is applying the standard deviation to the fast average (blue line). It is supposed to be set at 1 SD while the upper chart uses a 20 period 2 SD bollinger band. In order to get it to match the most current RealMotion of SPY, I have it set at 50 length with 2 SD. Other than that, I think it is nearly spot on. Enjoy!


Code:
# RealMotion indicator based off of description from Market Gauge website.
#//RealMotion indicator as explained by Market Gauge
#//"The brown dots are a dot plot of the individual values of the RealMotion variable.
#//Essentially, they divide the equity price by the moving average of that price (here 200 period).
#//We then subtract one and multiply that value by 100.
#//This centers the indicator at zero (when price = moving average then RealMotion will equal zero).
#//Furthermore, by multiplying by 100 we make it so that when RealMotion = 5.0
#//we can say that the price is 5% greater than the reference moving average."
#PrimaryAveragePlot=Average[PrimaryAverage](close)
#RealMotion=(close/PrimaryAveragePlot - 1)*100

declare lower;

input lengthfast = 50;
input lengthslow = 200;
input averageType = AverageType. SIMPLE;

def pAVERAGE = movingaverage(averageType, close, lengthslow);
def rMOTION = (close / pAVERAGE -1) * 100;
def sAVG = movingaverage(averageType,rMOTION, lengthslow);
def fAVG = movingaverage(averageType,rMOTION, lengthfast);

plot RM = rMOTION;
plot AVGs = sAVG;
plot AVGf = fAVG;


plot zeroline = 0;
zeroline.setDefaultColor(color.white);

def price = rMOTION;
input displace = 0;
input length = 50;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;


def sDev = StDev(price, length);

plot MidLine = AVGf;
plot LowerBand = MidLine + num_Dev_Dn * sDev;
plot UpperBand = MidLine + num_Dev_Up * sDev;

LowerBand.SetDefaultColor(GetColor(0));
MidLine.SetDefaultColor(GetColor(1));
UpperBand.SetDefaultColor(GetColor(5));


GJD39XA.png


https://marketgauge.com/charts/bv/bv-chart22a-mktwx.jpg
I added this to one of my charts and I kept on looking over at it for confirmation. Great job thanks ! 👍
 
I have continued to follow this indicator and make adjustments. In the latest change, I reduced the MA to 10 SMA, 30 EMA with 200 SMA. I added the same moving averages to the upper chart also. Next, I wanted to see if I could create a simple code to capture the small divergences between the momentum and price action. For example, if price action saw the close above the 30 EMA and momentum was below the 30 EMA. Here is the code for this study and a screen shot of the SPX on the daily to serve as a visual. Please let me know what you think or how can it be improved even further.

#rMOTION Divergence spotter


declare upper;

#rMOTION code ////////////////////////////////////////////////////

input tenLINE = 10;
input lengthfast = 30;
input lengthslow = 200;
input averageTypeF = AverageType.EXPONENTIAL;
input averageTypeS = AverageType. SIMPLE;
input averageTypeT = AverageType. SIMPLE;

def pAVERAGE = MovingAverage(averageTypeS, close, lengthslow);
def rMOTION = (close / pAVERAGE - 1) * 100;
def sAVG = MovingAverage(averageTypeS, rMOTION, lengthslow);
def fAVG = MovingAverage(averageTypeF, rMOTION, lengthfast);
def tAVG = MovingAverage(averageTypeT, rMOTION, tenLINE);

def price = rMOTION;
input displace = 0;
input lengthBB = 30;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;

def sDev = StDev(price, lengthBB);
def RM = rMOTION;

#10/30 movingAverage code ////////////////////////////////////////////

input price2 = close;
#input paintBars = yes;
input fastaverageType = AverageType.EXPONENTIAL;
input slowaverageType = AverageType.WEIGHTED;
input fastLength = 9;
input slowLength = 30;

def fastAvg = MovingAverage(fastaverageType, price2, fastLength);
def slowAvg = MovingAverage(slowaverageType, price2, slowLength);

def diverUP = if close < slowAvg and RM > fAVG then low else double.NaN;
def diverDN = if close > slowAvg and RM < fAVG then high else Double.NaN;

plot LONG = diverUP;
plot SHORT = diverDN;


1AfsPV8.png
 
I have continued to follow this indicator and make adjustments. In the latest change, I reduced the MA to 10 SMA, 30 EMA with 200 SMA. I added the same moving averages to the upper chart also. Next, I wanted to see if I could create a simple code to capture the small divergences between the momentum and price action. For example, if price action saw the close above the 30 EMA and momentum was below the 30 EMA. Here is the code for this study and a screen shot of the SPX on the daily to serve as a visual. Please let me know what you think or how can it be improved even further.

#rMOTION Divergence spotter


declare upper;

#rMOTION code ////////////////////////////////////////////////////

input tenLINE = 10;
input lengthfast = 30;
input lengthslow = 200;
input averageTypeF = AverageType.EXPONENTIAL;
input averageTypeS = AverageType. SIMPLE;
input averageTypeT = AverageType. SIMPLE;

def pAVERAGE = MovingAverage(averageTypeS, close, lengthslow);
def rMOTION = (close / pAVERAGE - 1) * 100;
def sAVG = MovingAverage(averageTypeS, rMOTION, lengthslow);
def fAVG = MovingAverage(averageTypeF, rMOTION, lengthfast);
def tAVG = MovingAverage(averageTypeT, rMOTION, tenLINE);

def price = rMOTION;
input displace = 0;
input lengthBB = 30;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;

def sDev = StDev(price, lengthBB);
def RM = rMOTION;

#10/30 movingAverage code ////////////////////////////////////////////

input price2 = close;
#input paintBars = yes;
input fastaverageType = AverageType.EXPONENTIAL;
input slowaverageType = AverageType.WEIGHTED;
input fastLength = 9;
input slowLength = 30;

def fastAvg = MovingAverage(fastaverageType, price2, fastLength);
def slowAvg = MovingAverage(slowaverageType, price2, slowLength);

def diverUP = if close < slowAvg and RM > fAVG then low else double.NaN;
def diverDN = if close > slowAvg and RM < fAVG then high else Double.NaN;

plot LONG = diverUP;
plot SHORT = diverDN;


1AfsPV8.png
Could you pl share the lower study code- Thank you!
 

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