当然不是,是TOS 程序做股票用的。这个是C++

本帖于 2023-02-06 04:54:14 时间, 由普通用户 va168 编辑
回答: 根本就不是c十十cheaterfinder2023-02-05 20:41:58

#include <iostream>
#include <vector>

// Calculate simple moving average (SMA)
double calcSMA(const std::vector<double>& data, int period)
{
    double sum = 0;
    for (int i = 0; i < period; i++)
        sum += data[data.size() - period + i];

    return sum / period;
}

int main()
{
    // Example data (OHLC)
    std::vector<double> data = { 100, 105, 102, 108, 110, 109, 112 };

    // Periods for moving averages
    int ma5 = 5, ma13 = 13;

    // Calculate the moving averages
    std::vector<double> ma5_values, ma13_values;
    for (int i = 0; i < data.size(); i++)
    {
        if (i + 1 >= ma5)
            ma5_values.push_back(calcSMA(data, ma5));

        if (i + 1 >= ma13)
            ma13_values.push_back(calcSMA(data, ma13));
    }

    // Check for moving average crossover
    for (int i = 0; i < ma5_values.size(); i++)
    {
        if (ma5_values[i] > ma13_values[i] && ma5_values[i - 1] <= ma13_values[i - 1])
            std::cout << "MA5 crosses above MA13 at index " << i << std::endl;
        else if (ma5_values[i] < ma13_values[i] && ma5_values[i - 1] >= ma13_values[i - 1])
            std::cout << "MA5 crosses below MA13 at index " << i << std::endl;
    }

    return 0;
}

请您先登陆,再发跟帖!