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.
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.
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.
To check the output of this gap detector, click the spyglass icon in the top row. It should look something like the chart below.
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.
This logic will give a positive value only where the difference is negative, that is a candle gap down from the previous.
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.
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.
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.