import pandas as pd
import numpy as np

def engulfing_strategy(data):
data = np.where((data.shift(1) < data) & (data.shift(1) > data), 1, 0)

return data
data = pd.read_csv('data.csv')
data = pd.to_datetime(data)
data.set_index('Date', inplace=True)
data = engulfing_strategy(data)
print(data)
import pandas as pd
import numpy as np
def price_difference_strategy(data, entry_threshold, exit_threshold):
data = data.diff()
data = np.where(data > entry_threshold, 1,
np.where(data < -entry_threshold, -1, 0))
data = np.where(data > exit_threshold, -1,
np.where(data < -exit_threshold, 1, 0))
data = data.diff().fillna(0)
data = data.shift()
return data
data = pd.read_csv('data.csv')
data = pd.to_datetime(data)
data.set_index('Date', inplace=True)
data = price_difference_strategy(data, 0.001, 0.0005)
print(data)
Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.