Avoiding Counter trending signals

convertiblejay

Member
VIP
I’ve recently been using TheBig4 indicator and have had some success with it. However, I’ve noticed that some of my largest losses occur when I take intraday signals that move against the broader market trend on higher timeframes such as the daily, 4-hour, and 1-hour charts.
To address this, I want to incorporate higher timeframe (HTF) alignment into the original strategy. The idea is straightforward: signals on the intraday chart (for example, the 5-minute timeframe) should only appear when they are aligned with the direction of the daily, 4-hour, and 1-hour trends.
In other words, if the intraday signal does not agree with the higher timeframe trend, the trade should be ignored and no signal arrow should appear on the chart.

Would someone @merryDay or @useThinkScript anyone else that are good with custom scripts please help implement this logic into the script? I’ve included the ThinkScript below for reference
Code:
# The Big Four Indicator
# https://usethinkscript.com/threads/the-big-four-chart-setup.14711/
# v1.0 - GiantBull and TradingNumbers
# v1.1 - TradingNumbers - hiding vertical lines by ddefault and added arrows
# v1.2 - TradingNumbers - added TMO
# v1.3 - TradingNumbers - hold trend input added
# v1.4 - TradingNumbers - simplified options, added filter with TMO, and set conditions per GianBull parameters
# v1.5 - TradingNumbers - removed TMO color filter percentChg GiantBull, added labels

# Info Labels

input showLabels = yes;
AddLabel(showLabels, " The Big Four v1.5 ", Color.WHITE);

# AK Trend

def aktrend_input1 = 3;
def aktrend_input2 = 8;
def aktrend_price = close;

def aktrend_fastmaa = MovAvgExponential(aktrend_price, aktrend_input1);
def aktrend_fastmab = MovAvgExponential(aktrend_price, aktrend_input2);
def aktrend_bspread = (aktrend_fastmaa - aktrend_fastmab) * 1.001;

def cond1_UP = if aktrend_bspread > 0 then 1 else 0;
def cond1_DN = if aktrend_bspread <= 0 then -1 else 0;

# ZSCORE

def zscore_price = close;
def zscore_length = 20;
def zscore_ZavgLength = 20;

def zscore_oneSD = StDev(zscore_price, zscore_length);
def zscore_avgClose = SimpleMovingAvg(zscore_price, zscore_length);
def zscore_ofoneSD = zscore_oneSD * zscore_price[1];
def zscore_Zscorevalue = ((zscore_price - zscore_avgClose) / zscore_oneSD);
def zscore_avgZv = Average(zscore_Zscorevalue, 20);
def zscore_Zscore = ((zscore_price - zscore_avgClose) / zscore_oneSD);
def zscore_avgZscore = Average(zscore_Zscorevalue, zscore_ZavgLength);

def cond2_UP = if zscore_Zscore > 0 then 1 else 0;
def cond2_DN = if zscore_Zscore <= 0 then -1 else 0;

# Ehlers

def ehlers_length = 34;

def ehlers_price = (high + low) / 2;
def ehlers_coeff = ehlers_length * ehlers_price * ehlers_price - 2 * ehlers_price * Sum(ehlers_price, ehlers_length)[1] + Sum(ehlers_price * ehlers_price, ehlers_length)[1];
def ehlers_Ehlers = Sum(ehlers_coeff * ehlers_price, ehlers_length) / Sum(ehlers_coeff, ehlers_length);

def cond3_UP = if close > ehlers_Ehlers then 1 else 0;
def cond3_DN = if close <= ehlers_Ehlers then -1 else 0;

# Anchored Momentum

def amom_src = close;
def amom_MomentumPeriod = 10;
def amom_SignalPeriod = 8;
def amom_SmoothMomentum = no;
def amom_SmoothingPeriod = 7;

def amom_p = 2 * amom_MomentumPeriod + 1;
def amom_t_amom = if amom_SmoothMomentum == yes then ExpAverage(amom_src, amom_SmoothingPeriod) else amom_src;
def amom_amom = 100 * ( (amom_t_amom / ( Average(amom_src, amom_p)) - 1));
def amom_amoms = Average(amom_amom, amom_SignalPeriod);


def cond4_UP = if amom_amom > 0 then 1 else 0;
def cond4_DN = if amom_amom <= 0 then -1 else 0;

# TMO

def tmo_length = 30; #def 14
def tmo_calcLength = 6; #def 5
def tmo_smoothLength = 6; #def 3

def tmo_data = fold i = 0 to tmo_length with s do s + (if close > GetValue(open, i) then 1 else if close < GetValue(open, i) then - 1 else 0);
def tmo_EMA5 = ExpAverage(tmo_data, tmo_calcLength);
def tmo_Main = ExpAverage(tmo_EMA5, tmo_smoothLength);
def tmo_Signal = ExpAverage(tmo_Main, tmo_smoothLength);
def tmo_color = if tmo_Main > tmo_Signal then 1 else -1;

def cond5_UP = if tmo_Main <= 0 then 1 else 0;
def cond5_DN = if tmo_Main >= 0 then -1 else 0;

# Strategy

input Strategy_Confirmation_Factor = 4;
input Strategy_FilterWithTMO = no;
input Strategy_ColoredCandlesOn = yes;
input Strategy_VerticalLinesOn = no;
input Strategy_HoldTrend = yes;

def cond_UP = cond1_UP + cond2_UP + cond3_UP + cond4_UP;
def cond_DN = cond1_DN + cond2_DN + cond3_DN + cond4_DN;

def direction = if cond_UP >= Strategy_Confirmation_Factor and (!Strategy_FilterWithTMO or cond5_UP) then 1
else if cond_DN <= -Strategy_Confirmation_Factor and (!Strategy_FilterWithTMO or cond5_DN) then -1
else if !Strategy_HoldTrend and direction[1] == 1 and cond_UP < Strategy_Confirmation_Factor and cond_DN > -Strategy_Confirmation_Factor then 0
else if !Strategy_HoldTrend and direction[1] == -1 and cond_DN > -Strategy_Confirmation_Factor and cond_UP < Strategy_Confirmation_Factor then 0
else direction[1];

plot signal_up = direction == 1 and direction[1] < 1;
signal_up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal_up.SetDefaultColor(Color.WHITE);
signal_up.Hide();
signal_up.HideBubble();
signal_up.HideTitle();

plot signal_dn = direction == -1 and direction[1] > -1;
signal_dn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
signal_dn.SetDefaultColor(Color.WHITE);
signal_dn.Hide();
signal_dn.HideBubble();
signal_dn.HideTitle();

