OPEN-SOURCE SCRIPT

Candlestick Pattern Criteria and Analysis Indicator

█ OVERVIEW

Define, then locate the presence of a candle that fits a specific criteria. Run a basic calculation on what happens after such a candle occurs.

Here, I’m not giving you an edge, but I’m giving you a clear way to find one.

[u]IMPORTANT NOTE: PLEASE READ:
THE INDICATOR WILL ALWAYS INITIALLY LOAD WITH A RUNTIME ERROR. WHEN INITIALLY LOADED THERE NO CRITERIA SELECTED.
[/u]
If you do not select a criteria or run a search for a criteria that doesn’t exist, you will get a runtime error. If you want to force the chart to load anyway, enable the debug panel at the bottom of the settings menu.

Who this is for:
- People who want to engage in TradingView for tedious and challenging data analysis related to candlestick measurement and occurrence rate and signal bar relationships with subsequent bars. People who don’t know but want to figure out what a strong bullish bar or a strong bearish bar is.

Who this is not for:
- People who want to be told by an indicator what is good or bad or buy or sell. Also, not for people that don’t have any clear idea on what they think is a strong bullish bar or a strong bearish bar and aren’t willing to put in the work.

Recommendation: Use on the candle resolution that accurately reflects your typical holding period. If you typically hold a trade for 3 weeks, use 3W candles. If you hold a trade for 3 minutes, use 3m candles.

Tldr; Read the tool tips and everything above this line. Let me know any issues that arise or questions you have.

█ CONCEPTS

Many trading styles indicate that a certain candle construct implies a bearish or bullish future for price. That said, it is also common to add to that idea that the context matters. Of course, this is how you end up with all manner of candlestick patterns accounting for thousands of pages of literature. No matter the context though, we can distill a discretionary trader's decision to take a trade based on one very basic premise: “A trader decides to take a trade on the basis of the rightmost candle's construction and what he/she believes that candle construct implies about the future price.” This indicator vets that trader’s theory in the most basic way possible. It finds the instances of any candle construction and takes a look at what happens on the next bar. This current bar is our [u]“Signal Bar.”[/u]

█ GUIDE

I said that we vet the theory in the most basic way possible. But, in truth, this indicator is very complex as a result of there being thousands of ways to define a ‘strong’ candle. And you get to define things on a very granular level with this indicator.

