Posted By: kandlekid
Smoothed HA attempt - 04/30/22 20:28
Hello All,
I've been attempting to code a Smoothed HA indicator for the last few weeks without any success. I thought I'd try to code one version from TradingView, since
it seems to be the most straightforward (https://www.tradingview.com/script/ROokknI2-Smoothed-Heiken-Ashi-Candles-v1/ ). Here is what I have so far:
This results in the following chart (see attached file below). Obviously not what is wanted. How can I get the Smoothed Ha chart?
Anyway, the only other attempt I've found on the Zorro forums is one attempting to code an MT4 indicator in lite-C, which also failed:
https://opserver.de/ubb7/ubbthreads.php?ubb=showflat%20&Number=462807
I've been attempting to code a Smoothed HA indicator for the last few weeks without any success. I thought I'd try to code one version from TradingView, since
it seems to be the most straightforward (https:/
Code
// Attempt to code the smoothed HA indicator from TradingView in // Lite-c. See: https://www.tradingview.com/script/ROokknI2-Smoothed-Heiken-Ashi-Candles-v1/ // // #define LEN 10 #define LEN2 10 vars Open, High, Low, Close; vars maOpen, maClose, maHigh, maLow; vars haOpen, haClose, haHigh, haLow; vars O2, C2, H2, L2; int run() { Open = series(priceOpen()); High = series(priceHigh()); Low = series(priceLow()); Close = series(priceClose()); ColorUp = GREEN; ColorDn = RED; BarPeriod = 60; } int bar( vars Open, vars High, vars Low, vars Close ) { maOpen = series(EMA(Open,LEN)); maClose = series(EMA(Close,LEN)); maHigh = series(EMA(High,LEN)); maLow = series(EMA(Low,LEN)); // Allocate space for the two series. haClose = series(Close[0]); haOpen = series(Open[0]); // Compute values. haClose[0] = (maOpen[0]+maHigh[0]+maLow[0]+maClose[0]) / 4; if ( Bar == 0 ) { haOpen[0] = ( maOpen[0] + maClose[0] ) / 2 ; } else if ( Bar > 0 ) { haOpen[0] = ( haOpen[1] + haClose[1] ) / 2 ; } haHigh = series(max(maHigh[0],max(haOpen[0],haClose[0]))); haLow = series(min(maLow[0],min(haOpen[0],haClose[0]))); O2 = series(EMA(haOpen,LEN2)); C2 = series(EMA(haClose,LEN2)); H2 = series(EMA(haHigh,LEN2)); L2 = series(EMA(haLow,LEN2)); Open[0] = O2[0]; Close[0] = C2[0]; High[0] = H2[0]; Low[0] = L2[0]; return 8; }
This results in the following chart (see attached file below). Obviously not what is wanted. How can I get the Smoothed Ha chart?
Anyway, the only other attempt I've found on the Zorro forums is one attempting to code an MT4 indicator in lite-C, which also failed:
https:/