Engulfing Candle Detector with Gap

This tutorial explains how to add additional logic to a standard candle detector. In this example we’ll use an engulfing candlestick and show how to add an extra condition to check for a candle gap down. A gap down is where there’s a gap between the closing of one candle and the opening of the next as in the screen below.

Card image cap

Detecting candle gaps

The first part of the logic is to detect a candle gap. To do this, open the Indicator Builder and set the top row to Subtract.

Card image cap

Add a subtract operator.

Next set the second input to Array Shift, then set the input of the shift to Low Price. This logic will subtract the low price in the previous candle from the high price in the current candle.

Card image cap

Array Shift

To check the output of this gap detector, click the spyglass icon in the top row. It should look something like the chart below.

Card image cap

Gap distance

As we’re only interested in gap downs, add a Less Than operator above Subtract in the top row. To do this, click to select the top row. Then click the plus symbol in the tool bar. Set the operator to Less Than.

Card image cap

Show gap downs only

This logic will give a positive value only where the difference is negative, that is a candle gap down from the previous.

Card image cap

Set the summation period

Follow the steps above to add a Summation operator in the top row. Then set the summation period to 5, or as required. This logic will have a positive value, whenever one of the five preceding candles has a gap down. The settings box can be found by clicking the cogs icon and selecting the parameters tab.

Card image cap

Add additional logic

Now add an And operator and set the second input to Engulfing Pattern. Now the logic will output a value whenever a candle is an engulfing and one of the five preceding candles had a gap down.

Card image cap

Preview result

Finally, add a Buy operator in the top row to mark the outputs with a buy signal. On clicking preview, the resulting chart should look something like the one above.

Use this Indicator

Risk Disclosure: Information given on this website is for general purposes only and should not be construed as investment advice. Certain instruments shown here are complex and may come with a high risk of losing money rapidly due to leverage. You should consider whether you understand how these instruments work and whether you can afford to take the high risk of losing your money. Market data displayed is indicative and is not a solicitation to buy or sell.