AssignPriceColor(if Strategy_ColoredCandlesOn then if direction == 1 then Color.LIGHT_GREEN else if direction == -1 then Color.RED else Color.GRAY else Color.CURRENT);

AddLabel(showLabels, if Strategy_ColoredCandlesOn then if direction == 1 then " Bullish " else if direction == -1 then " Bearish " else " Neutral " else " N/A ",
if Strategy_ColoredCandlesOn then if direction == 1 then Color.LIGHT_GREEN else if direction == -1 then Color.RED else Color.GRAY else Color.BLACK);

AddVerticalLine(Strategy_VerticalLinesOn and signal_up, "Buy", Color.LIGHT_GREEN);
AddVerticalLine(Strategy_VerticalLinesOn and signal_dn, "Sell", Color.RED);

Alert(signal_up[1], "Buy", Alert.BAR, Sound.DING);
Alert(signal_dn[1], "Sell", Alert.BAR, Sound.DING);
 
Last edited by a moderator:
Solution
https://tos.mx/!szZO62wX There are some "nuances" on coding HTF so I had to make it where the daily would just show up when true...made to use on intraday

68aK8g5.jpeg

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

What does this look like to you? Provide some examples.
Ben an examples of HTF alignment is if the Daily, 4hr,1hr, are all bearish but I get a long signal on the 5min intraday its a trap in the direction of the 5min signal. an example would be on AAOI on Friday. I don't want the long signals to show because on the daily, 4hr, and 1hr timeframe AAOI is in a downtrend.

The core issue is that The Big Four watches 4 indicators on the current timeframe only. It has no idea what the higher timeframe is doing. That's why I want to layer it properly.
 

Attachments

  • Screen Shot 2026-03-15 at 6.24.40 PM.png
    Screen Shot 2026-03-15 at 6.24.40 PM.png
    79.9 KB · Views: 24
Ben an examples of HTF alignment is if the Daily, 4hr,1hr, are all bearish but I get a long signal on the 5min intraday its a trap in the direction of the 5min signal. an example would be on AAOI on Friday. I don't want the long signals to show because on the daily, 4hr, and 1hr timeframe AAOI is in a downtrend.

The core issue is that The Big Four watches 4 indicators on the current timeframe only. It has no idea what the higher timeframe is doing. That's why I want to layer it properly.
How do you define downtrend? Got any more examples?
 
How do you define downtrend? Got any more examples?
Ben that's a nuance questions there's many ways to define a downtrend. price below all MAs, lower highs, failed reclaimed. I wanted to do the time frame alignment as the easier method because most of my trades are caused by me going against the bigger time frame trend. This is another trade I took the on the 12th on AAOI, Price is below all the MAs and hourly and 4hr are both in a downtrend.
 

Attachments

  • Screen Shot 2026-03-15 at 11.17.21 PM.png
    Screen Shot 2026-03-15 at 11.17.21 PM.png
    139.3 KB · Views: 13
Antwerks that's exactly what I am looking for. How were you able to create the labels and can you share it pls?
Well it is still "very long" we can rewrite this and shorten the code if it starts to bog down -let me know
Code:
# The Big Four Indicator + HTF Alignment
# Original by GiantBull and TradingNumbers
# Rewritten intraday HTF alignment version ANTWERKS 03/16/2026
# Use on charts BELOW 1 HOUR only
# Intraday signals only appear when aligned with 1H / 4H / Daily trend
# ENHANCED BY ANTWERKS 03/16/2026

input showLabels = yes;

input Strategy_Confirmation_Factor = 4;
input Strategy_FilterWithTMO = no;
input Strategy_ColoredCandlesOn = yes;
input Strategy_VerticalLinesOn = no;
input Strategy_HoldTrend = yes;

input useHTFAlignment = yes;
input use1H = yes;
input use4H = yes;
input useDaily = yes;

AddLabel(showLabels, " The Big Four HTF v2 ", Color.WHITE);

# --------------------------------------------------
# CHART TIMEFRAME LOGIC
# --------------------------------------------------

# AK Trend
def aktrend_input1 = 3;
def aktrend_input2 = 8;
def aktrend_price = close;

def aktrend_fastmaa = MovAvgExponential(aktrend_price, aktrend_input1);
def aktrend_fastmab = MovAvgExponential(aktrend_price, aktrend_input2);
def aktrend_bspread = (aktrend_fastmaa - aktrend_fastmab) * 1.001;

def cond1_UP = if aktrend_bspread > 0 then 1 else 0;
def cond1_DN = if aktrend_bspread <= 0 then -1 else 0;

# ZScore
def zscore_price = close;
def zscore_length = 20;
def zscore_ZavgLength = 20;

def zscore_oneSD = StDev(zscore_price, zscore_length);
def zscore_avgClose = SimpleMovingAvg(zscore_price, zscore_length);
def zscore_Zscorevalue = (zscore_price - zscore_avgClose) / zscore_oneSD;
def zscore_Zscore = (zscore_price - zscore_avgClose) / zscore_oneSD;
def zscore_avgZscore = Average(zscore_Zscorevalue, zscore_ZavgLength);

def cond2_UP = if zscore_Zscore > 0 then 1 else 0;
def cond2_DN = if zscore_Zscore <= 0 then -1 else 0;

# Ehlers
def ehlers_length = 34;
def ehlers_price = (high + low) / 2;
def ehlers_coeff =
    ehlers_length * ehlers_price * ehlers_price
    - 2 * ehlers_price * Sum(ehlers_price, ehlers_length)[1]
    + Sum(ehlers_price * ehlers_price, ehlers_length)[1];
def ehlers_Ehlers =
    Sum(ehlers_coeff * ehlers_price, ehlers_length) / Sum(ehlers_coeff, ehlers_length);

def cond3_UP = if close > ehlers_Ehlers then 1 else 0;
def cond3_DN = if close <= ehlers_Ehlers then -1 else 0;

# Anchored Momentum
def amom_src = close;
def amom_MomentumPeriod = 10;
def amom_SignalPeriod = 8;
def amom_SmoothMomentum = no;
def amom_SmoothingPeriod = 7;

def amom_p = 2 * amom_MomentumPeriod + 1;
def amom_t_amom =
    if amom_SmoothMomentum == yes
    then ExpAverage(amom_src, amom_SmoothingPeriod)
    else amom_src;
def amom_amom = 100 * ((amom_t_amom / Average(amom_src, amom_p)) - 1);
def amom_amoms = Average(amom_amom, amom_SignalPeriod);

def cond4_UP = if amom_amom > 0 then 1 else 0;
def cond4_DN = if amom_amom <= 0 then -1 else 0;

# TMO
def tmo_length = 30;
def tmo_calcLength = 6;
def tmo_smoothLength = 6;

