code attached - no long or short activity
code attached - no long or short activity
The problem is that you are buying SPY and then immediately selling the same number of shares of SPY. The net result is you will hold zero.
What you probably are trying to do is go long and short at the same time. Q doesn’t allow that. If one tries to go short, any existing shares will be sold first. This is also true in real trading. Most brokers (eg IB) won’t allow long and short positions of the same security.