thought as much, but all i get are a bunch of errors, so i must be doing something boneheaded. if you get a moment, could you have a look-see at my code; conversely, i'll keep on trying to sort it out myself. thanks!
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,http://www.thinkscripter.com, 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);
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);