# Upticks / Downticks

Let's mark each trade as an uptick if its price is above the last trade's price and as a downtick if it's below.

```ipython3
import onetick.py as otp

def uptick(t):
    if t['PRICE'] == otp.nan or t['PRICE'][-1] == otp.nan:
        return otp.nan
    if t['PRICE'] > t['PRICE'][-1]:
        return 1
    elif t['PRICE'] < t['PRICE'][-1]:
        return -1
    else:
        return 0

trd = otp.DataSource('US_COMP_SAMPLE', tick_type='TRD')
trd = trd[['PRICE']]
trd['UPTICK'] = trd.apply(uptick)
otp.run(
    trd,
    symbols=['AAPL'],
    start=otp.dt(2024, 2, 1, 9, 30),
    end=otp.dt(2024, 2, 1, 9, 30, 1),
)
```

```myst-ansi
                             Time    PRICE  UPTICK
0   2024-02-01 09:30:00.000961260  184.010     NaN
1   2024-02-01 09:30:00.000961491  184.000    -1.0
2   2024-02-01 09:30:00.000961701  184.000     0.0
3   2024-02-01 09:30:00.000973163  184.000     0.0
4   2024-02-01 09:30:00.000973355  184.000     0.0
..                            ...      ...     ...
574 2024-02-01 09:30:00.987184691  183.900     0.0
575 2024-02-01 09:30:00.990378350  183.920     1.0
576 2024-02-01 09:30:00.991941892  183.935     1.0
577 2024-02-01 09:30:00.993785116  183.905    -1.0
578 2024-02-01 09:30:00.996512511  183.934     1.0

[579 rows x 3 columns]
```