def tmo_data = fold i = 0 to tmo_length with s do
    s + (if close > GetValue(open, i) then 1 else if close < GetValue(open, i) then -1 else 0);

def tmo_EMA5 = ExpAverage(tmo_data, tmo_calcLength);
def tmo_Main = ExpAverage(tmo_EMA5, tmo_smoothLength);
def tmo_Signal = ExpAverage(tmo_Main, tmo_smoothLength);

def cond5_UP = if tmo_Main <= 0 then 1 else 0;
def cond5_DN = if tmo_Main >= 0 then -1 else 0;

# Chart timeframe direction
def cond_UP = cond1_UP + cond2_UP + cond3_UP + cond4_UP;
def cond_DN = cond1_DN + cond2_DN + cond3_DN + cond4_DN;

rec direction =
    if cond_UP >= Strategy_Confirmation_Factor and (!Strategy_FilterWithTMO or cond5_UP) then 1
    else if cond_DN <= -Strategy_Confirmation_Factor and (!Strategy_FilterWithTMO or cond5_DN) then -1
    else if !Strategy_HoldTrend and direction[1] == 1 and cond_UP < Strategy_Confirmation_Factor and cond_DN > -Strategy_Confirmation_Factor then 0
    else if !Strategy_HoldTrend and direction[1] == -1 and cond_DN > -Strategy_Confirmation_Factor and cond_UP < Strategy_Confirmation_Factor then 0
    else direction[1];

# --------------------------------------------------
# 1 HOUR HTF LOGIC
# --------------------------------------------------

def c1h = close(period = AggregationPeriod.HOUR);
def o1h = open(period = AggregationPeriod.HOUR);
def h1h = high(period = AggregationPeriod.HOUR);
def l1h = low(period = AggregationPeriod.HOUR);

def aktrend_fastmaa_1h = MovAvgExponential(c1h, aktrend_input1);
def aktrend_fastmab_1h = MovAvgExponential(c1h, aktrend_input2);
def aktrend_bspread_1h = (aktrend_fastmaa_1h - aktrend_fastmab_1h) * 1.001;
def cond1_UP_1h = if aktrend_bspread_1h > 0 then 1 else 0;
def cond1_DN_1h = if aktrend_bspread_1h <= 0 then -1 else 0;

def zscore_oneSD_1h = StDev(c1h, zscore_length);
def zscore_avgClose_1h = SimpleMovingAvg(c1h, zscore_length);
def zscore_Zscore_1h = (c1h - zscore_avgClose_1h) / zscore_oneSD_1h;
def cond2_UP_1h = if zscore_Zscore_1h > 0 then 1 else 0;
def cond2_DN_1h = if zscore_Zscore_1h <= 0 then -1 else 0;

def ehlers_price_1h = (h1h + l1h) / 2;
def ehlers_coeff_1h =
    ehlers_length * ehlers_price_1h * ehlers_price_1h
    - 2 * ehlers_price_1h * Sum(ehlers_price_1h, ehlers_length)[1]
    + Sum(ehlers_price_1h * ehlers_price_1h, ehlers_length)[1];
def ehlers_Ehlers_1h =
    Sum(ehlers_coeff_1h * ehlers_price_1h, ehlers_length) / Sum(ehlers_coeff_1h, ehlers_length);
def cond3_UP_1h = if c1h > ehlers_Ehlers_1h then 1 else 0;
def cond3_DN_1h = if c1h <= ehlers_Ehlers_1h then -1 else 0;

def amom_t_amom_1h =
    if amom_SmoothMomentum == yes
    then ExpAverage(c1h, amom_SmoothingPeriod)
    else c1h;
def amom_amom_1h = 100 * ((amom_t_amom_1h / Average(c1h, amom_p)) - 1);
def cond4_UP_1h = if amom_amom_1h > 0 then 1 else 0;
def cond4_DN_1h = if amom_amom_1h <= 0 then -1 else 0;

def tmo_data_1h = fold j = 0 to tmo_length with s1 do
    s1 + (if c1h > GetValue(o1h, j) then 1 else if c1h < GetValue(o1h, j) then -1 else 0);

def tmo_EMA5_1h = ExpAverage(tmo_data_1h, tmo_calcLength);
def tmo_Main_1h = ExpAverage(tmo_EMA5_1h, tmo_smoothLength);
def cond5_UP_1h = if tmo_Main_1h <= 0 then 1 else 0;
def cond5_DN_1h = if tmo_Main_1h >= 0 then -1 else 0;

def cond_UP_1h = cond1_UP_1h + cond2_UP_1h + cond3_UP_1h + cond4_UP_1h;
def cond_DN_1h = cond1_DN_1h + cond2_DN_1h + cond3_DN_1h + cond4_DN_1h;

rec direction_1h =
    if cond_UP_1h >= Strategy_Confirmation_Factor and (!Strategy_FilterWithTMO or cond5_UP_1h) then 1
    else if cond_DN_1h <= -Strategy_Confirmation_Factor and (!Strategy_FilterWithTMO or cond5_DN_1h) then -1
    else if !Strategy_HoldTrend and direction_1h[1] == 1 and cond_UP_1h < Strategy_Confirmation_Factor and cond_DN_1h > -Strategy_Confirmation_Factor then 0
    else if !Strategy_HoldTrend and direction_1h[1] == -1 and cond_DN_1h > -Strategy_Confirmation_Factor and cond_UP_1h < Strategy_Confirmation_Factor then 0
    else direction_1h[1];

# --------------------------------------------------
# 4 HOUR HTF LOGIC
# --------------------------------------------------

def c4h = close(period = AggregationPeriod.FOUR_HOURS);
def o4h = open(period = AggregationPeriod.FOUR_HOURS);
def h4h = high(period = AggregationPeriod.FOUR_HOURS);
def l4h = low(period = AggregationPeriod.FOUR_HOURS);

def aktrend_fastmaa_4h = MovAvgExponential(c4h, aktrend_input1);
def aktrend_fastmab_4h = MovAvgExponential(c4h, aktrend_input2);
def aktrend_bspread_4h = (aktrend_fastmaa_4h - aktrend_fastmab_4h) * 1.001;
def cond1_UP_4h = if aktrend_bspread_4h > 0 then 1 else 0;
def cond1_DN_4h = if aktrend_bspread_4h <= 0 then -1 else 0;

def zscore_oneSD_4h = StDev(c4h, zscore_length);
def zscore_avgClose_4h = SimpleMovingAvg(c4h, zscore_length);
def zscore_Zscore_4h = (c4h - zscore_avgClose_4h) / zscore_oneSD_4h;
def cond2_UP_4h = if zscore_Zscore_4h > 0 then 1 else 0;
def cond2_DN_4h = if zscore_Zscore_4h <= 0 then -1 else 0;

