hi gentlemen,
i have a question, i have written a simple code to detect inside bars of the same colour on heiken-ashi.
but the screener, i think, sometimes give me inconsistent results. below are the formulas that i use.
can you check it out for me where i did wrong for example? or it’s the fault of screener?
//inside candle of HA, long or short
myhaopen = CALL "ha-open"
myhaclose = CALL "ha-close"
//go long
c1 = myhaopen > myhaclose
c2 = myhaopen[1] > myhaclose[1]
c3 = myhaopen < myhaopen[1]
c4 = myhaclose > myhaclose[1]
//go short
c6 = (c1 and c2 and c3 and c4)
c7 = myhaopen < myhaclose
c8 = myhaopen[1] < myhaclose[1]
c9 = myhaopen > myhaopen[1]
c10 = myhaclose < myhaclose[1]
c12 = (c7 and c8 and c9 and c10)
screener [c6 or c12]
c1 = (open[1]+close[1])/2
return (c1)
c1 = (open+close+high+low)/4
return (c1)
thank you.
This is not the correct formula for Heikin Ashi candlesticks, please use the one below:
xClose = (open+high+low+close)/4
if BarIndex=0 THEN
xOpen = open
xHigh = high
xLow = low
else
xOpen = (xOpen[1] + xClose[1])/2
xHigh = Max(Max(high, xOpen), xClose)
xLow = Min(Min(low, xOpen), xClose)
endif
Xopen and Xclose in your case.
one final question: yes now the formula works but does not include dojis. i put the equal sign but again it does not work (for the dojis).
for example on 14/10/2022 doesnot show BRENNTAG stock on dax40.
where am i wrong? thank you!
//inside bar on S+R of the same color on H.A.
//real formula for open+close of H.A.
xClose = (open+high+low+close)/4
if BarIndex=0 THEN
xOpen = open
else
xOpen = (xOpen[1] + xClose[1])/2
endif
//go long
c1 = xOpen >= xClose
c2 = xOpen[1] > xClose[1]
c3 = xOpen < xOpen[1]
c4 = xClose > xClose[1]
c6 = (c1 and c2 and c3 and c4)
//go short
c7 = xOpen <= xClose
c8 = xOPen[1] < xClose[1]
c9 = xOpen > xOpen[1]
c10 = xClose < xClose[1]
c12 = (c7 and c8 and c9 and c10)
screener [c6 or c12]
JSParticipant
Veteran
Hi @gnellas77
Try this one…
//inside bar on S+R of the same color on H.A.
//real formula for open+close of H.A.
xClose = (open+high+low+close)/4
if BarIndex=0 THEN
xOpen = open
else
xOpen = (xOpen[1] + xClose[1])/2
endif
xHigh = Max(Max(high, xOpen), xClose)
xLow = Min(Min(low, xOpen), xClose)
DojiSize = 0.05
//go long
c1 = (abs(xOpen - xClose) <= (xHigh - xLow) * DojiSize)
c2 = xOpen[1] > xClose[1]
c3 = xOpen < xOpen[1]
c4 = xClose > xClose[1]
c6 = (c1 and c2 and c3 and c4)
//go short
c7 = (abs(xOpen - xClose) <= (xHigh - xLow) * DojiSize)
c8 = xOPen[1] < xClose[1]
c9 = xOpen > xOpen[1]
c10 = xClose < xClose[1]
c12 = (c7 and c8 and c9 and c10)
screener [c6 or c12]
now it catches the pure doji of BRENNTAG and the small doji of FRESENIUS but misses SYMRISE and DELIVERY HERO which have an inside bar of the same colour. That was the objective from the beginning to catch both inside bars and dojis at the same time.
i would like to have one formula for both cases. Do i have to use them seperately? by the way are the variables of xHigh and xLow necessary once i m only interested in the bodies of the candles?
thank you!!!
JSParticipant
Veteran
The body of the Doji is theoretically equal to zero when the Close = Open.
However, this will rarely (never?) occur and that is why you express the body of the Doji in a percentage of the range (xHigh – xLow).
For the inside bar you first have to determine whether you are looking for a “Bull Candle (xOpen < xClose)” or a “Bear Candle (xOpen > xClose)”.
So, you have to add an extra condition.
Examples of Doji spotted with Heikin Ashi formula, and with percentage of body compared to the range:
Heikin-Ashi Doji candle
Heikin Ashi Doji screener
ok mr. js finally i made it. a combo was needed. my brains stuck for a while. your code i thought it was a repetition of mine to some extend.
your help was very useful. thank you very much!!!