Hi, everybody!

I want to write a simple algo strategy, where I buy a certain stock at market oper or some minutes thereafter and sell at market close. IF the stock moves more than a certain % from the price at the open, I want to both stop loss or take profit, if the % the instrument has moved is either down or up.


Let's say, like in this example, that I want to buy AA at market open. If the price at market open is 10$ and the stock goes after opening at 11$, I want to take profit @ 10.1$ given an hypotetical 1% SL-TP target.

If the stock goes to 9$, I want to SL @ 9.9$.

If the stock remains during the day in the range 9.9$-10.1$ , I want to sell all the stock I own at market close (or, like in the code I attached, 2 minutes before).


So this is the strategy, in general, but I can't code it properly. The code which I attached doesn't either SL or TP, but just buys at market open and sells what was bought at market open at market close.


Can you help me? thanks