I have a column called Entry signal that signals a Short Sell Entry but want to implement a backtest with stop loss at 15% that references the most recent last “Entry” from Entry Signal calling (if price rises more than 15% from Entry Price then exit trade, do nothing until next Entry and repeat).
I want to create below Stop Loss column
e.g.
Date Price Entry Signal Stop Loss
2024-01-18 3595.0 NaN NaN
2024-01-19 3280.0 Entry NaN
2024-01-22 3505.0 NaN NaN
2024-01-23 3945.0 NaN Exit (since first time price change triggers > +15%)
2024-01-24 4075.0 NaN NaN
2024-03-07 10270.0 Entry NaN
2024-03-08 8120.0 NaN NaN
2024-03-11 14020.0 NaN Exit
So far I can only think of for looping across each row but there must be a better way given I am working with a dataframe.