//------------------------------------------------------------------------------ void ostream::putNum(uint32_t n, bool neg) { char buf[13]; char* end = buf + sizeof(buf) - 1; char* num; char* str; uint8_t base = flagsToBase(); *end = '\0'; str = num = fmtNum(n, end, base); if (base == 10) { if (neg) { *--str = '-'; } else if (flags() & showpos) { *--str = '+'; } } else if (flags() & showbase) { if (flags() & hex) { *--str = flags() & uppercase ? 'X' : 'x'; } *--str = '0'; } uint8_t len = end - str; fmtflags adj = flags() & adjustfield; if (adj == internal) { while (str < num) putch(*str++); } if (adj != left) { do_fill(len); } putstr(str); do_fill(len); }
//------------------------------------------------------------------------------ void ostream::putDouble(double n) { uint8_t nd = precision(); double round = 0.5; char sign; char buf[13]; // room for sign, 10 digits, '.', and zero byte char *end = buf + sizeof(buf) - 1; char *str = end; // terminate string *end = '\0'; // get sign and make nonnegative if (n < 0.0) { sign = '-'; n = -n; } else { sign = flags() & showpos ? '+' : '\0'; } // check for larger than uint32_t if (n > 4.0E9) { pgm err(PSTR("BIG FLT")); putPgm(err); return; } // round up and separate in and fraction parts for (uint8_t i = 0; i < nd; ++i) round *= 0.1; n += round; uint32_t intPart = n; double fractionPart = n - intPart; // format intPart and decimal point if (nd || (flags() & showpoint)) *--str = '.'; str = fmtNum(intPart, str, 10); // calculate length for fill uint8_t len = sign ? 1 : 0; len += nd + end - str; // extract adjust field fmtflags adj = flags() & adjustfield; if (adj == internal) { if (sign) putch(sign); do_fill(len); } else { // do fill for internal or right fill_not_left(len); if (sign) *--str = sign; } putstr(str); // output fraction while (nd-- > 0) { fractionPart *= 10.0; int digit = static_cast<int>(fractionPart); putch(digit + '0'); fractionPart -= digit; } // do fill if not done above do_fill(len); }
static void outputLine(HttpQueue *q, MprDirEntry *ep, cchar *path, int nameSize) { MprPath info; MprTime when; Dir *dir; char *newPath, sizeBuf[16], timeBuf[48], *icon; struct tm tm; bool isDir; int len; cchar *ext, *mimeType; char *dirSuffix; char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; path = mprEscapeHtml(path); dir = q->conn->data; if (ep->size >= (1024 * 1024 * 1024)) { fmtNum(sizeBuf, sizeof(sizeBuf), (int) ep->size, 1024 * 1024 * 1024, "G"); } else if (ep->size >= (1024 * 1024)) { fmtNum(sizeBuf, sizeof(sizeBuf), (int) ep->size, 1024 * 1024, "M"); } else if (ep->size >= 1024) { fmtNum(sizeBuf, sizeof(sizeBuf), (int) ep->size, 1024, "K"); } else { fmt(sizeBuf, sizeof(sizeBuf), "%6d", (int) ep->size); } newPath = mprJoinPath(path, ep->name); if (mprGetPathInfo(newPath, &info) < 0) { when = mprGetTime(); isDir = 0; } else { isDir = info.isDir ? 1 : 0; when = (MprTime) info.mtime * MPR_TICKS_PER_SEC; } if (isDir) { icon = "folder"; dirSuffix = "/"; } else { ext = mprGetPathExt(ep->name); if (ext && (mimeType = mprLookupMime(q->conn->rx->route->mimeTypes, ext)) != 0) { if (strcmp(ext, "es") == 0 || strcmp(ext, "ejs") == 0 || strcmp(ext, "php") == 0) { icon = "text"; } else if (strstr(mimeType, "text") != 0) { icon = "text"; } else { icon = "compressed"; } } else { icon = "compressed"; } dirSuffix = ""; } mprDecodeLocalTime(&tm, when); fmt(timeBuf, sizeof(timeBuf), "%02d-%3s-%4d %02d:%02d", tm.tm_mday, months[tm.tm_mon], tm.tm_year + 1900, tm.tm_hour, tm.tm_min); len = (int) strlen(ep->name) + (int) strlen(dirSuffix); if (dir->fancyIndexing == 2) { httpWrite(q, "<tr><td valign=\"top\">"); httpWrite(q, "<img src=\"/icons/%s.gif\" alt=\"[ ]\", /></td>", icon); httpWrite(q, "<td><a href=\"%s%s\">%s%s</a></td>", ep->name, dirSuffix, ep->name, dirSuffix); httpWrite(q, "<td>%s</td><td>%s</td></tr>\r\n", timeBuf, sizeBuf); } else if (dir->fancyIndexing == 1) { httpWrite(q, "<img src=\"/icons/%s.gif\" alt=\"[ ]\", /> ", icon); httpWrite(q, "<a href=\"%s%s\">%s%s</a>%-*s %17s %4s\r\n", ep->name, dirSuffix, ep->name, dirSuffix, nameSize - len, "", timeBuf, sizeBuf); } else { httpWrite(q, "<li><a href=\"%s%s\"> %s%s</a></li>\r\n", ep->name, dirSuffix, ep->name, dirSuffix); } }
void SignalGenerator::HandleCallBackResults( mapSymbol_t::iterator& iter, const std::string& sObject, const ou::tf::Bars& bars ) { // process bars here for ( ou::tf::Bars::const_iterator iterBars = bars.begin(); bars.end() != iterBars; ++iterBars ) { ou::tf::Price price( iterBars->DateTime(), iterBars->Close() ); iter->second.prices.Append( price ); // automatically updates indicators iter->second.emaVolume = ( ( iter->second.emaVolume * 19.0 + iterBars->Volume() ) / 20.0 ); // 20 day exponential moving average } ExcelFormat::CellFormat fmtNum( m_fmt_mgr ); fmtNum.set_format_string( XLS_FORMAT_DECIMAL ); ExcelFormat::CellFormat fmtInt( m_fmt_mgr ); fmtInt.set_format_string( XLS_FORMAT_INTEGER ); ExcelFormat::CellFormat fmtCenterTxt(m_fmt_mgr); fmtCenterTxt.set_alignment( ExcelFormat::EXCEL_HALIGN_CENTRED ); int iy = m_sheet->GetTotalRows(); ExcelFormat::BasicExcelCell* cell; int ix( 0 ); cell = m_sheet->Cell( iy, ix++ ); // Type cell->SetString( iter->second.sType.c_str() ); cell = m_sheet->Cell( iy, ix++ ); // Symbol cell->SetString( sObject.c_str() ); double last = bars.last().Close(); // Price cell = m_sheet->Cell( iy, ix++ ); cell->SetDouble( last ); cell->SetFormat( fmtNum ); cell = m_sheet->Cell( iy, ix++ ); // Volume cell->SetInteger( iter->second.emaVolume ); cell->SetFormat( fmtInt ); cell = m_sheet->Cell( iy, ix++ ); cell->SetFormat( fmtCenterTxt ); double upper = iter->second.pricesBollinger20.BBUpper(); double lower = iter->second.pricesBollinger20.BBLower(); double third = ( upper - lower ) / 3.0; if ( last > ( upper - third ) ) { std::cout << "u"; cell->SetString( "u" ); } else { if ( last < ( lower + third ) ) { std::cout << "l"; cell->SetString( "l" ); } else { std::cout << "m"; cell->SetString( "m" ); } } cell = m_sheet->Cell( iy, ix++ ); cell->SetFormat( fmtCenterTxt ); double sma1 = iter->second.pricesSMA1.MeanY(); double sma2 = iter->second.pricesSMA2.MeanY(); double sma3 = iter->second.pricesSMA3.MeanY(); if ( ( last > sma1 ) && ( sma1 > sma2 ) && ( sma2 > sma3 ) ) { std::cout << ">"; cell->SetString( ">" ); } if ( ( last < sma1 ) && ( sma1 < sma2 ) && ( sma2 < sma3 ) ) { std::cout << "<"; cell->SetString( "<" ); } std::cout << sObject << ": boll(" << lower << "," << upper << "),sma1(" << sma1 << "),sma2(" << sma2 << "),sma3(" << sma3 << ")" ; cell = m_sheet->Cell( iy, ix++ ); cell->SetFormat( fmtNum ); cell->SetDouble( upper ); cell = m_sheet->Cell( iy, ix++ ); cell->SetFormat( fmtNum ); cell->SetDouble( lower ); cell = m_sheet->Cell( iy, ix++ ); cell->SetFormat( fmtNum ); cell->SetDouble( sma1 ); cell = m_sheet->Cell( iy, ix++ ); cell->SetFormat( fmtNum ); cell->SetDouble( sma2 ); cell = m_sheet->Cell( iy, ix++ ); cell->SetFormat( fmtNum ); cell->SetDouble( sma3 ); ou::tf::statistics::Pivot pivot( bars ); std::cout << ",pivot(" << pivot.ItemOfInterest( ou::tf::statistics::Pivot::EItemsOfInterest::AbovePV ) << "," << pivot.ItemOfInterest( ou::tf::statistics::Pivot::EItemsOfInterest::AbovePV_X_Down ) << "," << pivot.ItemOfInterest( ou::tf::statistics::Pivot::EItemsOfInterest::BtwnPVR1_X_Up ) << "," << pivot.ItemOfInterest( ou::tf::statistics::Pivot::EItemsOfInterest::BtwnPVR1_X_Down ) << "," << pivot.ItemOfInterest( ou::tf::statistics::Pivot::EItemsOfInterest::BelowPV ) << "," << pivot.ItemOfInterest( ou::tf::statistics::Pivot::EItemsOfInterest::BelowPV_X_Up ) << "," << pivot.ItemOfInterest( ou::tf::statistics::Pivot::EItemsOfInterest::BtwnPVS1_X_Up ) << "," << pivot.ItemOfInterest( ou::tf::statistics::Pivot::EItemsOfInterest::BtwnPVS1_X_Down ) << "," << pivot.ItemOfInterest( ou::tf::statistics::Pivot::EItemsOfInterest::CrossPV ) << ")" ; cell = m_sheet->Cell( iy, ix++ ); cell->SetFormat( fmtNum ); cell->SetDouble( pivot.ItemOfInterest( ou::tf::statistics::Pivot::EItemsOfInterest::AbovePV ) ); cell = m_sheet->Cell( iy, ix++ ); cell->SetFormat( fmtNum ); cell->SetDouble( pivot.ItemOfInterest( ou::tf::statistics::Pivot::EItemsOfInterest::AbovePV_X_Down ) ); cell = m_sheet->Cell( iy, ix++ ); cell->SetFormat( fmtNum ); cell->SetDouble( pivot.ItemOfInterest( ou::tf::statistics::Pivot::EItemsOfInterest::BtwnPVR1_X_Up ) ); cell = m_sheet->Cell( iy, ix++ ); cell->SetFormat( fmtNum ); cell->SetDouble( pivot.ItemOfInterest( ou::tf::statistics::Pivot::EItemsOfInterest::BtwnPVR1_X_Down ) ); cell = m_sheet->Cell( iy, ix++ ); cell->SetFormat( fmtNum ); cell->SetDouble( pivot.ItemOfInterest( ou::tf::statistics::Pivot::EItemsOfInterest::BelowPV ) ); cell = m_sheet->Cell( iy, ix++ ); cell->SetFormat( fmtNum ); cell->SetDouble( pivot.ItemOfInterest( ou::tf::statistics::Pivot::EItemsOfInterest::BelowPV_X_Up ) ); cell = m_sheet->Cell( iy, ix++ ); cell->SetFormat( fmtNum ); cell->SetDouble( pivot.ItemOfInterest( ou::tf::statistics::Pivot::EItemsOfInterest::BtwnPVS1_X_Up ) ); cell = m_sheet->Cell( iy, ix++ ); cell->SetFormat( fmtNum ); cell->SetDouble( pivot.ItemOfInterest( ou::tf::statistics::Pivot::EItemsOfInterest::BtwnPVS1_X_Down ) ); cell = m_sheet->Cell( iy, ix++ ); cell->SetFormat( fmtNum ); cell->SetDouble( pivot.ItemOfInterest( ou::tf::statistics::Pivot::EItemsOfInterest::CrossPV ) ); std::cout << std::endl; }