def ehlers_price_4h = (h4h + l4h) / 2;
def ehlers_coeff_4h =
    ehlers_length * ehlers_price_4h * ehlers_price_4h
    - 2 * ehlers_price_4h * Sum(ehlers_price_4h, ehlers_length)[1]
    + Sum(ehlers_price_4h * ehlers_price_4h, ehlers_length)[1];
def ehlers_Ehlers_4h =
    Sum(ehlers_coeff_4h * ehlers_price_4h, ehlers_length) / Sum(ehlers_coeff_4h, ehlers_length);
def cond3_UP_4h = if c4h > ehlers_Ehlers_4h then 1 else 0;
def cond3_DN_4h = if c4h <= ehlers_Ehlers_4h then -1 else 0;

def amom_t_amom_4h =
    if amom_SmoothMomentum == yes
    then ExpAverage(c4h, amom_SmoothingPeriod)
    else c4h;
def amom_amom_4h = 100 * ((amom_t_amom_4h / Average(c4h, amom_p)) - 1);
def cond4_UP_4h = if amom_amom_4h > 0 then 1 else 0;
def cond4_DN_4h = if amom_amom_4h <= 0 then -1 else 0;

def tmo_data_4h = fold k = 0 to tmo_length with s2 do
    s2 + (if c4h > GetValue(o4h, k) then 1 else if c4h < GetValue(o4h, k) then -1 else 0);

def tmo_EMA5_4h = ExpAverage(tmo_data_4h, tmo_calcLength);
def tmo_Main_4h = ExpAverage(tmo_EMA5_4h, tmo_smoothLength);
def cond5_UP_4h = if tmo_Main_4h <= 0 then 1 else 0;
def cond5_DN_4h = if tmo_Main_4h >= 0 then -1 else 0;

def cond_UP_4h = cond1_UP_4h + cond2_UP_4h + cond3_UP_4h + cond4_UP_4h;
def cond_DN_4h = cond1_DN_4h + cond2_DN_4h + cond3_DN_4h + cond4_DN_4h;

rec direction_4h =
    if cond_UP_4h >= Strategy_Confirmation_Factor and (!Strategy_FilterWithTMO or cond5_UP_4h) then 1
    else if cond_DN_4h <= -Strategy_Confirmation_Factor and (!Strategy_FilterWithTMO or cond5_DN_4h) then -1
    else if !Strategy_HoldTrend and direction_4h[1] == 1 and cond_UP_4h < Strategy_Confirmation_Factor and cond_DN_4h > -Strategy_Confirmation_Factor then 0
    else if !Strategy_HoldTrend and direction_4h[1] == -1 and cond_DN_4h > -Strategy_Confirmation_Factor and cond_UP_4h < Strategy_Confirmation_Factor then 0
    else direction_4h[1];

# --------------------------------------------------
# DAILY HTF LOGIC
# --------------------------------------------------

def cD = close(period = AggregationPeriod.DAY);
def oD = open(period = AggregationPeriod.DAY);
def hD = high(period = AggregationPeriod.DAY);
def lD = low(period = AggregationPeriod.DAY);

def aktrend_fastmaa_D = MovAvgExponential(cD, aktrend_input1);
def aktrend_fastmab_D = MovAvgExponential(cD, aktrend_input2);
def aktrend_bspread_D = (aktrend_fastmaa_D - aktrend_fastmab_D) * 1.001;
def cond1_UP_D = if aktrend_bspread_D > 0 then 1 else 0;
def cond1_DN_D = if aktrend_bspread_D <= 0 then -1 else 0;

def zscore_oneSD_D = StDev(cD, zscore_length);
def zscore_avgClose_D = SimpleMovingAvg(cD, zscore_length);
def zscore_Zscore_D = (cD - zscore_avgClose_D) / zscore_oneSD_D;
def cond2_UP_D = if zscore_Zscore_D > 0 then 1 else 0;
def cond2_DN_D = if zscore_Zscore_D <= 0 then -1 else 0;

def ehlers_price_D = (hD + lD) / 2;
def ehlers_coeff_D =
    ehlers_length * ehlers_price_D * ehlers_price_D
    - 2 * ehlers_price_D * Sum(ehlers_price_D, ehlers_length)[1]
    + Sum(ehlers_price_D * ehlers_price_D, ehlers_length)[1];
def ehlers_Ehlers_D =
    Sum(ehlers_coeff_D * ehlers_price_D, ehlers_length) / Sum(ehlers_coeff_D, ehlers_length);
def cond3_UP_D = if cD > ehlers_Ehlers_D then 1 else 0;
def cond3_DN_D = if cD <= ehlers_Ehlers_D then -1 else 0;

def amom_t_amom_D =
    if amom_SmoothMomentum == yes
    then ExpAverage(cD, amom_SmoothingPeriod)
    else cD;
def amom_amom_D = 100 * ((amom_t_amom_D / Average(cD, amom_p)) - 1);
def cond4_UP_D = if amom_amom_D > 0 then 1 else 0;
def cond4_DN_D = if amom_amom_D <= 0 then -1 else 0;

def tmo_data_D = fold m = 0 to tmo_length with s3 do
    s3 + (if cD > GetValue(oD, m) then 1 else if cD < GetValue(oD, m) then -1 else 0);

def tmo_EMA5_D = ExpAverage(tmo_data_D, tmo_calcLength);
def tmo_Main_D = ExpAverage(tmo_EMA5_D, tmo_smoothLength);
def cond5_UP_D = if tmo_Main_D <= 0 then 1 else 0;
def cond5_DN_D = if tmo_Main_D >= 0 then -1 else 0;

def cond_UP_D = cond1_UP_D + cond2_UP_D + cond3_UP_D + cond4_UP_D;
def cond_DN_D = cond1_DN_D + cond2_DN_D + cond3_DN_D + cond4_DN_D;

rec direction_D =
    if cond_UP_D >= Strategy_Confirmation_Factor and (!Strategy_FilterWithTMO or cond5_UP_D) then 1
    else if cond_DN_D <= -Strategy_Confirmation_Factor and (!Strategy_FilterWithTMO or cond5_DN_D) then -1
    else if !Strategy_HoldTrend and direction_D[1] == 1 and cond_UP_D < Strategy_Confirmation_Factor and cond_DN_D > -Strategy_Confirmation_Factor then 0
    else if !Strategy_HoldTrend and direction_D[1] == -1 and cond_DN_D > -Strategy_Confirmation_Factor and cond_UP_D < Strategy_Confirmation_Factor then 0
    else direction_D[1];

