3-in-1 Simple or Exponential Moving Average for ThinkorSwim

if you mean the conditions in the addverticallines, change one condition to be x crosses above y ( or crosses below)
That is a solid Sir, Thank you for the help

input price = close;
input length1 = 5;
input length2 = 13;
input length3 = 50;
input length4 = 200;
input displace = 0;

plot A1 = ExpAverage(price[-displace], length1);
plot A2 = ExpAverage(price[-displace], length2);
plot A3 = ExpAverage(price[-displace], length3);
plot A4 = ExpAverage(price[-displace], length4);

AddVerticalLine (if
A1 crosses below A2 and a2<a3 and a3<a4
or
A1<A2 and a2 crosses below a3 and a3<a4
or
A1<A2 and a2<a3 and a3 crosses below a4
then 1 else 0, "--- Bearish Full ---", Color.White, Curve.LONG_DASH);

AddVerticalLine (if
A1 crosses above A2 and a2>a3 and a3>a4
or
A1>A2 and a2 crosses above a3 and a3>a4
or
A1>A2 and a2>a3 and a3 crosses above a4
then 1 else 0, "--- Bullish Full ---", Color.Black, Curve.LONG_DASH);

AddVerticalLine (if
A1 crosses below a4 and a2>a4 and a3>a4 and a3>a4
or
A1<a4 and a2 crosses above a4 and a3>a4 and a3>a4
or
A1<a4 and a2>a4 and a3 crosses above a4 and a3>a4
or
A1<a4 and a2>a4 and a3>a4 and a3 crosses above a4
then 1 else 0, "--- Bearish Reversal ---", Color.White, Curve.LONG_DASH);

AddVerticalLine (if
A1 crosses above A4 and a2<a4 and a3<a4 and a3<a4
or
A1>A4 and a2 crosses below a4 and a3<a4 and a3<a4
or
A1>A4 and a2<a4 and a3 crosses below a4 and a3<a4
or
A1>A4 and a2<a4 and a3<a4 and a3 crosses below a4
then 1 else 0, "--- Bullish Reversal ---", Color.Black, Curve.LONG_DASH);

Y6ACvDm.png
 
Last edited:

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

Here is a multi-moving averages indicator for ThinkorSwim so that you can easily add more than one simple or exponential moving averages without adding multiple indicators. Normally if you want to add a 5 and 10 SMA into your chart, you would need to include 2 different inputs and 2 copies of the same indicator. Now you don't have to. With this indicator, you can include 3 SMA or EMA into your chart in a single indicator.

The indicator is fully customizable and includes crossover signals (Bullish and Bearish) as well.

Jtqv3KK.png


thinkScript Code

Rich (BB code):
# E-Charts v2

declare upper;
input short_average = 5;
input medium_average = 10;
input long_average = 20;
input average_type = {default "SMA", "EMA"};
input show_vertical_line = no;
input show_bubble_labels = yes;

def MA1;
def MA2;
def MA3;
switch (average_type) {
case "SMA":
    MA1 = Average(close, short_average);
    MA2 = Average(close, medium_average);
    MA3 = Average(close, long_average);
case "EMA":
    MA1 = ExpAverage(close, short_average);
    MA2 = ExpAverage(close, medium_average);
    MA3 = ExpAverage(close, long_average);
}

# define e-signal and crossover point
def Eup = MA1 > MA2 && MA2 > MA3;
def Edn = MA1 < MA2 && MA2 < MA3;

def CrossUp = close > MA1 && Eup && !Eup[1];
def CrossDn = close < MA1 && Edn && !Edn[1];

# Define up and down signals
def higherHigh = close > Highest(max(open,close), 3)[1];
def lowerLow = close < Lowest(min(open,close), 3)[1];
def SignalUp = if (CrossUp && higherHigh)
    then 1
        else if    (CrossUp[1] && higherHigh && !higherHigh[1])
    then 1
        else if    (CrossUp[2] && higherHigh && !higherHigh[1] && !higherHigh[2])
    then 1
        else Double.NaN;
def SignalDn = if (CrossDn && lowerLow)
    then 1
        else if (CrossDn[1] && lowerLow && !lowerLow[1])
    then 1
        else if (CrossDn[2] && lowerLow && !lowerLow[1] && !lowerLow[2])
    then 1
        else Double.NaN;
      
# Plot the moving average lines
plot ln1 = MA1;
ln1.SetDefaultColor(CreateColor(145, 210, 144));
ln1.SetLineWeight(2);
plot ln2 = MA2;
ln2.SetDefaultColor(CreateColor(111, 183, 214));
ln2.SetLineWeight(2);
plot ln3 = MA3;
ln3.SetDefaultColor(CreateColor(249, 140, 182));
ln3.SetLineWeight(2);
  
# Draw vertical line to indicate call and put signals
AddVerticalLine(SignalUp && show_vertical_line, "Up", Color.UPTICK);
AddVerticalLine(SignalDn && show_vertical_line, "Down", Color.LIGHT_RED);

# Show Call / Put Signal in a Chart Bubble
AddChartBubble(SignalUp && show_bubble_labels, low - 0.3, "Up", Color.UPTICK, no);
AddChartBubble(SignalDn && show_bubble_labels, high + 0.3, "Dn", Color.LIGHT_RED);

# Add label for Eup or Edn
AddLabel(Eup, "E Up", Color.GREEN);
AddLabel(Edn, "E Dn", Color.RED);

Shareable Link

https://tos.mx/XxwhcP

All credit goes to Robert.
@BenTen Can some explain why the arrow is signaling a few bars after the crossover? can this be adjusted ?
 
@BenTen Can some explain why the arrow is signaling a few bars after the crossover? can this be adjusted ?
Because it is not just looking for the cross. It is looking for the cross and then the next higher high.
As shown in this code:
Code:
def SignalUp = if (CrossUp && higherHigh)
    then 1
        else if    (CrossUp[1] && higherHigh && !higherHigh[1])
    then 1
        else if    (CrossUp[2] && higherHigh && !higherHigh[1] && !higherHigh[2])
    then 1
        else Double.NaN;

Looking for a simple MA crossover? There are 101 flavors of crosses found:
https://usethinkscript.com/threads/moving-average-crossovers.229/
 
Triple Moving Average....Average MA
This script gives you a single moving average that is the average of 3 selected moving averages. I am finding this useful!

http://tos.mx/YAS16z1
Code:
# E-Charts v3

declare upper;
input short_average = 9;
input medium_average = 21;
input long_average = 50;

def MA1;
def MA2;
def MA3;
def MA4;

MA1 = Average(close, short_average);
MA2 = Average(close, medium_average);
MA3 = Average(close, long_average);

MA4 = (MA1 + MA2 + MA3) / 3;

# Plot the moving average lines

plot ln1 = MA4;
ln1.AssignValueColor (if close > MA4 then Color.cyan else if close < MA4 then Color.magenta else Color.white);
ln1.SetLineWeight(1);
mod edit: added the above source code provided in the above share link
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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