Heikin_Ashi Indicator For ThinkOrSwim

@BonBon I'm on the daily chart and it says time frames are wrong. Then the other doesn't even show up.

wWvrYBq.png

Your time frames cannot be lower than the main chart time frame etc. I adapted my script based on the below video and the accompanying script.

 
Based on my previous post, can anyone provide feedback to the below requests?

Feedback from members

I would like feedback from members regarding changing those candles that are “in the trend” but have a different color. (see chart). This would eliminate the number of signals that appear. (especially where there is only one red or green candle in the middle of the current trend. I have tried using strategies such as increasing the lookback period, using the previous candle(s) script but with no success. Please see notes within the chart on the first page.

Also, can someone please provide feedback on how to make the Fib lines shorter. Please see notes within the chart on the first page
 
@hexis777 You have to create separate scripts, load them into the lower chart and select the default time frame. The script is the same...the timeframe at the top is what changes. Check out the video which is posted at thread #41. This will give some clarity.
 
I like the project, I added more fib levels for the HA which are turned off, this script primarily draws the fib levels and creates a sloping line that follows price from the highs to the lows. If you want just the regular fibs just turn the r's off and turn the coefficient on.
Code:
# Auto Fib V1.3
# tomsk
# 11.19.2019
#German_Burrito
# Automatically draws fibonacci retracements using the highest price and lowest price
# from the current view and timeframe.
#
# Fibonacci retracements use horizontal lines to indicate areas of support or resistance
# at the key Fibonacci levels before it continues in the original direction. These levels
# are created by drawing a trendline between two extreme points and then dividing the
# vertical distance by the key Fibonacci ratios of: 23.6%, 38.2%, 50%, 61.8%, 78.6%, and 100%.

# CHANGE LOG
#
# V1.0 - 12.18.2018 - BenTen       - Initial release of Auto Fib, created by Ryan Hendricks
# V1.1 - 11.15.2019 - theelderwand - As script was difficult to read, made the following enhancements
#                                    Expands to right
#                                    Doesn't expand to left
#                                    Custom colors for Fibonacci bars (0.618 is GOLD color)
#                                    Custom line weights
#                                    Code is modularized so you can add extra plots as needed
# V1.2 - 11.15.2019 - tomsk        - Added an input selector for the colors of the label. You
#                                    can select from any of the colors listed - red, orange,
#                                    green, etc and bubbles for all the fib retracements will
#                                    utilize that color.
# V1.3 - 11.19.2019 - tomsk        - Modified the AddChartBubbles to be displayed on the right
#                                    side of the chart. Please ensure that you increase the
#                                    expansion area to that the bubbles have room to be displayed
#                                    Chart Settings > Time Axis > Expansion Area
#
# V1.4 - 1.22.2021 - AspaTrader.   - Modified to show fib levels for HA candles

#hint Price: Price used in the alerts on crossing retracement lines. <b>(Default is Close)</b>

#hint coefficient_0: Retracement Line 0: Retracement from the highest high to the lowest low.<b>(Default is 0%)</b>
#hint Coefficient_1: Retracement Line 1: Retracement from the highest high to the lowest low.<b>(Default is 23.6%)</b>
#hint Coefficient_2: Retracement Line 2: Retracement from the highest high to the lowest low.<b>(Default is 38.2%)</b>
#hint Coefficient_3: Retracement Line 3: Retracement from the highest high to the lowest low.<b>(Default is 50%)</b>
#hint Coefficient_4: Retracement Line 4: Retracement from the highest high to the lowest low.<b>(Default is 61.8%)</b>
#hint Coefficient_5: Retracement Line 5: Retracement from the highest high to the lowest low.<b>(Default is 78.6%)</b>
#hint Coefficient_6: Retracement Line 6: Retracement from the highest high to the lowest low.<b>(Default is 100%)</b>

#wizard input: Price
#wizard text: Inputs: Price:
#wizard input: coefficient_0
#wizard text: coefficient_0:
#wizard input: Coefficient_1
#wizard text: Coefficient_1:
#wizard input: Coefficient_2
#wizard text: Coefficient_2:
#wizard input: Coefficient_3
#wizard text: Coefficient_3:
#wizard input: Coefficient_4
#wizard text: Coefficient_4:
#wizard input: Coefficient_5
#wizard text: Coefficient_5:
#wizard input: Coefficient_6
#wizard text: Coefficient_6:

input period = 50;
input candleSmoothing = {default Valcu, Vervoort};
input slope_adjust_multiplier = 1.00;
input movingAverageType = {default  TEMA, Exponential, Hull };

def slope_adj = slope_adjust_multiplier;
def openMA;
def closeMA;
def highMA;
def lowMA;

switch (movingAverageType) {
case Exponential:
    openMA = CompoundValue(1, ExpAverage(open, period), open);
    closeMA = CompoundValue(1, ExpAverage(close, period), close);
    highMA = CompoundValue(1, ExpAverage(high, period), high);
    lowMA = CompoundValue(1, ExpAverage(low, period), low);
case Hull:
    openMA = CompoundValue(1, HullMovingAvg(open, period), open);
    closeMA = CompoundValue(1,  HullMovingAvg(close, period), close);
    highMA = CompoundValue(1,  HullMovingAvg(high, period), high);
    lowMA = CompoundValue(1,  HullMovingAvg(low, period), low);
case TEMA:
    openMA = CompoundValue(1, TEMA(open, period), open);
    closeMA = CompoundValue(1, TEMA(close, period), close);
    highMA = CompoundValue(1, TEMA(high, period), high);
    lowMA = CompoundValue(1, TEMA(low, period), low);

}


def haOpen;
def haClose;

switch (candleSmoothing){
case Valcu:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0) / 2.0), open);
    haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);