Features:
1. Candle Highlighting
  • When the user’s criteria is met, the candle is highlighted on the chart.
  • The following candle is highlighted based on whether it breaks out, breaks down, or is an inside bar.

    2. User-Defined Criteria
    Criteria that you define include:
    • Candle Type: Bull bars, Bear bars, or both
    • Candle Attributes
    • Average Size based on Standard Deviation or Average of all potential bars in price history
    • Search within a specific price range
    • Search within a specific time range
    • Clarify time range using defined sessions and with or without weekends


    3. Strike Lines on Candle
    Often you want to know how price reacts when it gets back to a certain candle. Also it might be true that candle types cluster in a price region. This can be identified visually by adding lines that extend right on candles that fit the criteria.

    4. User-Defined Context
    Labeled “Alternative Criteria,” this facet of the script allows the user to take the context provided from another indicator and import it into the indicator to use as a overriding criteria. To account for the fact that the external indicator must be imported as a float value, true (criteria of external indicator is met) must be imported as 1 and false (criteria of external indicator is not met) as 0. Basically a binary Boolean. This can be used to create context, such as in the case of a traditional fractal, or can be used to pair with other signals.

    If you know how to code in Pinescript, you can save a copy and simply add your own code to the section indicated in the code and set your bull and bear variables accordingly and the code should compile just fine with no further editing needed.

    Included with the script to maximize out-of-the-box functionality, there is preloaded as alternative criteria a code snippet. The criteria is met on the bull side when the current candle close breaks out above the prior candle high. The bear criteria is met when the close breaks below the prior candle. When Alternate Criteria is run by itself, this is the only criteria set and bars are highlighted when it is true. You can qualify these candles by adding additional attributes that you think would fit well.

    Using Alternative Criteria, you are essentially setting a filter for the rest of the criteria.

    5. Extensive Read Out in the Data Window (right side bar pop out window).
    As you can see in the thumbnail, there is pasted a copy of the Data Window Dialogue. I am doubtful I can get the thumbnail to load up perfectly aligned. Its hard to get all these data points in here. It may be better suited for a table at this point. Let me know what you think.

    The primary, but not exclusive, purpose of what is in the Data Window is to talk about how often your criteria happens and what happens on the next bar. There are a lot of pieces to this.
    • Red = Values pertaining to the size of the current bar only
    • Blue = Values pertaining or related to the total number of signals
    • Green = Values pertaining to the signal bars themselves, including their measurements
    • Purple = Values pertaining to bullish bars that happen after the signal bar
    • Fuchsia = Values pertaining to bearish bars that happen after the signal bar
    • Lime = Last four rows which are your percentage occurrence vs total signals percentages


    The best way I can explain how to understand parts you don’t understand otherwise in the data window is search the title of the row in the code using ‘ctrl+f’ and look at it and see if it makes more sense.

    [b}Available Candle Attributes
    Candle attributes can be used in any combination. They include:
    • [*}Bodies
      [*}High/Low Range
      [*}Upper Wick
      [*}Lower Wick
      [*}Average Size
      [*}Alternative Criteria


    Criteria will evaluate each attribute independently. If none is set for a particular attribute it is bypassed.

    Criteria Quantity can be in [u]Ticks, Points, or Percentage.[/u] For percentage keep in mind if using anything involving the candle range will not work well with percentage.

    Criteria Operators are [u]“Greater Than,” “Less Than,” and “Threshold.”[/u] Threshold means within a range of two numbers.

    Problems with this methodology and opportunities for future development:
    #1 This kind of work is hard.
    If you know what you’re doing you might be able to find success changing out the inputs for loops and logging results in arrays or matrices, but to manually go through and test various criteria is a lot of work. However, it is rewarding. At the time of publication in early Oct 2022, you will quickly find that you get MUCH more follow through on bear bars than bull bars. That should be obvious because we’re in the middle of a bear market, but you can still work with the parameters and contextual inputs to determine what maximizes your probability. I’ve found configurations that yield 70% probability across the full series of bars. That’s an edge. That means that 70% of the time, when this criteria is met, the next bar puts you in profit.

    #2 The script is VERY heavy.
    Takes an eternity to load. But, give it a break, it’s doing a heck of a lot! There is 10 unique arrays in here and a loop that is a bit heavy but gives us the debug window.

    #3 If you don’t have a clear idea its hard to know where to start.
    There are a lot of levers to pull on in this script. Knowing which ones are useful and meaningful is very challenging. Combine that with long load times… its not great.

    #4 Your brain is the only thing that can optimize your results because the criteria come from your mind.
    Machine learning would be much more useful here, but for now, you are the machine. Learn.

    #5 You can’t save your settings.
    So, when you find a good combo, you’ll have to write it down elsewhere for future reference. It would be nice if we could save templates on custom indicators like we can on some of the built in drawing tools, but I’ve had no success in that. So, I recommend screenshotting your settings and saving them in Notion.so or some other solid record keeping database. Then you can go back and retrieve those settings.

    #6 no way to export these results into conditions that can be copy/pasted into another script.
    Copy/Paste of labels or tables would be the best feature ever at this point. Because you could take the criteria and put it in a label, copy it and drop it into another strategy script or something. But… men can dream.

    Opportunities to PineCoders Learn:
    1. In this script I’m importing libraries, showing some of my libraries functionality. Hopefully that gives you some ideas on how to use them too.
    • The price displacement library (which I love!)
    • Creative and conventional ways of using debug()
    • how to display arrays and matrices on charts
    • I didn’t call in the library that holds the backtesting function. But, also demonstrating, you can always pull the library up and just copy/paste the function out of there and into your script. That’s fine to do a lot of the time.

      2. I am using REALLY complicated logic in this script (at least for me). I included extensive descriptions of this ? : logic in the text of the script. I also did my best to bracket () my logic groups to demonstrate how they fit together, both for you and my future self.

      3. The breakout, built-in, “alternative criteria” is actually a small bit of genius built in there if you want to take the time to understand that block of code and think about some of the larger implications of the method deployed.


      As always, a big thank you to TradingView and the Pinescript community, the Pinescript pros who have mentored me, and all of you who I am privileged to help in their Pinescripting journey.

      "Those who stay will become champions" - Bo Schembechler
Informacje o Wersji
Total Thumbnail FAILLLL hahahaha. I tried
Lets see if this works better
snapshot
Informacje o Wersji
I came up with the Data Window color schema, but didn't apply it. :shrugs: my bad. All better.
Informacje o Wersji
Overhauled a bit of the script already:
Added two more qualifying criteria.
Made some changes to the debug panel to help watch your criteria journey through the logic.
Made some changes to how the average is measured.
Found a couple bugs in my own travel through various criteria testing.

As I usually do. I release that first version a bit too early and there's always some optimization that happens immediately following publication as I also begin using it.
analysisCandlestick analysiscandlesticksignalforecastingmeasuremeasurementsignalstatistics

Skrypt open-source

W prawdziwym duchu TradingView autor tego skryptu opublikował go jako open source, aby inwestorzy mogli go zrozumieć i zweryfikować. Pozdrowienia dla autora! Możesz go używać bezpłatnie, ale ponowne użycie tego kodu w publikacji podlega Zasadom Regulaminu. Możesz go oznaczyć jako ulubione, aby użyć go na wykresie.

Chcesz użyć tego skryptu na wykresie?


Również na:

Wyłączenie odpowiedzialności