Example #1
0
double TechUtils::CalulateWMA(const std::vector<TickWrapper>& data, const TickWrapper& current, size_t seconds)
{
	//datetime to timestamp
	size_t n = seconds * 2;
	double totalExchangeLastPrice = current.LastPrice() * n;
	long long count = n--;

	long long leftedge = current.toTimeStamp() - seconds * 2;

	for (auto it = data.rbegin(); it != data.rend(); it++)
	{
		if (it->toTimeStamp() > leftedge){
			totalExchangeLastPrice += (it->LastPrice() * n);
			--n;
			count += n;
		}
		else{
			break;
		}
	}

	//assert(totalVolume != 0);
	//assert(totalExchangePrice >= 0.0);

	return totalExchangeLastPrice / count;
}
Example #2
0
    void DoubleMAStrategy::Run()
    {
        if (fast_ma->Count() <= 1 || slow_ma->Count() <= 1)
            return;

        double fv1 = fast_ma->get(1);
        double fv0 = fast_ma->get(0);
        double sv1 = slow_ma->get(1);
        double sv0 = slow_ma->get(0);

        if (fv1 < sv1 && fv0 > sv0)
        {
            cout << "Up Cross" << endl;
            SendOrder(inst, Order::Buy, 1, LastPrice());
        }

        if (fv1 > sv1 && fv0 < sv0)
        {
            cout << "Down Cross" << endl;
            SendOrder(inst, Order::Sell, 1, LastPrice());
        }
    }
Example #3
0
double TechUtils::CalulateMA(const std::vector<KData>& data, const KData& current, size_t mins){
	//datetime to timestamp
	double totalExchangeLastPrice = current.LastPrice();
	long long count = 1;

	long long leftedge = current.Timestamp() - mins * 60 - 1;
	for (auto it = data.rbegin(); it != data.rend(); it++)
	{
		if (it->Timestamp() > leftedge){
			totalExchangeLastPrice += it->LastPrice();
			++count;
		}
		else{
			break;
		}
	}

	//assert(totalVolume != 0);
	//assert(totalExchangePrice >= 0.0);

	return totalExchangeLastPrice / count;
}
Example #4
0
double TechUtils::CalulateMA(const std::list<TickWrapper>& data, const TickWrapper& current, size_t seconds)
{
	//datetime to timestamp
	double totalExchangeLastPrice = current.LastPrice();
	long long count = 1;

	long long leftedge = current.toTimeStamp() - seconds * 2;
	for (auto it = data.begin(); it != data.end(); it++)
	{
		if (it->toTimeStamp() > leftedge){
			totalExchangeLastPrice += it->LastPrice();
			++count;
		}
		else{
			break;
		}
	}

	//assert(totalVolume != 0);
	//assert(totalExchangePrice >= 0.0);

	return totalExchangeLastPrice / count;
}