AGAIG Label Fast MA is Above, Below Slow MA For ThinkOrSwim

csricksdds

Trader Educator
VIP
AGAIG 8/21 EMA LABEL SHOWING BARS ABOVE/BELOW for TOS​

As a label lover who wants only the information here is an 8/21 EMA LABEL (can be toggled for SMA, Weighted, Wilders, Hull, our choice) and you can also change the parameters should you desire.

EvsjIye.png


What it does
Shows a single label on your chart telling you whether the fast MA is above, below, or at the slow MA, and how many bars that condition has held.

Inputs
  • maType — dropdown: choose Simple (SMA), Exponential (EMA), Weighted (WMA), Wilders, or Hull. Applies to both lines.
  • fastLength — default 8
  • slowLength — default 21
  • price — default close (can switch to open/high/low/hl2 etc.)
  • LabelSize / LabelLocation — cosmetic placement, doesn't affect logic
Reading the label
  • Green, e.g. "EMA 8/21: Above (5)" — fast has been above slow for 5+ bars, trend confirmed
  • Red, e.g. "EMA 8/21: Below (12)" — fast has been below slow for 12+ bars, downtrend confirmed
  • Yellow — either fast = slow exactly, or the cross just happened (count = 1), meaning it hasn't had a bar yet to confirm
How to use it
Add to chart, pick your MA type and lengths.
Watch for yellow — that's your "just crossed" flag.
Green/red confirms the trend has held for more than one bar. You decide your own threshold from there based on how it behaves over time.

Known behavior to watch
  • Hull and Wilders will move differently than EMA/SMA — the count/color feel may need separate calibration if you experiment with those types.
  • Count resets to 1 every time trend flips, including whipsaws — a choppy market will show a lot of quick yellow flickers.

LABEL INDICATOR LINK: http://tos.mx/!2UuZwHF0
Code:
#AGAIG 8/21 MA Label

input maType      = AverageType.EXPONENTIAL;
input fastLength  = 8;
input slowLength  = 21;
input price       = close;
input LabelSize     = fontsize.medium;
input LabelLocation = location.top_left;

def fast = MovingAverage(maType, price, fastLength);
def slow = MovingAverage(maType, price, slowLength);

def trend = if fast > slow then 1 else if fast < slow then -1 else 0;
def count = if trend != trend[1] then 1 else count[1] + 1;

def maLabel = if maType == AverageType.SIMPLE then 1
    else if maType == AverageType.EXPONENTIAL then 2
    else if maType == AverageType.WEIGHTED then 3
    else if maType == AverageType.WILDERS then 4
    else if maType == AverageType.HULL then 5
    else 0;

AddLabel(yes,
    (if maLabel == 1 then "SMA"
     else if maLabel == 2 then "EMA"
     else if maLabel == 3 then "WMA"
     else if maLabel == 4 then "Wilders"
     else if maLabel == 5 then "Hull"
     else "MA") + " " + fastLength + "/" + slowLength + ": " +
    (if trend == 1 then "Above" else if trend == -1 then "Below" else "At") + " (" + count + ")",
    if trend == 0 then Color.YELLOW
    else if count <= 1 then Color.YELLOW
    else if trend == 1 then Color.GREEN
    else Color.RED, LabelLocation, LabelSize);
 
Last edited by a moderator:

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