case Vervoort:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0 ) / 2.0), open);
    haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);

}

plot o = haOpen;
o.Hide();

def haLow =  Min(lowMA, haOpen);
def haHigh = Max(highMA, haOpen);

def price = haClose;
def high = haHigh;
def low = haLow;

input coefficient_0 = 0.000;
input Coefficient_1 = .236;
input Coefficient_2 = .382;
input Coefficient_3 = .5;
input Coefficient_4 = .786;
input Coefficient_5 = .618;
input Coefficient_6 = 1.00;






input LabelColor = {default "MAGENTA", "CYAN", "PINK", "LIGHT_GRAY", "ORANGE", "RED", "GREEN", "GRAY", "WHITE"};
input n = 3;

def n1  = n + 1;
def a = HighestAll(haHigh);
def b = LowestAll(haLow);
def barnumber = BarNumber();
def c = if high == a then barnumber else Double.NaN;
def d = if low == b then barnumber else Double.NaN;
rec highnumber = CompoundValue(1, if IsNaN(c) then highnumber[1] else c, c);
def highnumberall = HighestAll(highnumber);
rec lownumber = CompoundValue(1, if IsNaN(d) then lownumber[1] else d, d);
def lownumberall = LowestAll(lownumber);

def upward = highnumberall > lownumberall;
def downward = highnumberall < lownumberall;

def x = AbsValue(lownumberall - highnumberall );

def slope = (a - b) / x;
def slopelow = (b - a) / x;

def day = GetDay();
def month = GetMonth();
def year = GetYear();
def lastDay = GetLastDay();
def lastmonth = GetLastMonth();
def lastyear = GetLastYear();
def isToday = If(day == lastDay and month == lastmonth and year == lastyear, 1, 0);
def istodaybarnumber = HighestAll(if isToday then barnumber else Double.NaN);
def line = b + (slope * (barnumber - lownumber));
def linelow = a + (slopelow * (barnumber - highnumber));
def currentlinelow = if barnumber <= lownumberall then linelow else Double.NaN;
def currentline = if barnumber <= highnumberall then line else Double.NaN;

plot FibFan =  if  downward then currentlinelow else if upward then currentline else Double.NaN;
FibFan.SetStyle(Curve.SHORT_DASH);
FibFan.AssignValueColor(Color.RED);
FibFan.HideBubble();

def range =  a - b;

def value0 = range * coefficient_0;
def value1 = range * Coefficient_1;
def value2 = range * Coefficient_2;
def value3 = range * Coefficient_3;
def value4 = range * Coefficient_4;
def value5 = range * Coefficient_5;
def value6 = range * Coefficient_6;

