I have stock market data, I would like to have the code purchase stock (buy) and wait until it gets sold (sell) and again purchases stock after selling. The below code only runs for the initial buy and sell. what if I want to do that for the entire dataset, instead of breaking at first buy and first sell.
i=0
j=0
while (i<1) and (j <len(data)):
if data['RSI'][j]>=70:
print(j,data['RSI'][j])
print("BUY")
k=j
i+=1
j+=1
while (i==1) and ((j>k) and (j<len(data))):
if data['RSI'][j]<=30:
print(j,data['RSI'][j])
print("Sell")
i+=1
j+=1
the output of the above code in a tabular format(for better understanding):
| index | RSI | tag |
|---|---|---|
| 0 | 100.0 | BUY |
| 7 | 25.38 | SELL |
Expected Output:
| index | RSI | tag |
|---|---|---|
| 0 | 100.0 | BUY |
| 7 | 25.38 | SELL |
| 10 | 80.24 | BUY |
| 20 | 40.20 | SELL |
| 25 | 81.24 | BUY |
| 30 | 41.20 | SELL |
and it goes on like this for entire dataset