OPEN-SOURCE SCRIPT

Doji Hunter

アップデート済
OVERVIEW

This script is built to search for 8 different Doji candlestick patterns in markets and makes them appear on screen with bar coloring and creating color-coded labels/shapes. It will identify the following variants based upon user input for various rules to abide by:

  • Gapping Up
  • Gapping Down
  • Gravestone
  • Dragonfly
  • Long-Legged
  • Rickshaw Man
  • Northern (Doji in uptrend)
  • Southern (Doji in downtrend)


Note: for the remainder of this description, the types for inputs will be marked by italic text.

OPTIONS

This script features a wide range of options available to the user to modify how it functions. The first set of inputs dictate how the trend analysis is done with moving averages. The second and third sets of inputs dictate specific rules for how Doji candles are analyzed and the colors used for when they appear.

INPUTS (short)

1 — Moving Average Rules:

The Northern and Southern Doji variants require some trend analysis which will be done by Moving Averages. The inputs in this section change various things about the moving average(s) to be used. In the second section of inputs, there is one boolean option that will nullify the need for trend detection and consolidates the Northern and Southern Doji variants into one.

2/3 — Doji Rules and Colors:

The next two sections of inputs correspond to the various rules that dictate how various doji variants will be analyzed, as well as the colors that correspond to each variant. The colors will also apply to each of the labels/shapes used.

4 — Diagnostics:

The last boolean will allow the user to see extra detail with regards to how and when dojis are detected. Note: This is not a part of any prior section and is simply included as a last functional item to the list of all inputs.

An example of multiple labels being shown on screen for various types of Dojis (DJI 1D chart):

スナップショット

INPUTS (extended)

1 — Moving Average Rules:

This section consists of 10 different inputs specific to the rules on how the moving average functions for trend analysis.

"Trend Rule" (string list) determines which Moving Average will be used for trend detection. It has 3 options: "MA 1", "MA 2", or "BOTH". The second input "Trend Source" determines which OHLC (or combination) value to use in comparison to either MA 1 or MA 2 (EX: Trend Rule -> "MA 1" and Trend Source -> "close": if close > MA 1 -> uptrend, downtrend otherwise). If "BOTH" is selected then "Trend Source" is ignored and added nuance in the script ensures that the shorter MA being above the longer MA yields an uptrend (downtrend otherwise).

The next 8 inputs focus on 4 different parts of both MA 1 and 2.

  • Length (integer(s))
  • Color
  • Switch between SMA/EMA (boolean(s))
  • Source for MA


Note: Additional attention to detail has been made here as trend direction is ignored if "BOTH" is selected for the MA Rules and the lengths of both Moving Averages are set to be the same.

2/3 — Doji Rules and Colors:

The next two sections include 19 inputs that are related to how this script will analyze and identify the different variants of Doji candles.

"Identify Pattern On Close" (boolean) modifies which candles are to be used for determining when Doji candles are recognized. This changes an offset used for historical reference on some global variables which will force the script to only identify patterns after the current candle has closed.

"Doji Body Tolerance" (float) tells the script the maximum % the candle body may be of the high-low range to be considered a Doji candle.

"Doji Wick Sample" (integer) defines how many prior candles to sample from in calculating the current average upper and lower wick sizes.

"Simplify Northern/Southern Dojis" (boolean) makes this script ignore trend direction for Doji detection and consolidates Northern and Southern Dojis into being recognized as the same. This has an added effect of removing the plotted moving averages from the screen.

"Northern/Southern Display" (string list) that has multiple options for how Northern and Southern Dojis will be displayed on screen. Because of how labels may be extremely taxing on TradingView's servers to display, the default setting is "shapes" where Northern and Southern (N/S) Dojis will be marked with a colored triangle at the top of the candle. If "Simplify Northern/Southern Dojis" is true, all N/S Dojis will be marked with an x-cross instead. Other options include "labels" which enables the use of labels accompanied by their respective tooltip and color, or "none" where N/S Dojis will be only noticeable by their changed barcolor.

"Allow Gravestone/Dragonfly Shadows" (boolean) allows a bit of additional nuance to the definition of Gravestone or Dragonfly Dojis with small shadows.

"Gravestone/Dragonfly Shadow Tolerance" (float) defines the maximum % that the lower wick/upper wick (respectively) may be relative to the high-low range for Gravestone or Dragonfly Dojis to still be considered valid.

"Doji Long Wick Setting" (string list) is a list of settings for three different ways of confirming if a Doji is Long-Legged. The settings are "one", "two", and "average". These define how many wick lengths of a candle need to exceed the calculated average wick lengths (EX: "both" -> upper wick length > upper wick average and lower wick length > lower wick average). The "average" setting will combine the lengths of both wicks and both prior wick averages, divide both of these sums by 2 and compare them instead.

"Doji Long Wick Tolerance" (float) defines how large compared to the averages that wick lengths need to be in order for them to be considered "Long-Legged" (EX: 1.50 -> upper/lower wick needs to exceed 150% the average of previous upper/lower wicks).

"Rickshaw Man Body Placement Tolerance" (float) defines how close to the high-low range's midpoint the candle body's midpoint needs to be in order for it to be considered a Rickshaw Man Doji candle instead.

The remaining 9 inputs define the colors to use for differentiating between all Doji variants this script will recognize.

USAGE

My hope for this script is that users find this easy to use/understand and will tinker with the input values to better identify Doji candlesticks across a wide range of markets.

Suggestions for changes in the future are welcome.
リリースノート
Some variable refactoring to maintain consistency.

Functionality update: "Simplify Northern/Southern Doji" input no longer makes the moving averages disappear, as I have just realized that the Gapping Up/Down Doji variants are also dependent upon the current trend directions.

Note: If MA 1 and 2 have the same length and "MA Rules" is set to "BOTH" then the moving averages will not appear and detection for the Gapping Up/Gapping Down variants will not work (unlikely to hinder actual functionality of this script, this is simply a very specific edge case I've decided to handle).
リリースノート
House Rules #2 update: links removed
Candlestick AnalysisDojihunterMoving Averagespattern

オープンソーススクリプト

TradingViewの精神に則り、このスクリプトの作者は、トレーダーが理解し検証できるようにオープンソースで公開しています。作者に敬意を表します!無料で使用することができますが、このコードを投稿で再利用するには、ハウスルールに準拠する必要があります。 お気に入りに登録してチャート上でご利用頂けます。

チャートでこのスクリプトを利用したいですか?

免責事項