bool TighteningStops::stop(const std::string & symbol, double changeFromOpen, double changeFromBest, double bestPrice, double percentBest) { double atr = getATR(symbol, 20); if(atr < .04) { atr = .04; } if((changeFromOpen > (4.0 * atr) && (bestPrice - changeFromBest)/bestPrice < .9) || (changeFromOpen > (3.0 * atr) && (bestPrice - changeFromBest)/bestPrice < .7) || (changeFromOpen > (2.0 * atr) && (bestPrice - changeFromBest)/bestPrice < .4)) { if((changeFromOpen > (4.0 * atr) && (bestPrice - changeFromBest)/bestPrice < .9)) { reason_ = "4 ATR rule!"; } else if((changeFromOpen > (3.0 * atr) && (bestPrice - changeFromBest)/bestPrice < .7)) { reason_ = "3 ATR rule!"; } else if((changeFromOpen > (2.0 * atr) && (bestPrice - changeFromBest)/bestPrice < .4)) { reason_ = "2 ATR rule!"; } return true; } return false; }
bool scard_power_on(ISO7816_SC* pScard) { if (!getATR(pScard)) // Try to get ATR return false; parseATR(pScard); // Parse ATR ang replace the Historical bytes if needed if(!pps_exchange(pScard)) // PPS exchange to default settings if no error return false; pScard->State = scs_Idle; // Switch card state return true; }
int TurtlePositionSizing::calculateSize(const std::string & symbol, const double price) { long quantity = 0; double startBP = AccountManager::instance()->getStartBuyingPower(); double BP = AccountManager::instance()->getBP(); double ATR = getATR(symbol, 20); if(ATR > 0.0) { quantity = (long)((0.01 * startBP)/(ATR * price)); if(quantity * price > BP) { quantity = 0; } } return quantity; }