# --------------------------------------------------
# HTF ALIGNMENT
# --------------------------------------------------

def pass1H =
    if !useHTFAlignment or !use1H then 1
    else if direction == 1 and direction_1h == 1 then 1
    else if direction == -1 and direction_1h == -1 then 1
    else 0;

def pass4H =
    if !useHTFAlignment or !use4H then 1
    else if direction == 1 and direction_4h == 1 then 1
    else if direction == -1 and direction_4h == -1 then 1
    else 0;

def passD =
    if !useHTFAlignment or !useDaily then 1
    else if direction == 1 and direction_D == 1 then 1
    else if direction == -1 and direction_D == -1 then 1
    else 0;

def bullishStack =
    (!use1H or direction_1h == 1) and
    (!use4H or direction_4h == 1) and
    (!useDaily or direction_D == 1);

def bearishStack =
    (!use1H or direction_1h == -1) and
    (!use4H or direction_4h == -1) and
    (!useDaily or direction_D == -1);

def htfAligned = pass1H and pass4H and passD;

# --------------------------------------------------
# SIGNALS
# --------------------------------------------------

plot signal_up =
    direction == 1 and
    direction[1] < 1 and
    (!useHTFAlignment or htfAligned);
signal_up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal_up.SetDefaultColor(Color.WHITE);
signal_up.HideBubble();
signal_up.HideTitle();

plot signal_dn =
    direction == -1 and
    direction[1] > -1 and
    (!useHTFAlignment or htfAligned);
signal_dn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
signal_dn.SetDefaultColor(Color.WHITE);
signal_dn.HideBubble();
signal_dn.HideTitle();

# --------------------------------------------------
# CANDLE COLORS
# --------------------------------------------------

AssignPriceColor(
    if Strategy_ColoredCandlesOn then
        if direction == 1 then Color.LIGHT_GREEN
        else if direction == -1 then Color.RED
        else Color.LIGHT_GRAY
    else Color.CURRENT
);

# --------------------------------------------------
# LABELS
# --------------------------------------------------

AddLabel(
    showLabels,
    if direction == 1 then " Bullish "
    else if direction == -1 then " Bearish "
    else " Neutral ",
    if direction == 1 then Color.DARK_GREEN
    else if direction == -1 then Color.DARK_RED
    else Color.DARK_ORANGE
);

AddLabel(
    showLabels and useHTFAlignment and use1H,
    " 1H " + (if direction_1h == 1 then "UP " else if direction_1h == -1 then "DOWN " else "NEUTRAL "),
    if direction_1h == 1 then Color.DARK_GREEN
    else if direction_1h == -1 then Color.DARK_RED
    else Color.YELLOW
);

AddLabel(
    showLabels and useHTFAlignment and use4H,
    " 4H " + (if direction_4h == 1 then "UP " else if direction_4h == -1 then "DOWN " else "NEUTRAL "),
    if direction_4h == 1 then Color.DARK_GREEN
    else if direction_4h == -1 then Color.DARK_RED
    else Color.YELLOW
);

def dailyValid = !IsNaN(direction_D);

AddLabel(
    showLabels and useHTFAlignment and useDaily and dailyValid,
    "D " + (if direction_D == 1 then "UP"
           else if direction_D == -1 then "DOWN"
           else "NEUTRAL"),
    if direction_D == 1 then Color.GREEN
    else if direction_D == -1 then Color.RED
    else Color.GRAY
);

AddLabel(
    showLabels and useHTFAlignment,
    if bullishStack then " HTF BULL STACK "
    else if bearishStack then " HTF BEAR STACK "
    else " HTF MIXED ",
    if bullishStack then Color.DARK_GREEN
    else if bearishStack then Color.DARK_RED
    else Color.YELLOW
);

# --------------------------------------------------
# VERTICAL LINES
# --------------------------------------------------

AddVerticalLine(Strategy_VerticalLinesOn and signal_up, "Buy", Color.LIGHT_GREEN);
AddVerticalLine(Strategy_VerticalLinesOn and signal_dn, "Sell", Color.RED);

# --------------------------------------------------
# ALERTS
# --------------------------------------------------

Alert(signal_up[1], "Buy", Alert.BAR, Sound.DING);
Alert(signal_dn[1], "Sell", Alert.BAR, Sound.DING);
 
Well it is still "very long" we can rewrite this and shorten the code if it starts to bog down -let me know
Code:
# The Big Four Indicator + HTF Alignment
# Original by GiantBull and TradingNumbers
# Rewritten intraday HTF alignment version ANTWERKS 03/16/2026
# Use on charts BELOW 1 HOUR only
# Intraday signals only appear when aligned with 1H / 4H / Daily trend
# ENHANCED BY ANTWERKS 03/16/2026

input showLabels = yes;

input Strategy_Confirmation_Factor = 4;
input Strategy_FilterWithTMO = no;
input Strategy_ColoredCandlesOn = yes;
input Strategy_VerticalLinesOn = no;
input Strategy_HoldTrend = yes;

input useHTFAlignment = yes;
input use1H = yes;
input use4H = yes;
input useDaily = yes;

AddLabel(showLabels, " The Big Four HTF v2 ", Color.WHITE);

# --------------------------------------------------
# CHART TIMEFRAME LOGIC
# --------------------------------------------------

# AK Trend
def aktrend_input1 = 3;
def aktrend_input2 = 8;
def aktrend_price = close;

def aktrend_fastmaa = MovAvgExponential(aktrend_price, aktrend_input1);
def aktrend_fastmab = MovAvgExponential(aktrend_price, aktrend_input2);
def aktrend_bspread = (aktrend_fastmaa - aktrend_fastmab) * 1.001;

def cond1_UP = if aktrend_bspread > 0 then 1 else 0;
def cond1_DN = if aktrend_bspread <= 0 then -1 else 0;

# ZScore
def zscore_price = close;
def zscore_length = 20;
def zscore_ZavgLength = 20;

def zscore_oneSD = StDev(zscore_price, zscore_length);
def zscore_avgClose = SimpleMovingAvg(zscore_price, zscore_length);
def zscore_Zscorevalue = (zscore_price - zscore_avgClose) / zscore_oneSD;
def zscore_Zscore = (zscore_price - zscore_avgClose) / zscore_oneSD;
def zscore_avgZscore = Average(zscore_Zscorevalue, zscore_ZavgLength);

def cond2_UP = if zscore_Zscore > 0 then 1 else 0;
def cond2_DN = if zscore_Zscore <= 0 then -1 else 0;

