void messageLoop() { MSG msg; bool quit = false; mApp.beforeWindowShown(); ShowWindow(mHWnd, SW_NORMAL); while(!quit) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (WM_QUIT == msg.message) { quit = true; willQuit(); } TranslateMessage(&msg); DispatchMessage(&msg); } else { processTick(); } } }
/** * Main application process cycle is here. Calculates frames delay so we can use * real time for tick processing. */ void Application::run() { running = true; while (running) { frameLength = frameEnd - frameStart; dt = frameLength.count(); frameStart = std::chrono::system_clock::now(); processEvents(); processTick(); processRender(); frameEnd = std::chrono::system_clock::now(); } }
Backtester::TransactionData & Backtester::backtest(DataSet & dataSet, const Specimen* strategy) { bought = false; sold = false; transactionData = TransactionData(); map<shared_ptr<Indicator>, double>* indicatorValues; int i = 0; while (i < dataSet.getSize()) { indicatorValues = dataSet.getIndicatorValues(i); processTick(dataSet.getOpenPrice(i), *indicatorValues, strategy); if (rand() % 2 == 0) { processTick(dataSet.getHighPrice(i), *indicatorValues, strategy); processTick(dataSet.getLowPrice(i), *indicatorValues, strategy); } else { processTick(dataSet.getLowPrice(i), *indicatorValues, strategy); processTick(dataSet.getHighPrice(i), *indicatorValues, strategy); } processTick(dataSet.getClosePrice(i), *indicatorValues, strategy); i++; } if (bought) { double gain = dataSet.getClosePrice(i - 1) - transactionData.buyPrices.back(); if (gain > 0) { transactionData.gains += priceToPips(gain); transactionData.goodTransactionCount++; } else { transactionData.losses += -priceToPips(gain); transactionData.badTransactionCount++; } bought = false; sold = false; } else if (sold) { double gain = transactionData.sellPrices.back() - dataSet.getClosePrice(i - 1); if (gain > 0) { transactionData.gains += priceToPips(gain); transactionData.goodTransactionCount++; } else { transactionData.losses += -priceToPips(gain); transactionData.badTransactionCount++; } bought = false; sold = false; } return transactionData; }