I have list of stock and then am going through each stock and check if short term moving average is bigger then long term moving average. I then want to purchase one stock that fits my criteria using
order_target_percent(stock, .50)
using 50% of capitol to that position. Am trying to then sell that stock once the longer moving average is bigger then the smaller moving average for the stock I purchased. Am having issues with how my code over buys and doesn't seem to keep track of what positions am holding. How do i go about fixing this? What am i doing wrong?