def condition1 = downward and barnumber >= highnumberall;
def condition2 = upward and barnumber >= lownumberall;

plot Retracement0 = if condition1 then HighestAll(b + value0) else if condition2 then HighestAll(a - value0) else Double.NaN;
plot Retracement1 = if condition1 then HighestAll(b + value1) else if condition2 then HighestAll(a - value1) else Double.NaN;
plot Retracement2 = if condition1 then HighestAll(b + value2) else if condition2 then HighestAll(a - value2) else Double.NaN;
plot Retracement3 = if condition1 then HighestAll(b + value3) else if condition2 then HighestAll(a - value3) else Double.NaN;
plot Retracement4 = if condition1 then HighestAll(b + value4) else if condition2 then HighestAll(a - value4) else Double.NaN;
plot Retracement5 = if condition1 then HighestAll(b + value5) else if condition2 then HighestAll(a - value5) else Double.NaN;
plot Retracement6 = if condition1 then HighestAll(b + value6) else if condition2 then HighestAll(a - value6) else Double.NaN;




def xx = if condition1 then (barnumber - highnumberall) else (barnumber - lownumberall);
def mm = if condition1 then HighestAll((ohlc4 - Retracement6) / xx) else LowestAll((ohlc4 - Retracement6) / xx);

#PLOT FIBS with slope
# Y = MX + B
#y = end value, m = slope = x is time b = beg value
plot r7 = mm * slope_adj * xx + Retracement6;
plot r6 = mm * slope_adj * xx + Retracement5;
plot r5 = mm * slope_adj * xx + Retracement4;
plot r4 = mm * slope_adj * xx + Retracement3;
plot r3 = mm * slope_adj * xx + Retracement3;
plot r2 = mm * slope_adj * xx + Retracement2;
plot r1 = mm * slope_adj * xx + Retracement1;
plot r0 = mm * slope_adj * xx + Retracement0;
Retracement0.AssignValueColor(CreateColor(255, 255, 255));
Retracement0.SetLineWeight(4);
Retracement0.HideBubble();
#AddChartBubble((downward and haClose[n1]) and IsNaN(haClose[n]), retracement0, concat( (coefficient_0 * 100), "%"), GetColor(LabelColor), yes);
#AddChartBubble((upward and haClose[n1]) and IsNaN(haClose[n]), retracement0, concat( (coefficient_0 * 100), "%"), GetColor(LabelColor), yes);


Retracement2.AssignValueColor(CreateColor(0, 197, 49));
Retracement2.SetLineWeight(2);
Retracement2.HideBubble();
#AddChartBubble((downward and haClose[n1]) and IsNaN(haClose[n]), retracement2, concat( (coefficient_2 * 100), "%"), GetColor(LabelColor), yes);
#AddChartBubble((upward and haClose[n1]) and IsNaN(haClose[n]), retracement2, concat( (coefficient_2 * 100), "%"), GetColor(LabelColor), yes);


Retracement4.AssignValueColor(CreateColor(255, 215, 0));
Retracement4.SetLineWeight(5);
Retracement4.HideBubble();
#AddChartBubble((downward and haClose[n1]) and IsNaN(haClose[n]), retracement4, concat( (coefficient_4 * 100), "%"), GetColor(LabelColor), yes);
#AddChartBubble((upward and haClose[n1]) and IsNaN(haClose[n]), retracement4, concat( (coefficient_4 * 100), "%"), GetColor(LabelColor), yes);


Retracement6.AssignValueColor(CreateColor(255, 255, 255));
Retracement6.SetLineWeight(4);
Retracement6.HideBubble();
#AddChartBubble((downward and haClose[n1]) and IsNaN(haClose[n]), retracement6, concat( (coefficient_6 * 100), "%"), GetColor(LabelColor), yes);
#AddChartBubble((upward and haClose[n1]) and IsNaN(haClose[n]), retracement6, concat( (coefficient_6 * 100), "%"), GetColor(LabelColor), yes);

