# Technical Pattern Recognition for Trading in Python.

Original article was published by Sofien Kaabar on Artificial Intelligence on Medium # TD Differential Pattern

This pattern seeks to find short-term trend reversals; therefore, it can be seen as a predictor of small corrections and consolidations. Below is an example on a candlestick chart of the TD Differential pattern.

If we want to code the conditions in Python, we may have a function similar to the below:

• Two closes each less than the prior.
• Current selling pressure < previous selling pressure.

Sell (Go short) trigger:

• Two closes each greater than the prior.
`def TD_differential(Data, true_low, true_high, buy, sell):    for i in range(len(Data)):        # True low        Data[i, true_low] = min(Data[i, 2], Data[i - 1, 3])        Data[i, true_low] = Data[i, 3] - Data[i, true_low]        # True high          Data[i, true_high] = max(Data[i, 1], Data[i - 1, 3])        Data[i, true_high] = Data[i, 3] - Data[i, true_high]        # TD Differential        if Data[i, 3] < Data[i - 1, 3] and Data[i - 1, 3] < Data[i - 2, 3] and \           Data[i, true_low] > Data[i - 1, true_low] and Data[i, true_high] < Data[i - 1, true_high]:                Data[i, buy] = 1if Data[i, 3] > Data[i - 1, 3] and Data[i - 1, 3] > Data[i - 2, 3] and \           Data[i, true_low] < Data[i - 1, true_low] and Data[i, true_high] > Data[i - 1, true_high]:                Data[i, sell] = -1`