So clearly this doesn't add up, it thinks it's ordering BTCUSD for FAR cheaper than it really could be, and it's also somehow magically gaining buying power. Can someone tell me why this is happening and how to fix this?

decimal price = data[btc].Close; decimal holdings = Portfolio[btc].Quantity; if (Portfolio.GetBuyingPower("BTCUSD") > price) { Debug("BUY; Date: " + data.Time + "; Price: " + price + "; Buying Power: " + Portfolio.GetBuyingPower("BTCUSD") + "; Coins: " + holdings); Order("BTCUSD", 1); } else { Debug("FAIL; Date: " + data.Time + "; Price: " + price + "; Buying Power: " + Portfolio.GetBuyingPower("BTCUSD") + "; Coins: " + holdings); }

 

Debug Below:

2017-12-01 19:00:00 : BUY; Date: 12/1/2017 7:00:00 PM; Price: 10869.84; Buying Power: 100000.000; Coins: 0 2017-12-02 19:00:00 : BUY; Date: 12/2/2017 7:00:00 PM; Price: 10930.24; Buying Power: 89191.635; Coins: 1 2017-12-03 19:00:00 : BUY; Date: 12/3/2017 7:00:00 PM; Price: 11290; Buying Power: 78996.8200; Coins: 2 2017-12-04 19:00:00 : BUY; Date: 12/4/2017 7:00:00 PM; Price: 11643.98; Buying Power: 68699.825000000000000000000001; Coins: 3 2017-12-05 19:00:00 : BUY; Date: 12/5/2017 7:00:00 PM; Price: 11718.35; Buying Power: 57397.860; Coins: 4 2017-12-06 19:00:00 : BUY; Date: 12/6/2017 7:00:00 PM; Price: 14090; Buying Power: 57495.7950; Coins: 5 2017-12-07 19:00:00 : BUY; Date: 12/7/2017 7:00:00 PM; Price: 17390.01; Buying Power: 63513.930000000000000000000002; Coins: 6 2017-12-08 19:00:00 : BUY; Date: 12/8/2017 7:00:00 PM; Price: 16367.03; Buying Power: 39086.40500000000000000000000; Coins: 7 2017-12-09 19:00:00 : FAIL; Date: 12/9/2017 7:00:00 PM; Price: 15309.98; Buying Power: 13600.40000000000000000000000; Coins: 8 2017-12-10 19:00:00 : FAIL; Date: 12/10/2017 7:00:00 PM; Price: 15290.01; Buying Power: 13456.56000000000000000000000; Coins: 8 2017-12-11 19:00:00 : BUY; Date: 12/11/2017 7:00:00 PM; Price: 16885.76; Buying Power: 26302.48000000000000000000000; Coins: 8 2017-12-12 19:00:00 : FAIL; Date: 12/12/2017 7:00:00 PM; Price: 17730.12; Buying Power: 17015.95500000000000000000000; Coins: 9