Hi! I have a question regarding the following; I have obtained buy signals from stock data for every 5 minutes. A small part of the data is shown below. So a buy signal at time t and then two periods a neutral position, and then the buy signal lasts for 6 periods. If a buy signal is triggered, I want to retrieve a sell signal 4 periods later and ignore the signals in between. If after the sell signal the buy signal still holds, there should be a buy signal again and after 4 periods a sell signal etc. In conclusion, the signal should be as presented in the second code below in the second column. I have tried using the generate/replace commands, but that sadly doesn't work all the time (still some errors). Is there another way to do this?
Then:
Thank you in advance! Much appreciated!
Best,
S.
Code:
BUY BUY BUY BUY BUY BUY BUY BUY BUY
Code:
BUY BUY BUY BUY SELL BUY BUY BUY BUY BUY SELL BUY BUY BUY

Best,
S.