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.
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
- 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
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: