Identifying Doji Candlesticks Contained Between Two Similar-Sized Candles

24 Jun 2016
0 comment
0 attachment

This ProBuilder code snippet is designed to identify a specific candlestick pattern in trading charts. The pattern consists of a doji candlestick flanked by two larger candlesticks that are similar in size. The code allows users to set parameters for the doji size and the minimum size and similarity of the surrounding candlesticks.


DojiPercent = 50 //percentage
CandleBodySize = 10 //points
Maxdifference = 20 //percentage

// --- 
doji=(abs(open - close) <= (high - low) * (Dojipercent/100))
body = abs(open-close)
bodysize = body>=candlebodysize*pointsize

if bodysize and (max(body,body[2])-min(body,body[2]))/body[2]<=maxdifference/100 and doji[1] then
    //drawarrow(barindex[1],low[1])
    //backgroundcolor(150,150,150,50)
    drawrectangle(barindex[2],highest[3](high),barindex,lowest[3](low))
endif

return

Explanation of the Code:

  • Parameter Definitions: The parameters DojiPercent, CandleBodySize, and Maxdifference are set to define the characteristics of the doji and the surrounding candles. DojiPercent determines the maximum body size of the doji as a percentage of its total range. CandleBodySize sets the minimum size of the bodies of the surrounding candles in points. Maxdifference allows a percentage difference in the body sizes of the surrounding candles.
  • Doji Calculation: The variable doji is calculated by comparing the absolute difference between the open and close prices to a fraction of the total range (high - low) of the candle. This determines if the current candle is a doji based on the defined DojiPercent.
  • Body Size Check: The body variable calculates the absolute difference between the open and close prices of the candle. The bodysize boolean checks if the body size of the candle is at least as large as the defined CandleBodySize.
  • Conditional Drawing: If the current and the candle two periods before have a minimum body size and their sizes are within the Maxdifference percentage, and the previous candle is a doji, then a rectangle is drawn from the highest high to the lowest low over the last three bars. This visually highlights the pattern on the chart.

This code is useful for traders and analysts who use technical analysis to identify potential reversals or continuations in price trends based on candlestick patterns.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/inside-bars/page/2/#post-149015

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
Nicolas Master
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
Author’s Profile

Comments

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
35
indicator
133
strategy
171

Recent Snippets

How to Create a Simple MTF Trend Dashboard with EMA and SMA
indicator
This indicator builds a compact multi-timeframe (MTF) dashboard that shows whether price is trading above or below a [...]
How to Display Per-Bar Volume Accumulation in Real Time (Intrabar Updates)
global
This snippet tracks and displays the current bar’s accumulated volume while the bar is still forming, instead of only [...]
Ticks Counter: Count Tick Updates Per Bar on Tick or Time Charts
global
This snippet counts how many tick updates have occurred for the current bar by incrementing a per-bar counter on each [...]
How to Build a Step-Based Trailing Stop That Moves to Break-Even First
strategy
This snippet implements a step trailing stop that advances in fixed increments once price reaches predefined profit [...]
Utilizing Arrays to Track and Compare Indicator Values Within the Same Bar in ProBuilder
indicator
This ProBuilder code snippet demonstrates how to use arrays to compare the values of an indicator (RSI in this case) [...]
Logo Logo
Loading...