Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by M_D. 04/26/24 20:22
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (M_D, AndrewAMD, Quad, Ayumi), 806 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Smoothed HA attempt #485864
04/30/22 20:28
04/30/22 20:28
Joined: Dec 2012
Posts: 34
New York
K
kandlekid Offline OP
Newbie
kandlekid  Offline OP
Newbie
K

Joined: Dec 2012
Posts: 34
New York
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:

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://opserver.de/ubb7/ubbthreads.php?ubb=showflat%20&Number=462807

Attached Files
x.jpg (51 downloads)
Last edited by kandlekid; 04/30/22 20:45. Reason: Add chart.
Re: Smoothed HA attempt [Re: kandlekid] #485865
05/01/22 07:29
05/01/22 07:29
Joined: Apr 2008
Posts: 586
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 586
Austria
Your code looks very complicated, and you have double variable names and generate price series in a bar function where they do not belong. HA uses the normal bar period so a bar function is not needed anyway. Use the run function for calculating the HA candles. Or use the normal HA functions and simply smooth them with EMA.

HAOpenSmooth = EMA(HAOpen(),10);


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1