# Ehlers
def ehlers_length = 34;
def ehlers_price = (high + low) / 2;
def ehlers_coeff =
    ehlers_length * ehlers_price * ehlers_price
    - 2 * ehlers_price * Sum(ehlers_price, ehlers_length)[1]
    + Sum(ehlers_price * ehlers_price, ehlers_length)[1];
def ehlers_Ehlers =
    Sum(ehlers_coeff * ehlers_price, ehlers_length) / Sum(ehlers_coeff, ehlers_length);

def cond3_UP = if close > ehlers_Ehlers then 1 else 0;
def cond3_DN = if close <= ehlers_Ehlers then -1 else 0;

# Anchored Momentum
def amom_src = close;
def amom_MomentumPeriod = 10;
def amom_SignalPeriod = 8;
def amom_SmoothMomentum = no;
def amom_SmoothingPeriod = 7;

def amom_p = 2 * amom_MomentumPeriod + 1;
def amom_t_amom =
    if amom_SmoothMomentum == yes
    then ExpAverage(amom_src, amom_SmoothingPeriod)
    else amom_src;
def amom_amom = 100 * ((amom_t_amom / Average(amom_src, amom_p)) - 1);
def amom_amoms = Average(amom_amom, amom_SignalPeriod);

def cond4_UP = if amom_amom > 0 then 1 else 0;
def cond4_DN = if amom_amom <= 0 then -1 else 0;

# TMO
def tmo_length = 30;
def tmo_calcLength = 6;
def tmo_smoothLength = 6;

def tmo_data = fold i = 0 to tmo_length with s do
    s + (if close > GetValue(open, i) then 1 else if close < GetValue(open, i) then -1 else 0);

def tmo_EMA5 = ExpAverage(tmo_data, tmo_calcLength);
def tmo_Main = ExpAverage(tmo_EMA5, tmo_smoothLength);
def tmo_Signal = ExpAverage(tmo_Main, tmo_smoothLength);

def cond5_UP = if tmo_Main <= 0 then 1 else 0;
def cond5_DN = if tmo_Main >= 0 then -1 else 0;

# Chart timeframe direction
def cond_UP = cond1_UP + cond2_UP + cond3_UP + cond4_UP;
def cond_DN = cond1_DN + cond2_DN + cond3_DN + cond4_DN;

rec direction =
    if cond_UP >= Strategy_Confirmation_Factor and (!Strategy_FilterWithTMO or cond5_UP) then 1
    else if cond_DN <= -Strategy_Confirmation_Factor and (!Strategy_FilterWithTMO or cond5_DN) then -1
    else if !Strategy_HoldTrend and direction[1] == 1 and cond_UP < Strategy_Confirmation_Factor and cond_DN > -Strategy_Confirmation_Factor then 0
    else if !Strategy_HoldTrend and direction[1] == -1 and cond_DN > -Strategy_Confirmation_Factor and cond_UP < Strategy_Confirmation_Factor then 0
    else direction[1];

# --------------------------------------------------
# 1 HOUR HTF LOGIC
# --------------------------------------------------

def c1h = close(period = AggregationPeriod.HOUR);
def o1h = open(period = AggregationPeriod.HOUR);
def h1h = high(period = AggregationPeriod.HOUR);
def l1h = low(period = AggregationPeriod.HOUR);

def aktrend_fastmaa_1h = MovAvgExponential(c1h, aktrend_input1);
def aktrend_fastmab_1h = MovAvgExponential(c1h, aktrend_input2);
def aktrend_bspread_1h = (aktrend_fastmaa_1h - aktrend_fastmab_1h) * 1.001;
def cond1_UP_1h = if aktrend_bspread_1h > 0 then 1 else 0;
def cond1_DN_1h = if aktrend_bspread_1h <= 0 then -1 else 0;

def zscore_oneSD_1h = StDev(c1h, zscore_length);
def zscore_avgClose_1h = SimpleMovingAvg(c1h, zscore_length);
def zscore_Zscore_1h = (c1h - zscore_avgClose_1h) / zscore_oneSD_1h;
def cond2_UP_1h = if zscore_Zscore_1h > 0 then 1 else 0;
def cond2_DN_1h = if zscore_Zscore_1h <= 0 then -1 else 0;

def ehlers_price_1h = (h1h + l1h) / 2;
def ehlers_coeff_1h =
    ehlers_length * ehlers_price_1h * ehlers_price_1h
    - 2 * ehlers_price_1h * Sum(ehlers_price_1h, ehlers_length)[1]
    + Sum(ehlers_price_1h * ehlers_price_1h, ehlers_length)[1];
def ehlers_Ehlers_1h =
    Sum(ehlers_coeff_1h * ehlers_price_1h, ehlers_length) / Sum(ehlers_coeff_1h, ehlers_length);
def cond3_UP_1h = if c1h > ehlers_Ehlers_1h then 1 else 0;
def cond3_DN_1h = if c1h <= ehlers_Ehlers_1h then -1 else 0;

def amom_t_amom_1h =
    if amom_SmoothMomentum == yes
    then ExpAverage(c1h, amom_SmoothingPeriod)
    else c1h;
def amom_amom_1h = 100 * ((amom_t_amom_1h / Average(c1h, amom_p)) - 1);
def cond4_UP_1h = if amom_amom_1h > 0 then 1 else 0;
def cond4_DN_1h = if amom_amom_1h <= 0 then -1 else 0;

def tmo_data_1h = fold j = 0 to tmo_length with s1 do
    s1 + (if c1h > GetValue(o1h, j) then 1 else if c1h < GetValue(o1h, j) then -1 else 0);

def tmo_EMA5_1h = ExpAverage(tmo_data_1h, tmo_calcLength);
def tmo_Main_1h = ExpAverage(tmo_EMA5_1h, tmo_smoothLength);
def cond5_UP_1h = if tmo_Main_1h <= 0 then 1 else 0;
def cond5_DN_1h = if tmo_Main_1h >= 0 then -1 else 0;

def cond_UP_1h = cond1_UP_1h + cond2_UP_1h + cond3_UP_1h + cond4_UP_1h;
def cond_DN_1h = cond1_DN_1h + cond2_DN_1h + cond3_DN_1h + cond4_DN_1h;

rec direction_1h =
    if cond_UP_1h >= Strategy_Confirmation_Factor and (!Strategy_FilterWithTMO or cond5_UP_1h) then 1
    else if cond_DN_1h <= -Strategy_Confirmation_Factor and (!Strategy_FilterWithTMO or cond5_DN_1h) then -1
    else if !Strategy_HoldTrend and direction_1h[1] == 1 and cond_UP_1h < Strategy_Confirmation_Factor and cond_DN_1h > -Strategy_Confirmation_Factor then 0
    else if !Strategy_HoldTrend and direction_1h[1] == -1 and cond_DN_1h > -Strategy_Confirmation_Factor and cond_UP_1h < Strategy_Confirmation_Factor then 0
    else direction_1h[1];

