import numpy as np import pandas as pd import matplotlib.pyplot as plt # Simulate data np.random.seed(1234) df = pd.DataFrame( {‘px_last’: 100 + np.random.randn(1000).cumsum()}, index=pd.date_range(‘2010-01-01′, periods=1000, freq=’B’), ) df[’50dma’] = df[‘px_last’].rolling(window=50, center=False).mean() df[‘200dma’] = df[‘px_last’].rolling(window=200, center=False).mean() ## Apply labels df[‘label’] = ‘out of bounds’ df.loc[abs(df[’50dma’] – df[‘200dma’]) >= 7, ‘label’] = ‘|50dma – 200dma| >= 7’…