Following is my sample dataset:
Price SL X
14 13.8 100
14.5 13.8 0
15 13.8 0
14.7 13.8 0
13.6 13.8 0
15 13.8 0
I want to create a new column that puts in remarks based on X. I want it to have BUY when X is 100. Followed by three rows of HOLD and two rows of SELL.
I am doing this using the following code:
cond = [
(df['X'] == 100),
(df['X'].shift(1) == 100),
(df['X'].shift(2) == 100),
(df['X'].shift(3) == 100),
(df['X'].shift(4) == 100),
(df['X'].shift(4) == 100),
]
choices = ['BUY', 'HOLD', 'HOLD', 'HOLD', 'SELL','SELL']
df['remarks'] = np.select(cond, choices)
Here is the outcome:
Price SL X remarks
14 13.8 100 BUY
14.5 13.8 0 HOLD
15 13.8 0 HOLD
14.7 13.8 0 HOLD
13.6 13.8 0 SELL
15 13.8 0 SELL
However, I want to add another option of Stopped Out when Price < SL like in the fifth row. How do I assign Stopped Out the highest priority overall?
Desired outcome:
Price SL X remarks
14 13.8 100 BUY
14.5 13.8 0 HOLD
15 13.8 0 HOLD
14.7 13.8 0 HOLD
13.6 13.8 0 Stopped Out
15 13.8 0 Stopped Out
14.5 13.8 0
15 14.7 100 BUY
14.8 14.7 0 HOLD
13 14.7 0 Stopped Out
I would want the remarks to end once the Stopped Out shows up. And they should come up only after a BUY and not sometime before it.
