Three Heiken-Ashi candles inside range of first


Category:
0
0

Hi Pete  and all-  I’m trying to create a HA scan  for  prev 4  candles.

The below code works fine..but it does not give the correct results. I know there are some stocks that fit that criterion.

*********************************

def C0 = ohlc4;
def O0 = (open[1] + close[1]) / 2;
def H0= Max(high, Max( C0, O0));
def L0= Min(low, Min( C0, O0));

def C1= (open[1] +high[1] +Low[1]+ close[1])/4;
def O1= (open[2] + close[2]) / 2;
def H1=Max(high, Max( C1, O1));
def L1 = Min(low, Min( C1, O1));

def C2= (open[2] +high[2] +Low[2]+ close[2])/4;
def O2= (open[3] + close[3]) / 2;
def H2=Max(high, Max( C2, O2));
def L2 = Min(low, Min( C2, O2));

def C3= (open[3] +high[3] +Low[3]+ close[3])/4;
def O3= (open[4] + close[4]) / 2;
def H3=Max(high, Max( C3, O3));
def L3 = Max(high, Max( C3, O3));

def C4= (open[4] +high[4] +Low[4]+ close[4])/4;
def O4= (open[5] + close[5]) / 2;
def H4=Max(high, Max( C4, O4));
def L4 =Min(high, Min( C4, O4));

def C5= (open[5] +high[5] +Low[5]+ close[5])/4;
def O5= (open[6] + close[6]) / 2;
def H5=Max(high, Max( C5, O5));
def L5 = Min(high, Min( C5, O5));

Plot symbls=

volumeAvg(5)>15000 and
H3>H2 and H3>H1 and H3>H0 and L3<l2 and L3<L1 and L3<L0

and close >5 within 8 bars;

*********************************

 

Is  there anything wrong with the  Heikin Definitions for the 4  prev bars.?

Thanks for your time.

D

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on April 22, 2020 8:40 am
152 views
0
Private answer

"Working fine" "does not give correct results" are a bit of a contradiction. There is a much simpler way to write that code. But I cannot fix this without you fully describing what the code is supposed to do. Since the code does not give correct results I cannot read it to determine what is wrong. You will have to explain exactly what the code was supposed to do.

"HA scan for prev 4 candles" does not provide sufficient detail. I have no idea what this means.

Edit: After receiving clarification in the comment section below I believe I understand the request and have a solution. I also updated the question title to better reflect the context of how I understand this request. State in my own words. The request is for a four bar pattern in which three consecutive Heiken-Ashi candles are within the range of the first. Here is the code to accomplish that:

def haClose = ohlc4;
def haOpen = if haOpen[1] == 0 then haClose[1] else (haOpen[1] + haClose[1]) / 2;
def haHigh = Max(high, Max(haClose, haOpen));
def haLow = Min(low, Min(haClose, haOpen));
def highOfFirstCandle = haHigh[3];
def lowOfFirstCandle = haLow[3];
def threeInsideCandles = Highest(haHigh, 3) < highOfFirstCandle and Lowest(haLow, 3) > lowOfFirstCandle;
plot scan = threeInsideCandles;

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on April 22, 2020 3:48 pm
0
Hi Pete- All I'm looking for is the 3 consecutive candles within the 4th one including the highs and lows. for ex: on the hourly..the first candle..8:30 to 9:30 AM shld encompass the next 3 hours including their highs and lows. This is all I'm looking for.From various other posts on this forum, I had those definitions for Heikin Ashi candles 01,2,3, 4 defined that way. Please let me know if there is an easier way to achieve the same result. Thanks for your time. Thanks.
( at April 23, 2020 7:19 am)
0
Thanks for the clarification. I have updated my answer to provide the solution for the request as I understand it.
( at April 23, 2020 8:36 am)
0
Thanks much Pete. That works. Awesome. __/\__
( at April 23, 2020 12:11 pm)