a problem with heikin-ashi formula

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #202560 quote
    gnellas77
    Participant
    Average

    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.

    #202567 quote
    Nicolas
    Keymaster
    Master

    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.

    gnellas77 thanked this post
    #202597 quote
    gnellas77
    Participant
    Average

    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]
    #202599 quote
    JS
    Participant
    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]
    gnellas77 thanked this post
    #202615 quote
    gnellas77
    Participant
    Average

    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!!!

    #202634 quote
    JS
    Participant
    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.

    gnellas77 thanked this post
    #202657 quote
    Nicolas
    Keymaster
    Master
    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
    gnellas77 thanked this post
    #202745 quote
    gnellas77
    Participant
    Average
    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!!!
    JS thanked this post
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.

a problem with heikin-ashi formula


ProScreener: Market Scanners & Detection

New Reply
Author
author-avatar
gnellas77 @gnellas77 Participant
Summary

This topic contains 7 replies,
has 3 voices, and was last updated by gnellas77
3 years, 5 months ago.

Topic Details
Forum: ProScreener: Market Scanners & Detection
Language: English
Started: 10/14/2022
Status: Active
Attachments: No files
Logo Logo
Loading...