Reputation: 67
I have the following data, and I want to create buy and sell signals based on the Close in the data frame. I want to create two conditions as follow
!pip install yfinance
!pip install keras
import yfinance as yf
import numpy as np
import pandas as pd
df=yf.download('BTC-USD',start='2008-01-04',end='2021-06-3',interval='1d')
buy=np.where((df['Close'][i] > df['Open'][i]) & (df['Close'][i-1] < df['Open'][i-1]),1,0)
But when I do that, it gives me one number of zero. Any insights would be appreciated.
Upvotes: 1
Views: 76
Reputation: 14949
IIUC, you need:
buy = np.where((df['Close'] > df['Open']) & (
df['Close'].shift() < df['Open'].shift()), 1, 0)
Upvotes: 2