Moving Average and TrendPeriods Setups For ThinkOrSwim

Mocnarf1

Member
Check this out. It's simple and straight forward. I use a 15 minute candle.
Let me know how it compares with other strategies:

Code:
####### My Buy Alert Study #######
     #### MyBuyAlert() is true;   ####
plot condition =
(MovingAvgCrossover("length1" = 21, "length2" = 42, "crossing type" = "below") is true
and TrendPeriods() is true
and open < SimpleMovingAvg("length" = 9)."SMA"[0]
and open > SimpleMovingAvg("length" = 200)."SMA"[0])
or
MovingAvgCrossover("length1" = 9, "length2" = 200, "crossing type" = "above") is true
;

######## My Sell Alert Study #########
   #### MySellAlert() is true;  ####
plot condition =
(MovingAvgCrossover("length1" = 21, "length2" = 42,"crossing type" = "Above") is true
and  open > SimpleMovingAvg("length" = 9)."SMA"[0])
or
MovingAvgCrossover("length1" = 9, "length2" = 200,"crossing type" = "below") is true
;


#########################################

######## MyBuySellAlert Strategy ##########

def buy =
(MovingAvgCrossover("length1" = 21, "length2" = 42, "crossing type" = "below") is true
and TrendPeriods() is true
and open < SimpleMovingAvg("length" = 9)."SMA"[0]
and open > SimpleMovingAvg("length" = 200)."SMA"[0])
or
MovingAvgCrossover("length1" = 9, "length2" = 200, "crossing type" = "above") is true
;

def sell =
(MovingAvgCrossover("length1" = 21, "length2" = 42,"crossing type" = "Above") is true
and  open > SimpleMovingAvg("length" = 9)."SMA"[0])
or
MovingAvgCrossover("length1" = 9, "length2" = 200,"crossing type" = "below") is true
;

def buysignal = buy;
def sellsignal = sell;
AddOrder(OrderType.BUY_TO_OPEN, buysignal, name = "Buy", tickcolor = Color.DARK_RED, arrowcolor = Color.RED);
AddOrder(OrderType.SELL_TO_CLOSE, sellsignal, name = "Sell", tickcolor = Color.GREEN, arrowcolor = Color.GREEN);
 
Last edited by a moderator:
Hello, it is giving me error when I copy past. Can you share TOS link?
add only the following code (Note -- as a "strategy". not as a "study")

######## MyBuySellAlert Strategy ##########

def buy =
(MovingAvgCrossover("length1" = 21, "length2" = 42, "crossing type" = "below") is true
and TrendPeriods() is true
and open < SimpleMovingAvg("length" = 9)."SMA"[0]
and open > SimpleMovingAvg("length" = 200)."SMA"[0])
or
MovingAvgCrossover("length1" = 9, "length2" = 200, "crossing type" = "above") is true
;

def sell =
(MovingAvgCrossover("length1" = 21, "length2" = 42,"crossing type" = "Above") is true
and open > SimpleMovingAvg("length" = 9)."SMA"[0])
or
MovingAvgCrossover("length1" = 9, "length2" = 200,"crossing type" = "below") is true
;

def buysignal = buy;
def sellsignal = sell;
AddOrder(OrderType.BUY_TO_OPEN, buysignal, name = "Buy", tickcolor = Color.DARK_RED, arrowcolor = Color.RED);
AddOrder(OrderType.SELL_TO_CLOSE, sellsignal, name = "Sell", tickcolor = Color.GREEN, arrowcolor = Color.GREEN);
 
Here's a TrendPeriod Strategy it creates Buy and Sell signals when the TrendPeriod changes from positive to negative SELL and from negative to positive BUY. What I am am hoping to do is to find a way to reduce the number of unprofitable Buy-Sell pairs. I know to eliminate ALL unprofitable Buy_Sell pairs is a fool's errand. But I would like to reduce them if possible. The Buy and Sell sections of this study can easily be copy and a separate Buy and Sell study can be created. Which I use in a Study based Sequential Conditional Order.
Any suggestions?

Code:
def buy = 
TrendPeriods("fast length" = 21, "slow length" = 42) < 0 
and TrendPeriods("fast length" = 21, "slow length" = 42) [1] > 0
;

def sell =
TrendPeriods("fast length" = 21, "slow length" = 42) > 0 
and TrendPeriods("fast length" = 21, "slow length" = 42) [1] < 0
;

def buysignal = buy;
def sellsignal = sell;
AddOrder(OrderType.BUY_TO_OPEN, buysignal, name = "Buy", tickcolor = Color.DARK_RED, arrowcolor = Color.RED);
AddOrder(OrderType.SELL_TO_CLOSE, sellsignal, name = "Sell", tickcolor = Color.GREEN, arrowcolor = Color.GREEN);

I use Red color to denote money going Out of my Account (Buy)
and Green color to denote money coming INTO my Account (Sell)
I know it's a little bass-ackwords. But it works for me.
 
MerryDay suggested using multiple tests in a strategy to increase the profitability of the strategy. So I modified MyBuySell_Trend_Strategy here's the TOS shared screen link. What else might I do to improve this strategy. Remember I want to use the Study versions of this strategy to build Sequential Conditional Orders. Each Order Set will contain 3 Buy/Sell round trips. I want to build Studies and Strategy that I can place a SCO and let it run while I do other stuff. I have my system set to send me notifications for Buy/Sell activity to my cell phone. That way I can keep tabs on what is going on without having to be in front of my computer. Any way that's my goal.

Here's the link: http://tos.mx/kSjWzgb
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
472 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