The script uses Simple Moving Averages (SMA50 and/or SMA200) to determine the trend. A candlestick is considered part of a downtrend if it closes below these averages and part of an uptrend if it closes above them.