4-Candlestick pattern detection

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #92778 quote
    carlo__
    Participant
    Average

    Dear all,

    Please help me to develop the following detection system.

    The pattern is based on 4 candles in sequence. Here the requirements/parameters in example:

    1)First candle must have a size = *multiplier* of ATR (let’s assume 1,2*ATR(20)) and 60% of his Volume must be constituted by the body.

    2)Second candle must have the same direction of the previous one (so, both green or red) and must have the same features with 20% of tolerance (so, 1,2*ATR +/20% and/or 60% +/-20% of body over total). 20% is considered on 60% value (so, equal to +/- 12% in this example)

    3)The third Candle has to be “opposite” (so, for 2 green, it must be red or vise versa) and must engulf the previous candle (it must close above or below, i don’t care about high or low)

    4)The fourth one needs just to make a new low (if third is red) or new high (if third is green) to validate the pattern. No additional requirements needed.

    Please, i need an indicator which allow me to customize the parameters explained without modifying the code (i don’t know coding language). So, parameters customizable for each first 2 candles are:

    • ATR period;
    • ATR Multiplier (from 0,1 to 3 is enough);
    • Body % over total size (i used 60% in this case, but should be customizable as described);
    • Tolerance %.

     

    Thanks for help!

    #92780 quote
    robertogozzi
    Moderator
    Master

    This is the code I wrote. I only tested it for syntax errors.

    I attach the ITF file to be imported into ProBuilder.

    DEFPARAM CalculateOnLastBars = 10000
    //AtrMultiplier = 1.20        //1.20   ATR multiplier
    //BodySize      = 0.60        //60%    minimum Body size (compared to Range)
    //Tolerance     = 0.20        //20%    tolerance
    MaxTolerance  = 1 + Tolerance
    MinTolerance  = 1 - Tolerance
    Body          = abs(close - open)
    MaxBody       = BodySize * MaxTolerance
    MinBody       = BodySize * MinTolerance
    Bullish       = close > open
    Bearish       = close < open
    MyAtr         = AverageTrueRange[14](close) * AtrMultiplier
    MyAtrMax      = MyAtr * MaxTolerance
    MyAtrMin      = MyAtr * MinTolerance
    Candle1       = (range[3] >= MyAtr[3]) AND (Body[3] >= (range[3] * BodySize))
    Candle2       = (Bullish[3] AND Bullish[2]) OR (Bearish[3] AND Bearish[2])
    Candle2       = Candle2 AND ((range[2] >= MyAtrMin[2]) AND (range[2] <= MyAtrMax[2]))
    Candle2       = Candle2 AND ((Body[2] <= (range[2] * MaxBody)) AND (Body[2] >= (range[2] * MinBody)))
    Candle3       = (Bullish[3] AND Bullish[2] AND Bearish[1]) OR  (Bearish[3] AND Bearish[2] AND Bullish[1])
    IF Bullish[3] THEN
       Candle3    = (Candle3 AND (close[1] < open[2]))
    ELSIF Bearish[3] THEN
       Candle3    = (Candle3 AND (close[1] > open[2]))
    ELSE
       Candle3    = 0
    ENDIF
    Candle3       = (Candle3 AND (range[1] >= MyAtr))
    Candle4       = ((Bullish[1]) AND (high > high[1])) OR ((Bearish[1]) AND (low < low[1]))
    Result        = Candle1 AND Candle2 AND Candle3 AND Candle4
    RETURN Result

    When you post your feedback, in case of unexpected results, please post:

    • instrument
    • TF used
    • value set with the indicator properties for the three variables
    • opentime/date of the candle when the pattern has incorrectly been reported or when it should have been correctly reported.

    Thank you.

    Il-Mio-Indicatore-ATR.itf
    #92799 quote
    carlo__
    Participant
    Average

    Buongiorno Roberto,

    Ho importato l’indicatore. Dovrebbe visualizzarmi il pattern anche nei dati storici vero? Non solo su quelli in real time?

    Ad un primo acchitto non vedo nessuna segnalazione di pattern conforme. Cmq adesso farò delle prove e le farò saprere. Intanto ringrazio

     

    PS

    Come dovrei visualizzare il pattern? Intendo…c’è una colorazione speciale delle quattro candele? Una freccia? Grazie

    Good morning Roberto,

    I imported the indicator. Should the pattern be displayed in historical data too? Not only on those in real time?

    At first glance I do not see any conformal pattern signaling. Anyway now I will do some tests and I will let them know. Meanwhile, thank you

    PS

    How should I view the pattern? I mean … is there a special coloring of the four candles? An arrow? Thank you

    #92800 quote
    carlo__
    Participant
    Average

    Nel frattempo allego un immagine in cui mi “aspettavo” una segnalazione.

     

    Dax 5 min TF, 25/02/2019 ore 15:30. Ho impostato ATR a 0,01 e Body a 0,2 per ridurre al “minimo” il filtraggio. Tolerance sempre a 0,2.

    A me a occhio pare che il pattern rispetti a pieno i requisiti. L’ellisse è disegnata un pò male, taglia la quarta candela che cmq di fatto va sotto la terza, che engulfa perfettamente la seconda.

    Inoltre mi pare che l’ATR non sia modificabile in periodi (mi serve customizzabile)

    Grazie

    In the meantime I am attaching an image in which I “expected” a report.

    Dax 5 min TF, 25/02/2019 at 15:30. I set ATR to 0.01 and Body to 0.2 to reduce filtering to “minimum”. Tolerance always at 0.2.

    It seems to me that the pattern fully complies with the requirements. The ellipse is drawn a little bad, cut the fourth candle that cmq actually goes under the third, which engulfs the second perfectly.

    Also I think that the ATR is not editable in periods (I need customizable)

    Thank you

    DXMXXXX_8-5-Minuti.png DXMXXXX_8-5-Minuti.png
    #92804 quote
    carlo__
    Participant
    Average

    Altra immagine migliorata con parametri abbassati per evitare eccessivo filtraggio

    Another image improved with lowered parameters to avoid excessive filtering

    Cattura.jpg Cattura.jpg
    #92806 quote
    robertogozzi
    Moderator
    Master

    Please speak english on the english forum.

    #92807 quote
    robertogozzi
    Moderator
    Master

    The indicator returns a line having values of either 0 or 1, so it will look like a triangle when a pattern is detected.

    I can draw arrows on the price chart, if you prefer.

    I will add a variable for the ATR.

    I will also take a look at your pics later this evening or tomorrow morning.

    #92817 quote
    carlo__
    Participant
    Average

    The triangle is a nice choice, thank you.

     

    Yeah, i need atr parameter. Please check images, they seems to match the requirements.

     

    Thanks

    #92940 quote
    carlo__
    Participant
    Average

    Hello Roberto,

    Any news about small fixes for the indicator?

     

    Thanks

    #92952 quote
    robertogozzi
    Moderator
    Master

    This is version 2:

    //-----------------------------------------------------------------------------------------------------------------------------------------
    //
    // Versione 2
    //
    DEFPARAM CalculateOnLastBars = 5000
    //AtrMultiplier = 1.20        //1.20   ATR multiplier
    //BodySize      = 0.60        //60%    minimum Body size (compared to Range)
    //Tolerance     = 0.20        //20%    tolerance
    //AtrPeriods    = 14          //14     periods
    MinTolerance  = 1 - Tolerance
    Body          = abs(close - open)
    MinBody       = BodySize * MinTolerance
    Bullish       = close > open
    Bearish       = close < open
    MyAtr         = AverageTrueRange[AtrPeriods](close) * AtrMultiplier
    MyAtrMin      = MyAtr * MinTolerance
    Candle1       = (range[3] >= MyAtr[3]) AND (Body[3] >= (range[3] * BodySize))
    Candle2       = (Bullish[3] AND Bullish[2]) OR (Bearish[3] AND Bearish[2])
    Candle2       = Candle2 AND ((range[2] >= MyAtrMin[2]))
    Candle2       = Candle2 AND (Body[2] >= (range[2] * MinBody))
    Candle3       = (Bullish[3] AND Bullish[2] AND Bearish[1]) OR  (Bearish[3] AND Bearish[2] AND Bullish[1])
    IF Bullish[2] THEN
       Candle3    = (Candle3 AND (close[1] < open[2]))
    ELSIF Bearish[2] THEN
       Candle3    = (Candle3 AND (close[1] > open[2]))
    ELSE
       Candle3    = 0
    ENDIF
    Candle4       = ((Bullish[1]) AND (high > high[1])) OR ((Bearish[1]) AND (low < low[1]))
    Result        = Candle1 AND Candle2 AND Candle3 AND Candle4
    RETURN Result

    I added a variable to set ATR periods with the indicator’s properties.

    As for Dax 5 min TF, 25/02/2019 at 15:30, candles 4 and 3 were not the same direction. There should be a valid pattern on 25/02/2019 at 17:05.

    Nicolas thanked this post
    Il-Mio-Indicatore-ATR-1.itf x-1.jpg x-1.jpg y.jpg y.jpg
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.

4-Candlestick pattern detection


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
carlo__ @carlo__ Participant
Summary

This topic contains 9 replies,
has 2 voices, and was last updated by robertogozzi
6 years, 11 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 03/04/2019
Status: Active
Attachments: 6 files
Logo Logo
Loading...