public void clac2(double dPrice_A, double dPrice_B, int nPeriod, ETIME_FRAME nTimeFrame = ETIME_FRAME.MIN1, EPRICE_MODE nPriceMode = EPRICE_MODE.BID, EPRICE_VAL nPriceVal = EPRICE_VAL.CLOSE) { if (m_cacheData_A.getTickCount() < nPeriod) { m_indVals[IND_MAIN] = 0; m_indVals[IND_CC] = 1; return; } double sumyy = 0, sumxyxy = 0; double x, y, xx, yy; for (int i = 0; i < nPeriod; i++) { x = getPrice(m_cacheData_A, i, nTimeFrame, nPriceMode, nPriceVal); y = getPrice(m_cacheData_B, i, nTimeFrame, nPriceMode, nPriceVal); xx = getPrice(m_cacheData_A, i + 1, nTimeFrame, nPriceMode, nPriceVal); yy = getPrice(m_cacheData_B, i + 1, nTimeFrame, nPriceMode, nPriceVal); sumyy += y * yy; sumxyxy += x * yy + xx * y; } m_indVals[IND_CC] = sumxyxy / sumyy / 2; m_indVals[IND_MAIN] = dPrice_A - dPrice_B * m_indVals[IND_CC]; m_cacheData_main.pushTick(m_indVals[IND_MAIN], m_indVals[IND_MAIN], CFATCommon.m_dtCurTime); }
public void calc(double dPrice_A, double dPrice_B, int nPeriod, ETIME_FRAME nTimeFrame = ETIME_FRAME.MIN1, EPRICE_MODE nPriceMode = EPRICE_MODE.BID, EPRICE_VAL nPriceVal = EPRICE_VAL.CLOSE) { if (m_cacheData_A.getTickCount() < nPeriod) { m_indVals[IND_MAIN] = 0; m_indVals[IND_CC] = 1; return; } double sumx = 0, sumy = 0, sumxx = 0, sumyy = 0, sumxyxy = 0, sumxy = 0; double dRet = 0; double x, y, xx, yy; for (int i = 0; i < nPeriod; i++) { x = getPrice(m_cacheData_A, i, nTimeFrame, nPriceMode, nPriceVal); y = getPrice(m_cacheData_B, i, nTimeFrame, nPriceMode, nPriceVal); xx = getPrice(m_cacheData_A, i + 1, nTimeFrame, nPriceMode, nPriceVal); yy = getPrice(m_cacheData_B, i + 1, nTimeFrame, nPriceMode, nPriceVal); sumx += x * x; sumxx += x * xx; sumy += y * y; sumyy += y * yy; sumxy += x * y; sumxyxy += x * yy + xx * y; } double a, b, c; a = sumy * sumxyxy - 2 * sumxy * sumyy; b = sumyy * sumx - sumy * sumxx; c = 2 * sumxy * sumxx - sumxyxy * sumx; dRet = (Math.Sqrt(b * b - a * c) - b) / a; m_indVals[IND_CC] = dRet; //m_indVals[IND_MAIN] = dPrice_A - m_indVals[IND_CC] * 31.103477; //For Logic_Pair_V3 m_indVals[IND_MAIN] = dPrice_A - dPrice_B * dRet; m_cacheData_main.pushTick(m_indVals[IND_MAIN], m_indVals[IND_MAIN], CFATCommon.m_dtCurTime); // string sRates = string.Format("{0},{1}", CFATCommon.m_dtCurTime, m_dIndVal); // CFATLogger.record_rates("Test\\CC", sRates); }
public void calc(int nPeriod, ETIME_FRAME nTimeFrame = ETIME_FRAME.MIN1, EPRICE_MODE nPriceMode = EPRICE_MODE.BID, EPRICE_VAL nPriceVal = EPRICE_VAL.CLOSE) { m_indSTD.calc(nPeriod, nTimeFrame, nPriceMode, nPriceVal); m_indMA.calc(nPeriod, nTimeFrame, nPriceMode, nPriceVal); double dStd = m_indSTD.getVal(); m_indVals[IND_BAND_MID] = m_indMA.getVal(); m_indVals[IND_BAND_UP] = m_indVals[IND_BAND_MID] + 2 * dStd; m_indVals[IND_BAND_DOWN] = m_indVals[IND_BAND_MID] - 2 * dStd; // string sRates = string.Format("{0},{1},{2},{3},{4}", CFATCommon.m_dtCurTime, // m_cacheData_A.getTick(0).getMid(), // m_indVals[IND_BAND_UP], m_indVals[IND_BAND_MID], m_indVals[IND_BAND_DOWN]); // CFATLogger.record_rates("Test\\Band", sRates); }
public void calc(int nPeriod, ETIME_FRAME nTimeFrame = ETIME_FRAME.MIN1, EPRICE_MODE nPriceMode = EPRICE_MODE.BID, EPRICE_VAL nPriceVal = EPRICE_VAL.CLOSE) { if (nPeriod == 0) { m_indVals[IND_MAIN] = 0; return; } double dRet = 0; for (int i = 0; i < nPeriod; i++) { dRet += getPrice(m_cacheData_A, i, nTimeFrame, nPriceMode, nPriceVal); } m_indVals[IND_MAIN] = dRet / nPeriod; }
public void calc(int nPeriod, ETIME_FRAME nTimeFrame = ETIME_FRAME.MIN1, EPRICE_MODE nPriceMode = EPRICE_MODE.BID, EPRICE_VAL nPriceVal = EPRICE_VAL.CLOSE) { m_indMA.calc(nPeriod, nTimeFrame, nPriceMode, nPriceVal); double dSum = 0; double dVal = 0; if (nPeriod == 0) { m_indVals[IND_MAIN] = 0; return; } double dMA = m_indMA.getVal(); for (int i = 0; i < nPeriod; i++) { dVal = getPrice(m_cacheData_A, i, nTimeFrame, nPriceMode, nPriceVal); dSum += (dVal - dMA) * (dVal - dMA); } m_indVals[IND_MAIN] = Math.Sqrt(dSum / nPeriod); }
public double getPrice(CCacheData cacheData, int nPos, ETIME_FRAME nTimeFrame = ETIME_FRAME.MIN1, EPRICE_MODE nPriceMode = EPRICE_MODE.BID, EPRICE_VAL nPriceVal = EPRICE_VAL.CLOSE) { double dRet = 0; if (nTimeFrame == ETIME_FRAME.MIN1) { if (nPriceMode == EPRICE_MODE.ASK) { if (nPriceVal == EPRICE_VAL.OPEN) { return(cacheData.getMin(nPos).dAsk_open); } if (nPriceVal == EPRICE_VAL.HIGH) { return(cacheData.getMin(nPos).dAsk_high); } if (nPriceVal == EPRICE_VAL.LOW) { return(cacheData.getMin(nPos).dAsk_low); } if (nPriceVal == EPRICE_VAL.CLOSE) { return(cacheData.getMin(nPos).dAsk_close); } } if (nPriceMode == EPRICE_MODE.BID) { if (nPriceVal == EPRICE_VAL.OPEN) { return(cacheData.getMin(nPos).dBid_open); } if (nPriceVal == EPRICE_VAL.HIGH) { return(cacheData.getMin(nPos).dBid_high); } if (nPriceVal == EPRICE_VAL.LOW) { return(cacheData.getMin(nPos).dBid_low); } if (nPriceVal == EPRICE_VAL.CLOSE) { return(cacheData.getMin(nPos).dBid_close); } } } if (nTimeFrame == ETIME_FRAME.TICK) { if (nPriceMode == EPRICE_MODE.ASK) { return(cacheData.getTick(nPos).dAsk); } if (nPriceMode == EPRICE_MODE.BID) { return(cacheData.getTick(nPos).dBid); } } return(dRet); }