Support Board
Date/Time: Fri, 31 Jan 2025 19:48:30 +0000
Post From: backtest with manual looping, sc.GetTradePosition() doesn't update?
[2019-05-16 21:53:10] |
uM8137 - Posts: 183 |
I had sc.GetTradePosition() making sense to me under automatic looping. But now that I'm changing over to manual looping, it doesn't seem to work anymore... Is there some trick? example: Given this little function to encapsulate GetTradePosition(): int getCurrentPos(SCStudyInterfaceRef sc) {
s_SCPositionData pos; sc.GetTradePosition(pos); int curPos = pos.PositionQuantity; return curPos; } then I'm backtesting with sc.AutoLoop = 0; (manual looping) over index k, and after a int beforePos = getCurrentPos(sc);
int sharesBought = (int)sc.BuyEntry(NewOrder, k); int afterPos = getCurrentPos(sc); if (sharesBought > 0) { // here, both beforePos *and* afterPos can be 0. // Which makes no sense, since sharesBought was >0, // so afterPos should be beforePos + sharesBought... // Or is it just a bug? } Thanks! (on version 1915) p.s. addendum: also with k = 0, any valid order is rejected with an odd "Order entry skipped because invalid bar index specified". Date Time Of Last Edit: 2019-05-16 22:21:22
|