top of page

Thinkscript Library

Public·1 member

Higher Timeframe MA Stack — Trend Drop


# Higher Timeframe MA Stack — Trend Drop


A trend-context tool you can drop on any chart. It pulls three moving averages from a higher timeframe, color-codes them by alignment, and tells you whether the bigger picture is bull-stacked, bear-stacked, or mixed — so your lower-timeframe entries stop fighting the macro trend.


## What it does


- Plots three MAs (default 20 / 50 / 200 EMA) computed on a higher timeframe of your choice

- Colors all three lines green when the stack is bullish (Fast > Mid > Slow)

- Colors them red when the stack is bearish (Fast < Mid < Slow)

- Shows a label with the current stack state and tints the background lightly

- Fires alerts the moment the stack flips bull or bear


## Recommended settings


- Aggregation: HOUR (use DAY for swing, 30min for day trades)

- Fast length: 20

- Mid length: 50

- Slow length: 200

- MA type: EMA (try SMA for slower, smoother bias)


## Ideal timeframe


Best on a chart at least 4x faster than your selected aggregation. Common combos: 15-min chart with HOUR stack, or 1-hour chart with DAY stack.


## How to use


Trade in the direction of the stack. When the script shows a Bull Stack and tints the background green, take long setups from your favorite system and ignore shorts. When it flips Bear, do the opposite. Mixed (gray) means the higher timeframe is in transition — size down or stand aside until the stack reasserts.


## thinkScript code


```

# ─────────────────────────────────────────────

# │ MarketFragments.com | DNA & Market │

# │ info@marketfragments.com │

# │ www.marketfragments.com │

# ─────────────────────────────────────────────

# Time →

# │

# █ █ █│ █

# █ █ █ │ █ █

# █ █ █ │ █ █ █ ╭─╮

# █ █ █ │ █ █ █ █ ╭─╯ ╰─╮

# █ █ █ │ █ █ █ █ █ █ ╭─╯ ╰─╮

# █ █ █ │ █ █ █ █ █ █ █ █ ╭─╯ ╰─╮

# █ █ █ │ █ █ █ █ █ █ █ █ █ █╭─╯ ╰─╮

# █ █ █ │ █ █ █ █ █ █ █ █ ╰─╮ ╭─╯

# █ █ █ │ █ █ █ █ █ █ ╰─╮ ╭─╯

# █ █ █ │ █ █ █ █ ╰─╮ ╭─╯

# █ █ █ │ █ █ ╰─╮ ╭─╯

# █ █ █ │ █ ╰─────╯

# ──────┴──────────────────────────────────────────────────────────────

# T1 T2 T3 T4 T5 T6

#

# Higher Timeframe MA Stack

# Plots 3 MAs from a higher timeframe and flags bull / bear / mixed alignment.

# Free for personal, non-commercial use. Attribution appreciated.


declare upper;


input aggregationPeriod = AggregationPeriod.HOUR;

input fastLength = 20;

input midLength = 50;

input slowLength = 200;

input maType = {default EMA, SMA, WMA, HullMA};

input showLabel = yes;

input tintBackground = yes;


def src = close(period = aggregationPeriod);


def ma1 = if maType == maType.EMA then ExpAverage(src, fastLength)

else if maType == maType.SMA then Average(src, fastLength)

else if maType == maType.WMA then wma(src, fastLength)

else HullMovingAvg(src, fastLength);


def ma2 = if maType == maType.EMA then ExpAverage(src, midLength)

else if maType == maType.SMA then Average(src, midLength)

else if maType == maType.WMA then wma(src, midLength)

else HullMovingAvg(src, midLength);


def ma3 = if maType == maType.EMA then ExpAverage(src, slowLength)

else if maType == maType.SMA then Average(src, slowLength)

else if maType == maType.WMA then wma(src, slowLength)

else HullMovingAvg(src, slowLength);


def bullStack = ma1 > ma2 and ma2 > ma3;

def bearStack = ma1 < ma2 and ma2 < ma3;

def state = if bullStack then 1 else if bearStack then -1 else 0;


plot Fast = ma1;

plot Mid = ma2;

plot Slow = ma3;


Fast.AssignValueColor(if state == 1 then Color.GREEN else if state == -1 then Color.RED else Color.GRAY);

Mid.AssignValueColor( if state == 1 then Color.GREEN else if state == -1 then Color.RED else Color.GRAY);

Slow.AssignValueColor(if state == 1 then Color.GREEN else if state == -1 then Color.RED else Color.GRAY);


Fast.SetLineWeight(2);

Mid.SetLineWeight(2);

Slow.SetLineWeight(3);


AssignBackgroundColor(if !tintBackground then Color.CURRENT

else if state == 1 then CreateColor(0, 35, 0)

else if state == -1 then CreateColor(40, 0, 0)

else Color.CURRENT);


AddLabel(showLabel,

(if state == 1 then "Bull Stack"

else if state == -1 then "Bear Stack"

else "Mixed") + " | HTF MA Stack",

if state == 1 then Color.GREEN else if state == -1 then Color.RED else Color.GRAY);


# Alerts on stack flips

Alert(state == 1 and state[1] != 1, "MF HTF MA Stack: Bull flip", Alert.BAR, Sound.Ding);

Alert(state == -1 and state[1] != -1, "MF HTF MA Stack: Bear flip", Alert.BAR, Sound.Ding);

```


Drop your tweaks, screenshots, and questions below — that's how the library gets better.


Brain with financial data analysis.

Inquiries at :

Important Risk Notice: Trading involves substantial risk of loss. This is educational content only—not advice. Full details here  ------------>  

Proceed only if you're prepared.

tel#: (843) 321-8514

bottom of page