Alert((price crosses below Retracement0) , "Price crosses below Retracement Line 0");
Alert((price crosses above Retracement0) , "Price crosses above Retracement Line 0");
Alert((price crosses below Retracement2) , "Price crosses below Retracement Line 2");
Alert((price crosses above Retracement2) , "Price crosses above Retracement Line 2");
Alert((price crosses below Retracement4) , "Price crosses below Retracement Line 4");
Alert((price crosses above Retracement4) , "Price crosses above Retracement Line 4");
Alert((price crosses below Retracement6) , "Price crosses below Retracement Line 6");
Alert((price crosses above Retracement6) , "Price crosses above Retracement Line 6");
# End Auto Fib v1.3

AddChartBubble((barnumber == istodaybarnumber), Retracement0, Concat( "$", Round(Retracement0, 2)), Color.RED, yes);
AddChartBubble((barnumber == istodaybarnumber), Retracement2, Concat( "$", Round(Retracement2, 2)), Color.RED, yes);
AddChartBubble((barnumber == istodaybarnumber), Retracement4, Concat( "$", Round(Retracement4, 2)), Color.RED, yes);
AddChartBubble((barnumber == istodaybarnumber), Retracement6, Concat( "$", Round(Retracement6, 2)), Color.RED, yes);


r0.setlineWeight(2);
r1.setlineWeight(2);
r2.setlineWeight(2);
r3.setlineWeight(2);
r4.setlineWeight(2);
r5.setlineWeight(2);
r6.setlineWeight(2);
r7.setlineWeight(2);


R0.AssignValueColor(CreateColor(255, 255, 255));
R1.AssignValueColor(CreateColor(255, 255, 25));
R2.AssignValueColor(CreateColor(25, 255, 255));
R3.AssignValueColor(CreateColor(255, 255, 255));
R4.AssignValueColor(CreateColor(5, 215, 25));
R5.AssignValueColor(CreateColor(115, 155, 215));
R7.AssignValueColor(CreateColor(255, 255, 255));

retracement0.Hide();
retracement1.Hide();
retracement2.Hide();
retracement3.Hide();
retracement4.Hide();
retracement5.Hide();
retracement6.Hide();
 
Can you show me your chart along with the script?
BonBon,

Thanks for your help and here you go -

Here is the Code -

Code:
#Heiken_Ashi based on Sylvan Verboort's Trading with HA Candlestick Oscillator
#Bon Bon _last update Jan 17th 2021
#Influenced by script from HoboTheClown / blt,[URL]http://www.thinkscripter.com[/URL], TD Hacolt etc.
#MTF based on HannTech's MTF_MACD script
#update 1/2/21 - changed the default moving average to TEMA.  Changed the period to 35.
#update changed reversal arrows to reversal bubbles with price

### YOU MUST HAVE THE STYLE SETTING FIT STUDIES ENABLED ###
#hint: The style setting Fit Studies must be enabled to use these bars.


input period = 50;
input hideCandles = yes;
input candleSmoothing = {default Valcu, Vervoort};
input show_bubble_labels = yes;
input bubbles = yes;
input arrows = yes;


#input smoothingLength = 3;

input movingAverageType = {default  TEMA, Exponential, Hull };

def openMA;
def closeMA;
def highMA;
def lowMA;

switch (movingAverageType) {
case Exponential:
    openMA = CompoundValue(1, ExpAverage(open, period), open);
    closeMA = CompoundValue(1, ExpAverage(close, period), close);
    highMA = CompoundValue(1, ExpAverage(high, period), high);
    lowMA = CompoundValue(1, ExpAverage(low, period), low);

case Hull:
    openMA = CompoundValue(1, HullMovingAvg(open, period), open);
    closeMA = CompoundValue(1,  HullMovingAvg(close, period), close);
    highMA = CompoundValue(1,  HullMovingAvg(high, period), high);
    lowMA = CompoundValue(1,  HullMovingAvg(low, period), low);

case TEMA:
    openMA = CompoundValue(1, TEMA(open, period), open);
    closeMA = CompoundValue(1, TEMA(close, period), close);
    highMA = CompoundValue(1, TEMA(high, period), high);
    lowMA = CompoundValue(1, TEMA(low, period), low);

}


HidePricePlot(hideCandles);

def haOpen;
def haClose;

switch (candleSmoothing){
case Valcu:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0) / 2.0), open);
    haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);
case Vervoort:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0 ) / 2.0), open);
    haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);

}

