/* * Calculate time required to move between certain prices * with certain initial direction of price change. * * PARAMETERS: * IN fStartPrice - price at the start of the time interval * IN fEndPrice - price at the end of the time interval * IN iStartDirection - direction (up or down) on the price curve at the start of the time interval * * RETURNS: * seconds required to move from the start price to the end price */ double CMEESecurity::CalculateTime( CMoney fStartPrice, CMoney fEndPrice, int iStartDirection) { int iHalfPeriod = m_iPeriod / 2; // Distance on the price curve from StartPrice to EndPrice (in dollars) // CMoney fDistance; // Amount of time (in seconds) needed to move $1 on the price curve. // In half a period the price moves over the entire price range. // double fSpeed = iHalfPeriod / m_fRange.DollarAmount(); if (fEndPrice > fStartPrice) { if (iStartDirection > 0) { fDistance = fEndPrice - fStartPrice; } else { fDistance = (fStartPrice - m_fRangeLow) + (fEndPrice - m_fRangeLow); } } else { if (iStartDirection > 0) { fDistance = (m_fRangeHigh - fStartPrice) + (m_fRangeHigh - fEndPrice); } else { fDistance = fStartPrice - fEndPrice; } } return fDistance.DollarAmount() * fSpeed; }
// Define / operator to make possible double operand on the left // double operator /(double l_f, CMoney r_m) { return l_f / r_m.DollarAmount(); }