# --------------------------------------------------
# 4 HOUR HTF LOGIC
# --------------------------------------------------

def c4h = close(period = AggregationPeriod.FOUR_HOURS);
def o4h = open(period = AggregationPeriod.FOUR_HOURS);
def h4h = high(period = AggregationPeriod.FOUR_HOURS);
def l4h = low(period = AggregationPeriod.FOUR_HOURS);

def aktrend_fastmaa_4h = MovAvgExponential(c4h, aktrend_input1);
def aktrend_fastmab_4h = MovAvgExponential(c4h, aktrend_input2);
def aktrend_bspread_4h = (aktrend_fastmaa_4h - aktrend_fastmab_4h) * 1.001;
def cond1_UP_4h = if aktrend_bspread_4h > 0 then 1 else 0;
def cond1_DN_4h = if aktrend_bspread_4h <= 0 then -1 else 0;

def zscore_oneSD_4h = StDev(c4h, zscore_length);
def zscore_avgClose_4h = SimpleMovingAvg(c4h, zscore_length);
def zscore_Zscore_4h = (c4h - zscore_avgClose_4h) / zscore_oneSD_4h;
def cond2_UP_4h = if zscore_Zscore_4h > 0 then 1 else 0;
def cond2_DN_4h = if zscore_Zscore_4h <= 0 then -1 else 0;

def ehlers_price_4h = (h4h + l4h) / 2;
def ehlers_coeff_4h =
    ehlers_length * ehlers_price_4h * ehlers_price_4h
    - 2 * ehlers_price_4h * Sum(ehlers_price_4h, ehlers_length)[1]
    + Sum(ehlers_price_4h * ehlers_price_4h, ehlers_length)[1];
def ehlers_Ehlers_4h =
    Sum(ehlers_coeff_4h * ehlers_price_4h, ehlers_length) / Sum(ehlers_coeff_4h, ehlers_length);
def cond3_UP_4h = if c4h > ehlers_Ehlers_4h then 1 else 0;
def cond3_DN_4h = if c4h <= ehlers_Ehlers_4h then -1 else 0;

def amom_t_amom_4h =
    if amom_SmoothMomentum == yes
    then ExpAverage(c4h, amom_SmoothingPeriod)
    else c4h;
def amom_amom_4h = 100 * ((amom_t_amom_4h / Average(c4h, amom_p)) - 1);
def cond4_UP_4h = if amom_amom_4h > 0 then 1 else 0;
def cond4_DN_4h = if amom_amom_4h <= 0 then -1 else 0;

def tmo_data_4h = fold k = 0 to tmo_length with s2 do
    s2 + (if c4h > GetValue(o4h, k) then 1 else if c4h < GetValue(o4h, k) then -1 else 0);

def tmo_EMA5_4h = ExpAverage(tmo_data_4h, tmo_calcLength);
def tmo_Main_4h = ExpAverage(tmo_EMA5_4h, tmo_smoothLength);
def cond5_UP_4h = if tmo_Main_4h <= 0 then 1 else 0;
def cond5_DN_4h = if tmo_Main_4h >= 0 then -1 else 0;

def cond_UP_4h = cond1_UP_4h + cond2_UP_4h + cond3_UP_4h + cond4_UP_4h;
def cond_DN_4h = cond1_DN_4h + cond2_DN_4h + cond3_DN_4h + cond4_DN_4h;

rec direction_4h =
    if cond_UP_4h >= Strategy_Confirmation_Factor and (!Strategy_FilterWithTMO or cond5_UP_4h) then 1
    else if cond_DN_4h <= -Strategy_Confirmation_Factor and (!Strategy_FilterWithTMO or cond5_DN_4h) then -1
    else if !Strategy_HoldTrend and direction_4h[1] == 1 and cond_UP_4h < Strategy_Confirmation_Factor and cond_DN_4h > -Strategy_Confirmation_Factor then 0
    else if !Strategy_HoldTrend and direction_4h[1] == -1 and cond_DN_4h > -Strategy_Confirmation_Factor and cond_UP_4h < Strategy_Confirmation_Factor then 0
    else direction_4h[1];

# --------------------------------------------------
# DAILY HTF LOGIC
# --------------------------------------------------

def cD = close(period = AggregationPeriod.DAY);
def oD = open(period = AggregationPeriod.DAY);
def hD = high(period = AggregationPeriod.DAY);
def lD = low(period = AggregationPeriod.DAY);

def aktrend_fastmaa_D = MovAvgExponential(cD, aktrend_input1);
def aktrend_fastmab_D = MovAvgExponential(cD, aktrend_input2);
def aktrend_bspread_D = (aktrend_fastmaa_D - aktrend_fastmab_D) * 1.001;
def cond1_UP_D = if aktrend_bspread_D > 0 then 1 else 0;
def cond1_DN_D = if aktrend_bspread_D <= 0 then -1 else 0;

def zscore_oneSD_D = StDev(cD, zscore_length);
def zscore_avgClose_D = SimpleMovingAvg(cD, zscore_length);
def zscore_Zscore_D = (cD - zscore_avgClose_D) / zscore_oneSD_D;
def cond2_UP_D = if zscore_Zscore_D > 0 then 1 else 0;
def cond2_DN_D = if zscore_Zscore_D <= 0 then -1 else 0;

def ehlers_price_D = (hD + lD) / 2;
def ehlers_coeff_D =
    ehlers_length * ehlers_price_D * ehlers_price_D
    - 2 * ehlers_price_D * Sum(ehlers_price_D, ehlers_length)[1]
    + Sum(ehlers_price_D * ehlers_price_D, ehlers_length)[1];
def ehlers_Ehlers_D =
    Sum(ehlers_coeff_D * ehlers_price_D, ehlers_length) / Sum(ehlers_coeff_D, ehlers_length);
def cond3_UP_D = if cD > ehlers_Ehlers_D then 1 else 0;
def cond3_DN_D = if cD <= ehlers_Ehlers_D then -1 else 0;

def amom_t_amom_D =
    if amom_SmoothMomentum == yes
    then ExpAverage(cD, amom_SmoothingPeriod)
    else cD;
def amom_amom_D = 100 * ((amom_t_amom_D / Average(cD, amom_p)) - 1);
def cond4_UP_D = if amom_amom_D > 0 then 1 else 0;
def cond4_DN_D = if amom_amom_D <= 0 then -1 else 0;

