New Members: Be sure to confirm your email address by clicking on the link that was sent to your email inbox. You will not be able to post messages until you click that link.

reverse engineering bearish engulfing

I'm trying to reverse engineer the code Stockcharts uses for some of their candlesticks. It's quite difficult actually. I usually end up with not enough rules and end up with more candidates than the stockcharts predefined scan. Currently I'm working on the Bearish Engulfing candle and this is what I have:

[exchange is NYSE]
and [group is not ETF]

and [today's open > today's EMA(10, close)]
and [yesterday's close > yesterday's open]
and [today's high > yesterday's close]

and [today's close < today's open]
and [today's open > yesterday's close]

#not shooting star
and [high - open < [open - close]*2]
#not hammer
and [close - low < [open - close]*1]

#closing lower than yesterday's open
and [today's close < yesterday's open]


If you compare my code to the stockcharts predefined scan for bearish engulfing (NYSE) you will see my scan returns more stocks than the stockcharts predefined scan. Any obvious rules I'm missing here?

Comments

  • markdmarkd mod
    edited November 2019
    First impression, without looking at the logic, differences might be due to different universes - Stockcharts may be including only SCTR ranked stocks for instance, or there may be a market cap condition (just guessing). Or, if you compared results before the market close (or before the final daily update - about 6 pm eastern), the scans were looking at different data.
  • markdmarkd mod
    edited November 2019
    So this gets 14 and Stockcharts gets 12. It returned quite a few more before adding the volume requirement, which might not be quite the same as SC's. I think the "Doji" condition gets around having to specify shooting star and hammer (thanks for documenting by the way - very helpful).

    [exchange is NYSE]

    and [group is not ETF]

    and [sma(21,volume) > 40000]

    and [1 day ago Doji is not true]

    and [1 day ago close > 1 day ago open]

    and [open > 1 day ago close]

    and [close < 1 day ago open]

    and [Long Body is true]
  • Great feedback, those inputs definitely improve the scan.

    How would you do it without using the 'doji' and 'long body' pre-definitions though? I'm trying to get away from using all of stockcharts pre-defined setups so I can port to another program if needed.
  • You would have to decide what your definitions of those candles are.

    Long body could be

    and[close > open]
    and [close - open > range * .5]

    or maybe .6 or .7, .8. .9

    For a long body closing down then same thing except open > close, open - close to get positive number comparisons.

    There are a few variations of doji, but the main property is a small body, so it would similar to long body, but the multiplier might be .1 or .05. Then if you care about where it happens you would have to place the close somewhere in the range. For a high close

    and [close > low + [range * .8] ]

    For a low close

    and [close < low + [range * .2] ]

    Most definitions I've seen don't care about whether the close is above the open, but you could include that test, too, if it helps.

    You might also specify something about range if you want a reasonably normal candle for the doji (or the long body, for that matter), like

    and [range > ATR(14) * .5]

    or some other multiplier.




Sign In or Register to comment.