Moving Average Master Strategy for ThinkOrSwim

I agree. The 1st script in the 1st post is riddled with syntax errors.
The OP is no longer active on this forum, so he isn't available to provide a working version.
Maybe one of the other members of this thread will see your plight and offer a shared link to a working script.
Hi all!

Yes, I wasn't active, as I'm having health issues. I have completely rewritten the code and have been using it to actively trade. I'm always open to any suggestions anyone would have.

Dwain

Updated code and shared link in post one.
 

Attachments

  • MovingAverageMaster.jpg
    MovingAverageMaster.jpg
    180.9 KB · Views: 329

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Hi all!

Yes, I wasn't active, as I'm having health issues. I have completely rewritten the code and have been using it to actively trade. I'm always open to any suggestions anyone would have.

Dwain

Updated code and shared link in post one.
@dap711
Hope you are feeling better. Thanks for the update!

MEMBERS! This is a STRATEGY.
It needs to be cut & pasted into the STRATEGY tab (to the right of the study tab)
If you are having problems, here is a chart with the strategy already applied:
shared chart link: http://tos.mx/Yr8c5qV
WBAhUQO.png
 
Last edited:
Hi all!

Yes, I wasn't active, as I'm having health issues. I have completely rewritten the code and have been using it to actively trade. I'm always open to any suggestions anyone would have.

Dwain

Updated code and shared link in post one.

@dap711
Hope you are feeling better. Thanks for the update!

MEMBERS! This is a STRATEGY.
It needs to be cut & pasted into the STRATEGY tab (to the right of the study tab)
If you are having problems, here is a chart with the strategy already applied:
shared chart link: http://tos.mx/Yr8c5qV
WBAhUQO.png

I like my screenshot better .. LOL
 

Attachments

  • MovingAverageMaster.jpg
    MovingAverageMaster.jpg
    180.9 KB · Views: 233
I like my screenshot better .. LOL
So so sorry... I was in the middle of another analysis when I pulled up your script.

Yes, your chart is more better!
Pros: Moving averages work awesome on trending stocks in trending markets.
Cons: as seen when you compare @dap711 charts to mine. All other stocks will whipsaw and/ or post losses.
 
So so sorry... I was in the middle of another analysis when I pulled up your script.

Yes, your chart is more better!
Pros: Moving averages work awesome on trending stocks in trending markets.
Cons: as seen when you compare @dap711 charts to mine. All other stocks will whipsaw and/ or post losses.

Totally agree with you .. This strategy is best used with the more active stocks.
Right now TSLA and NVDA are the best trending stocks. My screenshot was TSLA, I'll attach one for NVDA.

Here is a link that will help you pick a stock to trade .. Trending Stocks
 

Attachments

  • NVDA.jpg
    NVDA.jpg
    293.3 KB · Views: 236
Last edited:
I converted the Moving Average Stategy into a study for use in the AGAIG chart setups:

Ruby:
# Author - Dwain Pattillo 2022

#1. Set the Trend MA type, price, and length. We only take buys if price is above the trend line and sells below it.
#2. Adjust the MA length to achieve the best profit from the floating P/L.
#3. Adjust the MA displacement for the highest profit.
#4. Repeat steps 2 and 3 until you are satisfied with the results. Now you see where this is going! LOL
#5. Share you insights for the best time frames and settings to help everyone make some money!


input BackTestTradeSize = 1;
input ShowBackTestPositions = yes;
input TrendAvgType = AverageType.EXPONENTIAL;
input TrendPrice = CLOSE;
input TrendLength = 200;
input UseVolumeAsFilter = yes;
input VolumeLength = 200;
input MAType = AverageType.HULL;
input MAPrice = Open;
input MALength = 2.1;
input MADisplace = 1;
input AlertOnSignal = no;
input ShowAutoKeyLabels = yes; #(I use Macro Recorder to auto trade. Ask me about the setup at [email protected])

#Average the volume and only open trades when volume is higher than the average.
def VolStrength = lg(volume[1]) - lg(SimpleMovingAvg(volume[1], VolumeLength));

#MA Magic goes here
def Diff = MovingAverage(MAType, MAPrice, MALength*100) -  MovingAverage(MAType, MAPrice, MALength*100)[MADisplace];

#Trendline
plot MA = MovingAverage(TrendAvgType, TrendPrice, TrendLength);
MA.DefineColor("Up", GetColor(1));
MA.DefineColor("Down", GetColor(0));
MA.AssignValueColor(if MA > MA[1] then MA.color("Up") else MA.color("Down"));

#Add the signal labels (use with Macro Recorder or not)
def OpenOrders = GetQuantity();
AddLabel(ShowAutoKeyLabels and diff[1] > diff[2] and low > MA and OpenOrders < 1 and (if UseVolumeAsFilter then VolStrength>0 else yes),  "     BUY      ", CreateColor(153, 255, 153));
AddLabel(ShowAutoKeyLabels and ( diff[1] < diff[2] or close < MA ) and OpenOrders > 0, "     CLOSE     ", CreateColor(102, 0, 0));
AddLabel(ShowAutoKeyLabels and diff[1] < diff[2] and high < MA and OpenOrders > -1 and (if UseVolumeAsFilter then VolStrength>0 else yes), "     SELL     ", CreateColor(255, 102, 102));
AddLabel(ShowAutoKeyLabels and ( diff[1] > diff[2] or close > MA ) and OpenOrders < 0 , "     CLOSE     ", CreateColor(102, 0, 0));

#Sound the bell. (If alerts are turn on)
Alert(diff[1] > diff[2] and low > MA and OpenOrders < 1 and AlertOnSignal, "Buy Open Signal", Alert.Bar, Sound.Ding);
Alert( ( diff[1] < diff[2] or close < MA ) and OpenOrders > 0 and AlertOnSignal, "Buy Close Signal", Alert.Bar, Sound.Bell);
Alert(diff[1] < diff[2] and high < MA and OpenOrders > -1 and AlertOnSignal, "Sell Open Signal", Alert.Bar, Sound.Ding);
Alert( ( diff[1] > diff[2] or close > MA ) and OpenOrders < 0 and AlertOnSignal, "Sell Close Signal", Alert.Bar, Sound.Bell);

AddLabel(UseVolumeAsFilter, if VolStrength > 0 then "   Trading allowed. Volume Strength: " + (VolStrength) + "  "  else "   Trading isn't allowed - Volume Strength: " + (VolStrength) + "  " , if (VolStrength < 0) then Color.RED else Color.Red);
 
Last edited by a moderator:

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
227 Online
Create Post

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