plot o = haOpen;
o.Hide();

def haLow =  Min(lowMA, haOpen);
def haHigh = Max(highMA, haOpen);

#Zero Lag System - MetaStock Crossover Formula
#zero-lagging principle
#Zero-lagging TEMA average on closing prices

#Medium-term price reversals - upward trend

def avg = 34;
def TMA1 = reference TEMA(haClose, avg); # triple exponential moving average (TEMA) of 34 bars
def TMA2 =  reference TEMA(TMA1, avg);
def Diff = TMA1 - TMA2;
def ZlHa = TMA1 + Diff; #Zero-lagging TEMA average on closing prices - medium term uptrend;

#Medium-term price reversals - downward trend
def TMA1_ = reference TEMA((high + low) / 2, avg);
def Diff2 = TMA1_ - TMA2;
def ZlCl = TMA1_ + Diff2; #Zero-lagging TEMA average on closing prices - medium term doenwardtrend;

def ZlDif = ZlCl - ZlHa; # Zero-Lag close - Zero-Lag HA(green candle) Uptrend when ZlDif is equal to or greater than zero

#uptrend {green candle}
def keep1 = if (haClose >= haOpen and haClose[1] >= haOpen[1]) then 1 else 0;
def keep2 = if ZlDif >= 0 then 1 else 0;
def keep3 = if (AbsValue(close - open) < ((high - low) * 0.35)) and high >= low[1] then 1 else 0;
def keeping = if (keep1 or keep2) then 1 else 0;
def keepall = if keeping or (keeping[1]) and close >= open or close >= (close[1]) then 1 else 0;

def utr = if keepall or (keepall[1]) and keep3 then 1 else 0;

#downtrend red candle

def keep1_ = if (haClose < haOpen and haClose[1] < haOpen[1]) then 1 else 0;
def keep2_ = if ZlDif < 0 then 1 else 0;
def keep3_ = if (AbsValue(close - open) < ((high - low) * 0.35)) and low <= high[1] then 1 else 0;
def keeping_ = if (keep1_ or keep2_) then 1 else 0;
def dkeepall_ = if keeping_ or (keeping_[1]) and close < open or close < (close[1]) then 1 else 0;

def dtr = if dkeepall_ or (dkeepall_[1] - 1) and keep3_ == 1 then 1 else 0;  #downtrend
def upw = if dtr and (dtr[1]) and utr then 1 else 0;
def dnw = if !utr and (utr[1] ) and dtr then 1 else 0;

def results = if upw then 1 else if dnw then 0 else results[1];

#Change the color of HA and Japanese Candles - turn off to show only HA on chart
AssignPriceColor(if haClose >= haOpen
                 then Color.GREEN else
                 if  haClose < haOpen
                 then Color.RED else Color.WHITE);


#Heiken_A script

#####################################################################################################
input charttype = ChartType.CANDLE;

def haopen_ = if haClose <= haOpen
              then haOpen + 0
             else Double.NaN;

def HAhi   = if haClose <= haOpen
              then haHigh
              else Double.NaN;

def HAlo =   if haClose <= haOpen
              then haLow
              else Double.NaN;


AddChart(growColor = Color.RED, neutralColor = Color.CURRENT, high = HAhi, low = HAlo, open = haopen_, close = haClose, type = ChartType.CANDLE);

def HAclose1 = ohlc4;
def HAopen1  = if haClose >= haOpen
               then CompoundValue(1, (haOpen[1] + haClose[1]) / 2, (open[1] + close[1]) / 2)   
               else Double.NaN;

def haopen_1 = if haOpen <= haClose
               then HAopen1 + 0  else Double.NaN;

def HAhigh1  = haHigh;
def HAlow1   = haLow;


AddChart(growColor = Color.GREEN, neutralColor = Color.CURRENT,  high = HAhigh1, low = HAlow1, open = haopen_1, close = haClose, type = ChartType.CANDLE);

#####################################################################################################
#Buy and sell signals
def trend =  haClose >= haOpen; #high color;
def trendup = trend and !trend[1];
def trendd =  haClose < haOpen;
def trendDown = trendd and !trendd[1];