def tmo_data_D = fold m = 0 to tmo_length with s3 do
    s3 + (if cD > GetValue(oD, m) then 1 else if cD < GetValue(oD, m) then -1 else 0);

def tmo_EMA5_D = ExpAverage(tmo_data_D, tmo_calcLength);
def tmo_Main_D = ExpAverage(tmo_EMA5_D, tmo_smoothLength);
def cond5_UP_D = if tmo_Main_D <= 0 then 1 else 0;
def cond5_DN_D = if tmo_Main_D >= 0 then -1 else 0;

def cond_UP_D = cond1_UP_D + cond2_UP_D + cond3_UP_D + cond4_UP_D;
def cond_DN_D = cond1_DN_D + cond2_DN_D + cond3_DN_D + cond4_DN_D;

rec direction_D =
    if cond_UP_D >= Strategy_Confirmation_Factor and (!Strategy_FilterWithTMO or cond5_UP_D) then 1
    else if cond_DN_D <= -Strategy_Confirmation_Factor and (!Strategy_FilterWithTMO or cond5_DN_D) then -1
    else if !Strategy_HoldTrend and direction_D[1] == 1 and cond_UP_D < Strategy_Confirmation_Factor and cond_DN_D > -Strategy_Confirmation_Factor then 0
    else if !Strategy_HoldTrend and direction_D[1] == -1 and cond_DN_D > -Strategy_Confirmation_Factor and cond_UP_D < Strategy_Confirmation_Factor then 0
    else direction_D[1];

# --------------------------------------------------
# HTF ALIGNMENT
# --------------------------------------------------

def pass1H =
    if !useHTFAlignment or !use1H then 1
    else if direction == 1 and direction_1h == 1 then 1
    else if direction == -1 and direction_1h == -1 then 1
    else 0;

def pass4H =
    if !useHTFAlignment or !use4H then 1
    else if direction == 1 and direction_4h == 1 then 1
    else if direction == -1 and direction_4h == -1 then 1
    else 0;

def passD =
    if !useHTFAlignment or !useDaily then 1
    else if direction == 1 and direction_D == 1 then 1
    else if direction == -1 and direction_D == -1 then 1
    else 0;

def bullishStack =
    (!use1H or direction_1h == 1) and
    (!use4H or direction_4h == 1) and
    (!useDaily or direction_D == 1);

def bearishStack =
    (!use1H or direction_1h == -1) and
    (!use4H or direction_4h == -1) and
    (!useDaily or direction_D == -1);

def htfAligned = pass1H and pass4H and passD;

# --------------------------------------------------
# SIGNALS
# --------------------------------------------------

plot signal_up =
    direction == 1 and
    direction[1] < 1 and
    (!useHTFAlignment or htfAligned);
signal_up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal_up.SetDefaultColor(Color.WHITE);
signal_up.HideBubble();
signal_up.HideTitle();

plot signal_dn =
    direction == -1 and
    direction[1] > -1 and
    (!useHTFAlignment or htfAligned);
signal_dn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
signal_dn.SetDefaultColor(Color.WHITE);
signal_dn.HideBubble();
signal_dn.HideTitle();

# --------------------------------------------------
# CANDLE COLORS
# --------------------------------------------------

AssignPriceColor(
    if Strategy_ColoredCandlesOn then
        if direction == 1 then Color.LIGHT_GREEN
        else if direction == -1 then Color.RED
        else Color.LIGHT_GRAY
    else Color.CURRENT
);

# --------------------------------------------------
# LABELS
# --------------------------------------------------

AddLabel(
    showLabels,
    if direction == 1 then " Bullish "
    else if direction == -1 then " Bearish "
    else " Neutral ",
    if direction == 1 then Color.DARK_GREEN
    else if direction == -1 then Color.DARK_RED
    else Color.DARK_ORANGE
);

AddLabel(
    showLabels and useHTFAlignment and use1H,
    " 1H " + (if direction_1h == 1 then "UP " else if direction_1h == -1 then "DOWN " else "NEUTRAL "),
    if direction_1h == 1 then Color.DARK_GREEN
    else if direction_1h == -1 then Color.DARK_RED
    else Color.YELLOW
);

AddLabel(
    showLabels and useHTFAlignment and use4H,
    " 4H " + (if direction_4h == 1 then "UP " else if direction_4h == -1 then "DOWN " else "NEUTRAL "),
    if direction_4h == 1 then Color.DARK_GREEN
    else if direction_4h == -1 then Color.DARK_RED
    else Color.YELLOW
);

def dailyValid = !IsNaN(direction_D);

AddLabel(
    showLabels and useHTFAlignment and useDaily and dailyValid,
    "D " + (if direction_D == 1 then "UP"
           else if direction_D == -1 then "DOWN"
           else "NEUTRAL"),
    if direction_D == 1 then Color.GREEN
    else if direction_D == -1 then Color.RED
    else Color.GRAY
);

AddLabel(
    showLabels and useHTFAlignment,
    if bullishStack then " HTF BULL STACK "
    else if bearishStack then " HTF BEAR STACK "
    else " HTF MIXED ",
    if bullishStack then Color.DARK_GREEN
    else if bearishStack then Color.DARK_RED
    else Color.YELLOW
);

# --------------------------------------------------
# VERTICAL LINES
# --------------------------------------------------

AddVerticalLine(Strategy_VerticalLinesOn and signal_up, "Buy", Color.LIGHT_GREEN);
AddVerticalLine(Strategy_VerticalLinesOn and signal_dn, "Sell", Color.RED);

# --------------------------------------------------
# ALERTS
# --------------------------------------------------

Alert(signal_up[1], "Buy", Alert.BAR, Sound.DING);
Alert(signal_dn[1], "Sell", Alert.BAR, Sound.DING);
Hey @antwerks it is laggy and also the arrows that are normally there when bars changes color disappeared?
 

Attachments

  • Screen Shot 2026-03-16 at 11.40.48 AM.png
    Screen Shot 2026-03-16 at 11.40.48 AM.png
    176.8 KB · Views: 7
Hey @antwerks it is laggy and also the arrows that are normally there when bars changes color disappeared?
The arrows are still there - I reworked the logic to get rid of the "false" arrows

ALL FOUR indicators must agree.

The 4 indicators:​

IndicatorCondition
AK TrendEMA 3 vs EMA 8
Z-Scoreprice above mean
Ehlersprice above Ehlers filter
Anchored Momentummomentum > 0

So bullish requires:

AK Trend bullish
ZScore positive
Ehlers bullish
Anchored momentum positive


All four must align.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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