My strategies rely on buying and selling ETFs at close prices. Lets say I am 100% long SPY but want to switch to QQQ at the end of the day and place orders sell all SPY MOC and buy QQQ MOC. If the buy order is executed first without selling, then I will not have the funds to execute the buy order. Is there a way to avoid this problem? Does the order in which the orders are entered matter? If I enter the sell order first and then the buy order then will I have this problem?