OPEN-SOURCE SCRIPT

Three Bar Gap (Simple Price Action - with 1 line plot)

This script is tailored towards experienced traders who prefer to view raw price charts during live execution. It searches for a three-bar pattern of what is colloquially called "fair value gap", or "imbalance" and uses a single line to plot the results. The goal is to display price in a way that is as simple as possible so that chart readers who don't prefer to add indicators on their screen will still find this indicator as an acceptable option to consider for.

From a code perspective, this script explores a new PineScript feature called UDT (user-defined types). This is an incredible update because it brings developers one step close to having the ability to create abstract data types.


█ What is price action?

Experienced traders will tell you that the chart that they use for live execution is raw, clean, and uses no indicators. They say they execute on price action, so what exactly is price action?

There is no formal definition to it, but one can agree that it implies the process of analyzing price without considering the fundamentals, without needing to know what the news was about, and without needing to know any of the Greeks (except for the desire to “seek alpha” Ha.haa...). This is not to say that price action traders are executing in their own vacuums without the need to know what is happening around the world. Surely fundamentals and financial models can be used beforehand for developing a bias for what is being traded, but it’s price-first at the moment of execution. That said, Factor (A) is Price.

Factor (B) is time-perception, it’s how the trader reads the tape. How the trader perceives price to change with respect to time is valuable information. Interpretation of "time" will be elaborated in the next section that talks about candlestick patterns detected by this script.

Putting this together, price action means the analysis of price movement by only considering (A) price, and (B) time, to predict which direction the market will move. A speculative trader is timing the market with the expectation to make a quick in-and-out profit; she/she is using price action. On the other hand, a long term investor holding a diversified portfolio with a strategy based on modern portfolio theory combined with fundamental analysis (at this point candlesticks are irrelevant) but has one additional criteria of, say, can only go Long on a stock when it has closed Green on Daily; he/she is also considered to be executing on price action.

█ Candlestick patterns

This script calculates the displacement of highs and lows over three consecutive bars.
  • A) Down move = When High of the recent confirmed bar is lower than the Low of the previous-previous candle
  • B) Up move = When Low of the recent confirmed bar is higher than the High of the previous-previous candle
    (Note that its the confirmed bar that is being talked about, so it does not repaint)

    An ATR filter will be applied to reduce the number of lines generated as many times they might just be associated with minor price changes.

スナップショット
Interpretations:
When price moves quickly across three bars, it can be thought that it has gapped. Although the candle in the middle appears to be solid, it’s not from a conceptual perspective. This is because time itself is arbitrary; timeframes don’t necessarily have to be fixed intervals. Take stocks with regular trading hours for example, if price makes a breakaway gap and you bundle the after-hours and pre-market sessions together as one candle, never minding that intervals should be fixed, then you will see the exact three-bar-gap patterns. Similar happens during intraday sessions on lower timeframes, if you zoom-in closer, you’ll see that ticks within the middle candle are sparsely dispersed. This is why it's called a gap.


█ Parameters with fixed inputs & assumptions used:

ATR is used for filtering out minor movements that will likely be deemed as irrelevant by trader for the purpose of live execution. The following inputs are required:
  • A) ATR lookback period
  • B) Multiplier

The product of ATR(len=A) and B produces a threshold for minimum distance that price must gap by. Initially, it was proposed to be only based on one ATR, but often an ATR is too wide and using it will filter out too many lines. Because of this observation, a multiplier (Parameter B) has been introduced to allow users to apply fractional ATR as a threshold.


█ Applications:

  • For trend followers: Follow the direction of the gap. Entering above recent high/low points above/below the first impulse with a stop-limit order is a viable tactic.
  • For contrarians fading a trend: The mid-point is a good point of reference for predicting potential areas of support/resistance.
Candlestick analysiscandlestickpatternChart patternsfairvaluegapimbalancePivot Points

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

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

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


免責事項