Hi all,

My algo uses a simple rule to allow only one order at any gieven time. So far I have been using SetHoldings with 100% allocations:

// Method 1 // ------------ // check if it's time to buy, bla bla bla if (!Portfolio.Invested) { SetHoldings(symbol, 1); // for buying with 100% allocation } // and // check if it's time to sell, bla bla bla if (Portfolio.Invested) { SetHoldings(symbol, 0); // sell everything }

 

With this, if you look at the resulted trades, you always see a nicely filled Long trade followed by a nicely filled Short trade. And my Portfolio.Cash never goes to any negative number.

Now I need to trade with a fixed amount instead (e.g. $50K). I used a couple of different methods:

// method 2 if (!Portfolio.Invested) { LimitOrder(symbol, shares, price, tag: "Buy LimitOrder"); } // method 3 if (!Portfolio.Invested) { Order(symbol, shares, OrderType.Limit, price, "Buy Order"); } // method 4 if (!Portfolio.Invested) { StopMarketOrder(symbol, shares, price, tag: "Buy StopMarketOrder"); }

 

When I used any of these methods, the trades show a strange behavior. I get multiple Long tickets, some show as New and finally one that says Filled. Also in several points my Portfolio.Cash goes to negative numbers!

I'm thinking of two possible reasons.

1. Portfolio.Invested doesn't become true if I allocate parts of the cash and not all of it ... very unlikely!

2. There might be a delay (considering that I use Resolution.Second) that causes a new OnData to happen before the first Order is filled.

 

Could anyone please shed some light on this behavior? Thanks a lot!