I am trading my entire account and keep getting an error that I am trying to trade more money than I have in my account. What command will trade all my account minus a minimal amount for trading fee. It would be better to have a percentage than a dollar amount to accommodate account size for trading fee.

My last trade during the day is a market order around 3:30 so there is no concern regarding not having a trade implemented before close. I.E. I do not need a safety margin other than the trading fee.

I have tried the following unsuccessfully

METHOD 1

INITIALIZE

self.Settings.FreePortfolioValuePercentage = 0.025

ONDATA

Quantity = self.CalculateOrderQuantity('SPY', 1)

self.MarketOrder('SPY',Quantity)

 

METHOD 2

Works but keeps too much money in cash, I want to minimize. Also, when money grows I eventually get the error again at around 60k.

ONDATA

Quantity = self.CalculateOrderQuantity('SPY', 1)

OrderQuantity = Quantity - round (1500 / price)

self.MarketOrder('SPY',OrderQuantity)

 

METHOD 3

ONDATA

Quantity = self.CalculateOrderQuantity('SPY', .97)

self.MarketOrder('SPY',Quantity)