Code for percentage from Candlestick

Forums ProRealTime English forum ProScreener support Code for percentage from Candlestick

Viewing 9 posts - 1 through 9 (of 9 total)
  • #47713

    Hi, Next question in my programming career :-).

    What is the code for dividing a candlestick or bar in a percentage, if there is any?

    I need this for the coding of a piercing pattern. (the second candle is piercing for more than 50% into the first).

    Thank you………..

    #47730
    AVT

    There is an indicator with a lot of candle patterns, also good for source code reading/learning, that’s here:

    https://www.prorealcode.com/prorealtime-indicators/candlesticks-patterns-indicator/

    Have fun exploring it.

    #47811

    @AVT, Thanks for thinking with me. I already know this indicator, but cannot manage to fathom it yet.

    #47845
    AVT

    @Marcel give me a little time and I will see how I best help you.

    #47866
    AVT

    In your first post you wrote you need that for a piercing pattern. (Just in case: the “master of candles” has decribed it here: http://thepatternsite.com/Piercing.html). Before beginning to code I sometimes make a little sketch, just to see what is needed, like this:

    • Condition for bar one: down bar
    • Definition pierce: middle of body bar one
    • Condition for bar two: open below bar ones low and close higher than piercing line and below bar ones open

     

    Now as we broke down the task into small pieces, we can make a simple code. To make it general we define the reference bar number as n.

    Condition for bar one, being n+1: condition1=( open[n+1]-close[n+1]>0 )

    Definition pierce, middle of the body, the body is: body1=open[n+1]-close[n+1]
    Middle of it, simple devide by 2: middle1=body1/2
    Value of the middle, add half of the body to close: middle1price=middle1+close[n+1]
    All put together: pierce=(open[n+1]-close[n+1])/2+close[n+1]

    Condition for bar two, being n, open below bar ones low: open[n]<low[n+1]
    and close higher than pierce: close[n]>pierce
    and close below bar ones open: close[n]<open[n+1]
    All together: condition2=( (open[n]<low[n+1]) AND (close[n]>pierce) AND (close[n]<open[n+1]) )
    One thing missing, define what value n is: n=0

    Now let’s have a look into that complicated code of the candlesticks-patterns-indicator. The pattern has this code:

    First we need to read the whole line to see how candles are counted: we see bare names like “open” or “close” and indexed names like “body[1]” or “low[1]”. This means when comparing to our version the bare names correspond to our “[n]” and the indexed ones to our “[n+1]”. On my sketch I would just paint another “timeline”:

    We can break it into pieces now. First question here, what is body? Seems to be some selfdefined stuff, usually those things can be found before they are used, so we scroll a bit up and find all those definitions:

    With this at hand we analyse

    In our example we did not see whether both bars are longcandles, nor did we look at the trend condition. Both should be considered as they are in the candlesticks-patterns, longcandle because it performs better and because its shape might interfere with another candle type; and trend because a candle pattern is only valid if certain trend conditions are met. But this is just an example of how to break down problems into smaller pieces and make a code from that. So no need for a 50% value (which is by the way calculated as value50percent=OfWhichValue*0.5).

    Pitfalls: Decide just for one way of caculating the body and stick to that. It’s a matter of view: if I look at the close first and then at where we started opening, I use close-open; if I look at the open first and then where we finally end up closing, I use open-close; depending on that the result is above/below zero the opposite way.

    General versus simple version: Our example is in code a bit longer than the one of the candlesticks-patterns because we use a general version. In an indicator where you need this only once, it is shorter to use the simple version. I prefer to write all my stuff if possible in general form; this needs to set n=ReferencePoint but with that I can for example let the user define what “n” should be, or if I need the code in a loop or IF condition where I do some other calculation, I can simply copy and paste it. Example: Let’s assume this piercing pattern works and it’s best to let it run for 10 bars and then exit. As we cannot future our code, we must look back while our bars run forward. If we set n=10 that means the 10th bar before our current bar pierced and we can now set at our current bar a marker for exit, if we set it n=9 or =8 we include some reaction time.

    Hope I did not include a mistake in this long stuff 😉 and it helps you a bit to do the remaining tasks for your piercing.

    2 users thanked author for this post.
    #48199

    @AVT, Thanks for this detailed explanation. It will take me a while before I have translated it in for me understandable pieces, but I am sure I gonna get the piercing pattern screener working with it.

     

     

    #48212

    @AVT, If I understand your explaination correctly, this should be the code for the Dark Cloud Cover pattern (The opposit of the Piercing pattern).

    Would you please be so kind to check this for me, so I know I am on te right track?

     

    #48226
    AVT

    You are on the way of getting it, some corrections (don’t lose hope, I am fighting this thing called “logic” more than once in new code)
    Bulkowski: Look for two candles in an upward price trend.
    The first candle is a tall white one
    followed by a black candle with an opening price above the top of the white candle
    (an opening price above the prior high),
    but a close below the mid point of the white body.

    |
    —<–open —12425 |
    | <–high |X| —12415 |
    ^ —<–close –|X| ——— —12400 |– pierce=close+middle=12400+(-75)=12325
    | | | |X| |
    | | |<–pierce–|X|———- —? ——|—12325
    | | | |X| | middle=(-150)/2=(-75)
    | —<–open — —<–close —12250 |– body=open-close=12250-12400=(-150)
    | |

    bar1=n+1 <— bar2=n reference bar
    white bar black bar

    pierce=(open[n+1]-close[n+1])/2 + close[n+1]
    white=open[n+1]-close[n+1]<0
    bar2: open[n]>high[n+1] and
    close[n]<pierce and
    close[n]>open[n+1]

    n=0;
    pierce=(close[n]<open[n+1])/2+close[n+1] // (open[n+1]-close[n+1])/2 =>cannot divide close<open by 2
    C5= (close[n]<open[n+1]) // > =>below mid point of white body<–ends at open, so must be still above
    and (close[n]<pierce) // ok
    and (open[n+1]-close[n+1]>0 // <0 =>first candle goes up, open-close becomes negative
    and (open[n]<low[n+1])) // >high[n+1] =>open above the top=high of white
    Screener [C5]

    open-close>0 black candle (reminder: you need more black color)
    open-close<0 white candle (reminder: you need less black color)

     

    1 user thanked author for this post.
    #48244

    @AVT, Thank you for your help again…….

Viewing 9 posts - 1 through 9 (of 9 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login