AddChartBubble(bubbles and trendup and trendup, HAlow1, ("Reversal:"    + round(HAlow1, 2)), Color.GREEN, no);

AddChartBubble(bubbles and trendDown and trendDown, HAhigh1, ("Reversal:"  + round(HAhigh1,2)), Color.LIGHT_RED, yes);
 
teeMG1V.png


I was backtesting reversal indicator. There was a difference in HA reversal(15.92) and candlestick price(16.71). Also, Candlestick was going up but HA was coming down. Is there a way to filter out these entries?
 
@Ghs Can you send the strategy that you used for the backtesting?

@JoeSD did you change the candle type as well to "candle" instead of "heiken ashi" ? Also, if you don't want to have the HA smoothing indicator turn off the "addchart" script.

8xwRnZd.jpg
 
@Ghs

As a reminder the HA plots the average price while the Japanese candlestick plots the actual price. You have to decide which price you will use for your entry and exit. If you wish to plot the regular candlesticks for your entry and exit you will have to change the script to reflect your preference.
 
@Ghs, here is a script for a backtest.
Code:
# Backtest of BonBon Heiken_Ashi
# BonBon 1/24/2021

input period = 50;

def openMA = CompoundValue(1, Average(open, period), open);
def closeMA = CompoundValue(1, Average(close, period), close);
def highMA = CompoundValue(1, Average(high, period), high);
def lowMA = CompoundValue(1, Average(low, period), low);


def  haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0 ) / 2.0), open);
def haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);

def haLow =  Min(lowMA, haOpen);
def haHigh = Max(highMA, haOpen);

def trend = haClose >= haOpen ;
def trendup = trend and !trend[1];

def trendd = haClose < haOpen ;
def trendDown = trendd and !trendd[1];

AddOrder(OrderType.BUY_TO_OPEN, trendup, halow, 100, color.light_green, color.light_green,"BUY");

AddOrder(OrderType.SELL_TO_CLOSE,trenddown, hahigh, 100,color.red, color.red,"SELL");
 
@AspaTrader @germanburrito thank you for your contribution.

This is what I have done regarding the number of signals that occur. I have incorporated the trend reversal posted by @BenTen to reduce the number of signals. The script that is bold refers to the original HA script on the first page. At this time I am looking to write a script whereby signals occur daily as I not only swing trade but day trade as well. If you have created this script please share. I have made some additional changes and will share as soon as they are complete.

Notice the buy and/or sell signal does not appear at each color change. The plum color is neutral.

pbSF5ZJ.jpg


Here, there is no signal on the daily 5 minute chart if a signal triggered previously and certain conditions were met.

7KH31OJ.jpg


Code:
def price = close;
def superfast_length = 21;
def fast_length = 50;
def slow_length = 100;
def displace = 0;
def mah = reference TEMA(haHigh, avg);
def mal = reference TEMA(haLow, avg);

def mov_avg21 = reference TEMA(price[-displace], superfast_length);
def mov_avg50 = reference TEMA(price[-displace], fast_length);
def mov_avg100 = reference TEMA(price[-displace], slow_length);

#moving averages
def Superfast = mov_avg21;
def Fast = mov_avg50;
def Slow = mov_avg100;

def stopbuy = mov_avg21 <= mov_avg50;
def buynow = !buy[1] and buy;
def buysignal = CompoundValue(1, if buynow and !stopbuy then 1 else if buysignal[1] == 1 and stopbuy then 0 else buysignal[1], 0);

def Buy_Signal = buysignal[1] == 0 and buysignal == 1;

#Alert(condition = buysignal[1] == 0 and buysignal == 1, text = "Buy Signal", sound = Sound.Bell, "alert type" = Alert.BAR);

def Momentum_Down = buysignal[1] == 1 and buysignal == 0;

#Alert(condition = buysignal[1] == 1 and buysignal == 0, text = "Momentum_Down", sound = Sound.Bell, "alert type" = Alert.BAR);

def stopsell = mov_avg21 >= mov_avg50;
def sellnow = !sell[1] and sell;
def sellsignal = CompoundValue(1, if sellnow and !stopsell then 1 else if sellsignal[1] == 1 and stopsell then 0 else sellsignal[1], 0);

def Sell_Signal = sellsignal[1] == 0 and sellsignal;

