#macd_hull_ashi_signals
#https://usethinkscript.com/threads/macd-and-hull-ma-indicators-for-signals.20391/
#MACD and Hull MA indicators for signals
#Dr. Dave 1/20
#1
# buy signals,
# HMA 10 20 cross up and both with positive slope up.
# This is confirmed by MACD above signal line and both at or above the zero line.
# Signals remain bullish as long as stock continues up, 10/20 HMA's are green and up, and MACD is going up and remains above signal and zero line. Heikin-Ashi candles used here for green is entry Exit or short entry is tirggered by HMA's with 20 over 10 period, and confirmed by MACD below signal line, (downward slope of both lines), Helkin-Ashi red candle confirms red arrow down and exit of the trade or short entry.
#Here is the script per ChatGPT to produce this:
# Pseudo-code for Buy and Sell signals based on your conditions
# Calculate HMA
#def HMA(price, period):
# Calculate Hull Moving Average for the given period
#return hull_moving_average(price, period)
# MACD Calculation
#def MACD(price, fast_period, slow_period, signal_period):
# Calculate MACD line and Signal line
#macd_line = macd(price, fast_period, slow_period)
#signal_line = signal(macd_line, signal_period)
#return macd_line, signal_line
# Determine Entry Signal (Buy)
#def check_entry(price, hma_10, hma_20, macd_line, signal_line):
# Check if HMA 10 crosses above HMA 20 with positive slope for both HMAs
#if hma_10 > hma_20 and is_positive_slope(hma_10) and is_positive_slope(hma_20):
# Check if MACD is above the signal line and both are above zero line
#if macd_line > signal_line and macd_line > 0 and signal_line > 0:
# Check if Heikin-Ashi candle is green (bullish)
#if is_heikin_ashi_green():
#return "Buy Signal - Green Arrow"
#return None
# Determine Exit Signal (Sell)
#def check_exit(price, hma_10, hma_20, macd_line, signal_line):
# Check if HMA 20 crosses above HMA 10 with negative slope for both HMAs
#if hma_20 > hma_10 and is_negative_slope(hma_20) and is_negative_slope(hma_10):
# Check if MACD is below the signal line and both are sloping downward
#if macd_line < signal_line and macd_line < 0 and signal_line < 0:
# Check if Heikin-Ashi candle is red (bearish)
#if is_heikin_ashi_red():
#return "Sell Signal - Red Arrow"
#return None
#-------------------
def na = double.nan;
def bn = barnumber();
#-------------------
# avgs
#https://toslc.thinkorswim.com/center/reference/thinkScript/Constants/AverageType
#input avg1_type = AverageType.Simple;
#input avg1_type = AverageType.exponential;
#input avg1_type = AverageType.hull;
#input avg1_type = AverageType.weighted;
#input avg1_type = AverageType.wilders;
def data = close;
def stk_up = data > data[1];
def stk_dwn = data < data[1];
input avg1_type = AverageType.hull;
input avg1_length = 10;
def avg1 = MovingAverage(avg1_type, data, avg1_length );
input avg2_type = AverageType.hull;
input avg2_length = 20;
def avg2 = MovingAverage(avg2_type, data, avg2_length );
# long - HMA 10 20 cross up and both with positive slope up.
# crossing averages is the driver
def xup = avg1 crosses above avg2;
def xdwn = avg1 crosses below avg2;
def avg1_slope_up = avg1 > avg1[1];
def avg1_slope_dwn = avg1 < avg1[1];
def avg2_slope_up = avg2 > avg2[1];
def avg2_slope_dwn = avg2 < avg2[1];
input show_avg_lines = yes;
plot zavg1 = if show_avg_lines then avg1 else na;
plot zavg2 = if show_avg_lines then avg2 else na;
zavg1.SetDefaultColor(Color.cyan);
zavg1.setlineweight(1);
zavg1.hidebubble();
zavg2.SetDefaultColor(Color.yellow);
zavg2.setlineweight(1);
zavg2.hidebubble();
def avg_long_enter = xup and avg1_slope_up and avg2_slope_up;
def avg_short_enter = xdwn and avg1_slope_dwn and avg2_slope_dwn;
#-------------------
# macd
#declare lower;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;
def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);
def Diff = Value - Avg;
def ZeroLine = 0;
def UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
def DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;
# long - MACD above signal line and both at or above the zero line. value > avg
def m_valueup = value > avg;
def m_value_above0 = value >= 0;
# short - MACD below signal line and both at or below the zero line. value < avg
def m_valuedwn = value < avg;
def m_value_below0 = value <= 0;
def macd_long_enter = m_valueup and m_value_above0;
def macd_short_enter = m_valuedwn and m_value_below0;
#---------------------
# arrows for entering trade . green up for long , green down for short
input show_avg_enter = yes;
plot zavg_le = show_avg_enter and avg_long_enter and macd_long_enter;
#zavg_le.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
zavg_le.SetPaintingStrategy(PaintingStrategy.boolean_ARROW_UP);
zavg_le.SetDefaultColor(Color.cyan);
zavg_le.setlineweight(2);
zavg_le.hidebubble();
plot zavg_se = show_avg_enter and avg_short_enter and macd_short_enter;
#zavg_se.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_down);
zavg_se.SetPaintingStrategy(PaintingStrategy.boolean_ARROW_down);
zavg_se.SetDefaultColor(Color.yellow);
zavg_se.setlineweight(2);
zavg_se.hidebubble();
#