#Alert(condition = sellsignal[1] == 0 and sellsignal == 1, text = "Sell Signal", sound = Sound.Bell, "alert type" = Alert.BAR);

def Momentum_Up = sellsignal[1] == 1 and sellsignal == 0;

#Alert(condition = sellsignal[1] == 1 and sellSignal == 0, text = "Momentum_Up", sound = Sound.Bell, "alert type" = Alert.BAR);

def Colorbars = if buysignal == 1 then 1 else if sellsignal == 1 then 2 else if buysignal == 0 or sellsignal == 0 then 3 else 0;
#Colorbars.Hide();
#Colorbars.DefineColor("Buy_Signal_Bars", Color.GREEN);
#Colorbars.DefineColor("Sell_Signal_Bars", Color.RED);
#Colorbars.DefineColor("Neutral", Color.PLUM);

def HA = ZigZagHighLow("price h" = mah, "price l" = mal, "percentage reversal" = percentamount, "absolute reversal" = revAmount, "atr length" = atrlength, "atr reversal" = atrreversal);
rec HASave = if !IsNaN(HA) then HA else GetValue(HASave, 1);
def chg = (if HASave == mah then mah else mal) - GetValue(HASave, 1);
def isUp = chg >= 0;
def HA_L = if !IsNaN(HA) and !isUp then mal else GetValue(HA_L, 1);
def HA_H = if !IsNaN(HA) and isUp then mah else GetValue(HA_H, 1);
def dir = CompoundValue(1, if HA_L != HA_L[1] or mal == HA_L[1] and mal == HASave then 1 else if HA_H != HA_H[1] or mah == HA_H[1] and mah == HASave then -1 else dir[1], 0);
def signal = CompoundValue(1, if dir > 0 and mal > HA_L then if signal[1] <= 0 then 1 else signal[1] else if dir < 0 and mah < HA_H then if signal[1] >= 0 then -1 else signal[1] else signal[1], 0);

def showarrows = yes;
def barnumber = BarNumber()[10];
def U1 = showarrows and signal > 0 and signal[1] <= 0;
def D1 = showarrows and signal < 0 and signal[1] >= 0;

# Plot Signals
def bull = signal > 0 and signal[1] <= 0;
#bull.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#bull.SetDefaultColor(Color.YELLOW);
#bull.SetLineWeight(2);

def bear = signal < 0 and signal[1] >= 0;
#bear.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#bear.SetDefaultColor(Color.YELLOW);
#bear.SetLineWeight(2);

#Buy Signal
AddChartBubble((barnumber and U1), if isUp then halow1 else hahigh1, if showarrows and signal > 0 and signal[1] <= 0 then "Reversal:" + round(halow1,2) else "" , if Colorbars == 3 then Color.PLUM else Color.UPTICK, no);

#Sellsignal
AddChartBubble((barnumber and D1), if isUp then halow1 else hahigh1, if showarrows and signal < 0 and signal[1] >= 0 then "Reversal:" + round(hahigh1,2) else "" , if Colorbars == 3 then Color.PLUM else Color.DOWNTICK, yes);
 
Last edited:
@BonBon Yes, I had the appearance set as you showed??? Not sure why I ONLY see the HA Smoothed and not the regular charts.???
@JoeSD I took a look at your code once again. It appears you might have your candles hidden. You must change your "hidecandles" to "no" if you want to see the candles. You have it as "yes".

input hidecandles = no;
 
@JoeSD I took a look at your code once again. It appears you might have your candles hidden. You must change your "hidecandles" to "no" if you want to see the candles. You have it as "yes".

input hidecandles = no;
BonBon, Yes that took care of it and thanks again. Joe

Is there a version where the HA smoothed is just a line (as opposed to a candle with wicks)? I have checked the forum and couldn't come up with one...? Thanks.

I like this version with the purple. Can you make one where the smoothed HA is a line (not candles with wicks)?

thanks.
 
@JoeSD I am not sure. However, you could turn off the smoothed HA by placing an hashtag in front of the "addchart ", turn on the assignpricecolor by removing the hashtag (if it is turned off) and change the candle in the "chart setting" to "Line" instead of "candle"
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
181 Online
Create Post

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