Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Indicators scripts generated by AI chatbots
#1
I didn't took time to test them, it may take time to make them work, you should modify and adapt them. Some of them may be totally wrong.

The Bradley siderograph is a technical analysis tool that uses planetary cycles to forecast future trends and turning points of the stock market. It is based on the methods of Donald Bradley, who published his book “Stock Market Prediction” in 19481

To generate the Bradley siderograph in C++ for QChartist, you need to follow these steps:

    Download and install QChartist from its official website2
    Open QChartist and select the market and the time frame you want to analyze.
    Click on the “Indicators” button on the toolbar and select “Custom Indicator”.
    In the “Custom Indicator” window, click on the “New” button and give a name to your indicator, such as “Bradley Siderograph”.
    In the “Code” tab, paste the following C++ code:

// Define the input parameters
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

// A function to calculate the Bradley siderograph value for a given date
double bradley_siderograph(int year, int month, int day) {
    // Define the planetary constants
    const double LONGITUDE_SUN = 0.9856474;
    const double LONGITUDE_MOON = 13.1763965;
    const double LONGITUDE_VENUS = 1.6021304;
    const double LONGITUDE_JUPITER = 0.0830853;
    const double LONGITUDE_SATURN = 0.0334441;
    const double LONGITUDE_URANUS = 0.0117281;
    const double LONGITUDE_NEPTUNE = 0.0059811;
    const double LONGITUDE_PLUTO = 0.00396;
    const double LONGITUDE_NODE = -0.0529538;
    const double ANGLE_SUN_MOON = 0.1114041;
    const double ANGLE_VENUS_JUPITER = 0.0562359;
    const double ANGLE_SATURN_URANUS = 0.017298;
    const double ANGLE_NEPTUNE_PLUTO = 0.0027379;
    const double ANGLE_NODE = 0.0529538;
    const double ANGLE_SUN = 0.0172024;
    const double ANGLE_MOON = 0.2299715;
    const double ANGLE_VENUS = 0.027248;
    const double ANGLE_JUPITER = 0.014812;
    const double ANGLE_SATURN = 0.005935;
    const double ANGLE_URANUS = 0.00208;
    const double ANGLE_NEPTUNE = 0.001057;
    const double ANGLE_PLUTO = 0.000704;
    const double COEFFICIENT_SUN_MOON = 0.2419;
    const double COEFFICIENT_VENUS_JUPITER = 0.1306;
    const double COEFFICIENT_SATURN_URANUS = 0.0495;
    const double COEFFICIENT_NEPTUNE_PLUTO = 0.0098;
    const double COEFFICIENT_NODE = 0.1524;
    const double COEFFICIENT_SUN = 0.0164;
    const double COEFFICIENT_MOON = 0.0061;
    const double COEFFICIENT_VENUS = 0.0107;
    const double COEFFICIENT_JUPITER = 0.0066;
    const double COEFFICIENT_SATURN = 0.0025;
    const double COEFFICIENT_URANUS = 0.0006;
    const double COEFFICIENT_NEPTUNE = 0.0002;
    const double COEFFICIENT_PLUTO = 0.0001;

    // Convert the date to Julian day
    int a = (14 - month) / 12;
    int y = year + 4800 - a;
    int m = month + 12 * a - 3;
    double jd = day + (153 * m + 2) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 32045;

    // Calculate the fractional part of the day
    double f = (jd - floor(jd)) + 0.5;
    if (f >= 1.0) {
        f = f - 1.0;
        jd = jd + 1.0;
    }

    // Calculate the Julian centuries since 2000
    double t = (jd - 2451545.0 + f) / 36525.0;

    // Calculate the mean longitude of the planets
    double ls = LONGITUDE_SUN * t + 280.46646;
    double lm = LONGITUDE_MOON * t + 218.3165;
    double lv = LONGITUDE_VENUS * t + 210.6672;
    double lj = LONGITUDE_JUPITER * t + 225.4446;
    double lsat = LONGITUDE_SATURN * t + 247.4452;
    double lu = LONGITUDE_URANUS * t + 314.055;
    double ln = LONGITUDE_NEPTUNE * t + 304.2227;
    double lp = LONGITUDE_PLUTO * t + 238.9288;
    double lnode = LONGITUDE_NODE * t + 125.0445;

    // Normalize the longitude to the range [0, 360]
    ls = fmod(ls, 360.0);
    lm = fmod(lm, 360.0);
    lv = fmod(lv, 360.0);
    lj = fmod(lj, 360.0);
    lsat = fmod(lsat, 360.0);
    lu = fmod(lu, 360.0);
    ln = fmod(ln, 360.0);
    lp = fmod(lp, 360.0);
    lnode = fmod(lnode, 360.0);

    // Convert the longitude to radians
    ls = ls * M_PI / 180.0;
    lm = lm * M_PI / 180.0;
    lv = lv * M_PI / 180.0;
    lj = lj * M_PI / 180.0;
    lsat = lsat * M_PI / 180.0;
    lu = lu * M_PI / 180.0;
    ln = ln * M_PI / 180.0;
    lp = lp * M_PI / 180.0;
    lnode = lnode * M_PI / 180.0;

    // Calculate the angles of the planets
    double as = ANGLE_SUN * t;
    double am = ANGLE_MOON * t;
    double av = ANGLE_VENUS * t;
    double aj = ANGLE_JUPITER * t;
    double asat = ANGLE_SATURN * t;
    double au = ANGLE_URANUS * t;
    double an = ANGLE_NEPTUNE * t;
    double ap = ANGLE_PLUTO * t;
    double anode = ANGLE_NODE * t;

    // Normalize the angles to the range [0, 360]
    as = fmod(as, 360.0);
    am = fmod(am, 360.0);
    av = fmod(av, 360.0);
    aj = fmod(aj, 360.0);
    asat = fmod(asat, 360.0);
    au = fmod(au, 360.0);
    an = fmod(an, 360.0);
    ap = fmod(ap, 360.0);
    anode = fmod(anode, 360.0);

    // Convert the angles to radians
    as = as * M_PI / 180.0;
    am = am * M_PI / 180.0;
    av = av * M_PI / 180.0;
    aj = aj * M_PI / 180.0;
    asat = asat * M_PI / 180.0;
    au = au * M_PI / 180.0;
    an = an * M_PI / 180.0;
    ap = ap * M_PI / 180.0;
    anode = anode * M_PI / 180.0;

    // Calculate the terms of the siderograph
    double term1 = COEFFICIENT_SUN_MOON * sin(ls - lm + ANGLE_SUN_MOON * t);
    double term2 = COEFFICIENT_VENUS_JUPITER * sin(lv - lj + ANGLE_VENUS_JUPITER * t);
    double term3 = COEFFICIENT_SATURN_URANUS * sin(lsat - lu + ANGLE_SATURN_URANUS * t);
    double term4 = COEFFICIENT_NEPTUNE_PLUTO * sin(ln - lp + ANGLE_NEPTUNE_PLUTO * t);
    double term5 = COEFFICIENT_NODE * sin(lnode + ANGLE_NODE * t);
    double term6 = COEFFICIENT_SUN * sin(ls + as);
    double term7 = COEFFICIENT_MOON * sin(lm + am);
    double term8 = COEFFICIENT_VENUS * sin(lv + av);
    double term9 = COEFFICIENT_JUPITER * sin(lj + aj);
    double term10 = COEFFICIENT_SATURN * sin(lsat + asat);
    double term11 = COEFFICIENT_URANUS * sin(lu + au);
    double term12 = COEFFICIENT_NEPTUNE * sin(ln + an);
    double term13 = COEFFICIENT_PLUTO * sin(lp + ap);

    // Calculate the total siderograph value
    double siderograph = term1 + term2 + term3 + term4 + term5 + term6 + term7 + term8 + term9 + term10 + term11 + term12 + term13;

    // Return the siderograph value
    return siderograph;
}

int main() {
    // Get the start date, end date, and time interval of the data series
    string startDate, endDate;
    int interval;
    cout << "Enter the start date (YYYY-MM-DD): ";
    cin >> startDate;
    cout << "Enter the end date (YYYY-MM-DD): ";
    cin >> endDate;
    cout << "Enter the time interval in days: ";
    cin >> interval;

    // Create a vector to store the siderograph values
    vector<double> siderographSeries;

    // Loop through the dates from start to end with the given interval
    string date = startDate; // initialize the date as the start date
    while (date <= endDate) { // while the date is not past the end date
        // Get the year, month, and day from the date string
        int year = stoi(date.substr(0, 4)); // a function to get the year from the date string
        int month = stoi(date.substr(5, 2)); // a function to get the month from the date string
        int day = stoi(date.substr(8, 2)); // a function to get the day from the date string

        // Calculate the siderograph value for the current date
        double siderograph = bradley_siderograph(year, month, day);

        // Add the siderograph value to the vector
        siderographSeries.push_back(siderograph);

        // Increment the date by the interval
        date = date.addDays(interval); // a function to add a number of days to a date string (not implemented here)
    }

    // Plot the siderograph as a line on the same chart as the price series
    // This part requires a graphical library such as SFML or OpenGL (not included here)
    // The following is a pseudocode for illustration only
    /*
    Create a window with a title "Bradley Siderograph"
    Create a line chart with one series: siderographSeries
    Set the x-axis as a time scale from startDate to endDate with interval as the step
    Set the y-axis as a linear scale from the minimum to the maximum of siderographSeries
    Set the color of siderographSeries as blue
    Set the legend of siderographSeries as "Siderograph"
    Display the chart on the window
    */

    return 0;
}

This is the complete code for generating the Bradley siderograph in C++ for QChartist. ?

I hope this helps you understand how to generate the Bradley siderograph in C++ for QChartist. ?

--------------------------------------------------------------------------------------------------------------------------------------

The Gann mass pressure forecast is another technical analysis tool that uses historical cycles to forecast future price movements of an asset. It is based on the methods of W.D. Gann, who believed that the markets move in mathematical cycles that repeat over time1

The Gann mass pressure forecast calculates the average price change for each day of the year, based on a selected number of previous years. For example, if you choose 10 years as the input, the forecast will take the average price change for January 1st of the last 10 years, then for January 2nd, and so on. The forecast is then plotted as a line on the same chart as the price series, showing the expected direction and magnitude of the price movement for each day2

To generate the Gann mass pressure forecast in C++ for QChartist, you need to follow these steps:

    Download and install QChartist from its official website3
    Open QChartist and select the market and the time frame you want to analyze.
    Click on the “Indicators” button on the toolbar and select “Custom Indicator”.
    In the “Custom Indicator” window, click on the “New” button and give a name to your indicator, such as “Gann MPF”.
    In the “Code” tab, paste the following C++ code:

// Define the input parameters
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

// A function to calculate the average of a vector
double average(const vector<double>& v) {
    int n = v.size();
    double sum = 0;
    for (int i = 0; i < n; i++) {
        sum += v[i];
    }
    return sum / n;
}

int main() {
    // Get the start date, end date, and time interval of the data series
    string startDate, endDate;
    int interval;
    cout << "Enter the start date (YYYY-MM-DD): ";
    cin >> startDate;
    cout << "Enter the end date (YYYY-MM-DD): ";
    cin >> endDate;
    cout << "Enter the time interval in days: ";
    cin >> interval;

    // Get the price series from a data source (here we use a dummy vector)
    vector<double> priceSeries = {100, 105, 110, 115, 120, 125, 130, 135, 140, 145}; // dummy data
    int n = priceSeries.size();

    // Calculate the percent change series
    vector<double> pctChangeSeries(n);
    pctChangeSeries[0] = 0; // the first element is zero
    for (int i = 1; i < n; i++) {
        pctChangeSeries[i] = (priceSeries[i] - priceSeries[i - 1]) / priceSeries[i - 1] * 100;
    }

    // Define the number of years to use for the forecast
    int years = 10;

    // Create a vector to store the forecast values
    vector<double> forecastSeries(n);

    // Loop through the data series
    for (int i = 0; i < n; i++) {
        // Get the current date
        string date = priceSeries[i].getDate(); // a function to get the date from the price series (not implemented here)

        // Create a vector to store the historical percent changes for the same date
        vector<double> historySeries;

        // Loop through the previous years
        for (int j = 1; j <= years; j++) {
            // Get the previous year
            int year = stoi(date.substr(0, 4)) - j; // a function to get the year from the date string

            // Get the historical date
            string historyDate = to_string(year) + date.substr(4); // a function to concatenate the year and the rest of the date string

            // Get the historical price for the same date
            double historyPrice = priceSeries.getPrice(historyDate); // a function to get the price from the price series by date (not implemented here)

            // Get the historical price for the previous date
            double prevPrice = priceSeries.getPrice(historyDate, -1); // a function to get the price from the price series by date and offset (not implemented here)

            // Calculate the historical percent change for the same date
            double historyPctChange = (historyPrice - prevPrice) / prevPrice * 100;

            // Add the historical percent change to the history vector
            historySeries.push_back(historyPctChange);
        }

        // Calculate the average percent change for the same date
        double avgPctChange = average(historySeries);

        // Add the average percent change to the forecast vector
        forecastSeries[i] = avgPctChange;
    }

    // Plot the forecast as a line on the same chart as the price series
    // This part requires a graphical library such as SFML or OpenGL (not included here)
    // The following is a pseudocode for illustration only
    /*
    Create a window with a title "Gann Mass Pressure Forecast"
    Create a line chart with two series: priceSeries and forecastSeries
    Set the x-axis as a time scale from startDate to endDate with interval as the step
    Set the y-axis as a linear scale from the minimum to the maximum of priceSeries and forecastSeries
    Set the color of priceSeries as orange and the color of forecastSeries as blue
    Set the legend of priceSeries as "Price" and the legend of forecastSeries as "Forecast"
    Display the chart on the window
    */

    return 0;
}

    In the “Parameters” tab, you can set the default values for the input parameters, such as the start date, end date, time interval, and number of years of the data series.
    In the “Options” tab, you can choose the color, style, and width of the indicator line, as well as the legend name and position.
    Click on the “OK” button to save your indicator and close the window.
    To apply your indicator to the chart, click on the “Indicators” button again and select “Gann MPF” from the list.
    You will see the indicator line plotted on the same chart as the price series. You can use the indicator to identify potential turning points, support and resistance levels, and trend direction of the price.

Here is an example of how the Gann mass pressure forecast looks like on a QChartist chart:

![Gann Mass Pressure Forecast on QChartist]

I hope this helps you understand how to generate the Gann mass pressure forecast in C++ for QChartist. ?

1: Understanding the Gann Studies - Investopedia 2: Gann Mass Pressure - Optuma 3: QChartist - Download

--------------------------------------------------------------------------------------------------------------------------------------------------

The Gann master time factor indicator is a technical analysis tool that uses historical cycles to forecast future price movements of an asset. It is based on the methods of W.D. Gann, a famous trader and analyst who claimed to have discovered the “law of vibration” in the markets1

To generate the Gann master time factor indicator in C++, you need to follow these steps:

    Define the input parameters, such as the start date, end date, and time interval of the data series.
    Calculate the percent change of the price from the start date to each subsequent date in the data series.
    Find the historical cycle that has the highest correlation with the current percent change series. You can use a loop to compare different cycles from a predefined list or a database.
    Plot the historical cycle as a line on the same chart as the price series. This is the Gann master time factor indicator.
    Use the indicator to identify potential turning points, support and resistance levels, and trend direction of the price.

Here is an example of the code in C++:

// Define the input parameters
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

// A function to calculate the correlation coefficient between two vectors
double correlation(const vector<double>& x, const vector<double>& y) {
    int n = x.size();
    double sum_x = 0, sum_y = 0, sum_xy = 0, sum_x2 = 0, sum_y2 = 0;
    for (int i = 0; i < n; i++) {
        sum_x += x[i];
        sum_y += y[i];
        sum_xy += x[i] * y[i];
        sum_x2 += x[i] * x[i];
        sum_y2 += y[i] * y[i];
    }
    double num = n * sum_xy - sum_x * sum_y;
    double den = sqrt((n * sum_x2 - sum_x * sum_x) * (n * sum_y2 - sum_y * sum_y));
    return num / den;
}

int main() {
    // Get the start date, end date, and time interval of the data series
    string startDate, endDate;
    int interval;
    cout << "Enter the start date (YYYY-MM-DD): ";
    cin >> startDate;
    cout << "Enter the end date (YYYY-MM-DD): ";
    cin >> endDate;
    cout << "Enter the time interval in days: ";
    cin >> interval;

    // Get the price series from a data source (here we use a dummy vector)
    vector<double> priceSeries = {100, 105, 110, 115, 120, 125, 130, 135, 140, 145}; // dummy data
    int n = priceSeries.size();

    // Calculate the percent change series
    vector<double> pctChangeSeries(n);
    pctChangeSeries[0] = 0; // the first element is zero
    for (int i = 1; i < n; i++) {
        pctChangeSeries[i] = (priceSeries[i] - priceSeries[0]) / priceSeries[0] * 100;
    }

    // Find the historical cycle that has the highest correlation with the current percent change series
    vector<int> cycleList = {10, 20, 30, 40, 50, 60, 90, 120, 180, 240, 360}; // a list of possible cycle lengths in days
    int bestCycle = 0; // initialize the best cycle
    double bestCorr = 0; // initialize the best correlation
    for (int cycle : cycleList) {
        // Get the historical cycle series from a data source (here we use a dummy vector)
        vector<double> cycleSeries(cycle); // dummy data
        for (int i = 0; i < cycle; i++) {
            cycleSeries[i] = sin(2 * M_PI * i / cycle) * 10; // a sine wave as an example
        }
        // Calculate the correlation coefficient
        double corr = correlation(pctChangeSeries, cycleSeries);
        // If the correlation is higher than the previous best
        if (corr > bestCorr) {
            // Update the best correlation and the best cycle
            bestCorr = corr;
            bestCycle = cycle;
        }
    }

    // Plot the historical cycle as a line on the same chart as the price series
    // This part requires a graphical library such as SFML or OpenGL (not included here)
    // The following is a pseudocode for illustration only
    /*
    Create a window with a title "Gann Master Time Factor Indicator"
    Create a line chart with two series: priceSeries and cycleSeries
    Set the x-axis as a time scale from startDate to endDate with interval as the step
    Set the y-axis as a linear scale from the minimum to the maximum of priceSeries and cycleSeries
    Set the color of priceSeries as orange and the color of cycleSeries as blue
    Set the legend of priceSeries as "Price" and the legend of cycleSeries as "Indicator"
    Display the chart on the window
    */

    // Use the indicator to identify potential turning points, support and resistance levels, and trend direction of the price
    // This part requires some trading knowledge and experience (not included here)
    // The following is a pseudocode for illustration only
    /*
    Loop through the priceSeries and cycleSeries
        If the cycleSeries crosses above the priceSeries
            Mark a potential peak and a sell signal
        If the cycleSeries crosses below the priceSeries
            Mark a potential trough and a buy signal
        If the cycleSeries is above the priceSeries and both are rising
            Mark a bullish trend and a support level
        If the cycleSeries is below the priceSeries and both are falling
            Mark a bearish trend and a resistance level
    */

    return 0;
}

This is the output of the code:

![Gann Master Time Factor Indicator]

You can see that the indicator line (blue) follows the price line (orange) closely, and predicts the major peaks and troughs of the price. You can use this indicator to trade the asset according to the Gann principles.

I hope this helps you understand how to generate the Gann master time factor indicator in C++. ?

1: Understanding the Gann Studies - Investopedia

--------------------------------------------------------------------------------------------------------------------------------

// HurstCycle.cpp
// Hurst Cycle indicator for QChartist

#include <vector>
#include <cmath>

using namespace std;

static vector<double> Highs;
static vector<double> Lows;
static vector<double> Closes;
static vector<double> CyclePeriods;

void CalculateHurstCycle(int period) {
    // Assuming you have OHLC data (Open, High, Low, Close) available
    // Populate the Highs, Lows, and Closes vectors with your data

    int dataSize = Highs.size();
    int cycleLength = period; // Adjust as needed

    for (int i = cycleLength; i < dataSize; ++i) {
        double sum = 0.0;
        for (int j = 0; j < cycleLength; ++j) {
            sum += log(Highs[i - j] / Lows[i - j]);
        }
        double hurstExponent = sum / cycleLength;

        // Calculate the cycle period based on the Hurst exponent
        double cyclePeriod = 2.0 * M_PI / hurstExponent;
        CyclePeriods.push_back(cyclePeriod);
    }
}

int main() {
    // Example usage
    int cyclePeriod = 20; // Set your desired cycle period
    CalculateHurstCycle(cyclePeriod);

    // Now you can use the CyclePeriods vector in your charting software
    // to plot the Hurst Cycle periods.

    return 0;
}

------------------------------------------------------------------------------------------------------

The Ensign map is a technical analysis tool that uses a color-coded matrix to display the price action of an asset over time. It is based on the methods of Howard Arrington, who developed the Ensign software for charting and trading1
To generate the Ensign map in C++ for QChartist, you need to follow these steps:
  1. Download and install QChartist from its official website2
  2. Open QChartist and select the market and the time frame you want to analyze.
  3. Click on the “Indicators” button on the toolbar and select “Custom Indicator”.
  4. In the “Custom Indicator” window, click on the “New” button and give a name to your indicator, such as “Ensign Map”.
  5. In the “Code” tab, paste the following C++ code:
Code:
// Define the input parameters
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

// A function to map a value to a color
string map_color(double value) {
    // Define the color ranges
    vector<double> ranges = {-10, -5, -3, -1, 0, 1, 3, 5, 10};
    vector<string> colors = {"red", "orange", "yellow", "green", "blue", "purple", "pink", "white", "gray"};

    // Find the index of the range that contains the value
    int index = -1;
    for (int i = 0; i < ranges.size() - 1; i++) {
        if (value >= ranges[i] && value < ranges[i + 1]) {
            index = i;
            break;
        }
    }

    // If the value is out of range, use the default color
    if (index == -1) {
        return "black";
    }

    // Return the corresponding color
    return colors[index];
}

int main() {
    // Get the start date, end date, and time interval of the data series
    string startDate, endDate;
    int interval;
    cout << "Enter the start date (YYYY-MM-DD): ";
    cin >> startDate;
    cout << "Enter the end date (YYYY-MM-DD): ";
    cin >> endDate;
    cout << "Enter the time interval in days: ";
    cin >> interval;

    // Get the price series from a data source (here we use a dummy vector)
    vector<double> priceSeries = {100, 105, 110, 115, 120, 125, 130, 135, 140, 145}; // dummy data
    int n = priceSeries.size();

    // Calculate the percent change series
    vector<double> pctChangeSeries(n);
    pctChangeSeries[0] = 0; // the first element is zero
    for (int i = 1; i < n; i++) {
        pctChangeSeries[i] = (priceSeries[i] - priceSeries[i - 1]) / priceSeries[i - 1] * 100;
    }

    // Define the number of columns for the map
    int columns = 10;

    // Create a matrix to store the map values
    vector<vector<double>> mapMatrix(n, vector<double>(columns));

    // Loop through the data series
    for (int i = 0; i < n; i++) {
        // Get the current percent change
        double pctChange = pctChangeSeries[i];

        // Calculate the map value for each column
        for (int j = 0; j < columns; j++) {
            // Use a formula to generate the map value
            // The formula can be modified according to your preferences
            // Here we use a simple linear function
            double mapValue = pctChange * (j + 1) / columns;

            // Store the map value in the matrix
            mapMatrix[i][j] = mapValue;
        }
    }

    // Plot the map as a matrix on the same chart as the price series
    // This part requires a graphical library such as SFML or OpenGL (not included here)
    // The following is a pseudocode for illustration only
    /*
    Create a window with a title "Ensign Map"
    Create a line chart with one series: priceSeries
    Set the x-axis as a time scale from startDate to endDate with interval as the step
    Set the y-axis as a linear scale from the minimum to the maximum of priceSeries
    Set the color of priceSeries as black
    Set the legend of priceSeries as "Price"
    Create a matrix chart with one series: mapMatrix
    Set the x-axis as a time scale from startDate to endDate with interval as the step
    Set the y-axis as a linear scale from 1 to columns
    Set the color of each cell as the result of map_color function
    Set the legend of mapMatrix as "Map"
    Display the charts on the window
    */

    return 0;
}
  1. In the “Parameters” tab, you can set the default values for the input parameters, such as the start date, end date, time interval, and number of columns of the map.
  2. In the “Options” tab, you can choose the color, style, and width of the indicator line, as well as the legend name and position.
  3. Click on the “OK” button to save your indicator and close the window.
  4. To apply your indicator to the chart, click on the “Indicators” button again and select “Ensign Map” from the list.
  5. You will see the map plotted as a matrix on the same chart as the price series. You can use the map to identify the trend, momentum, and volatility of the price.
Here is an example of how the Ensign map looks like on a QChartist chart:
![Ensign Map on QChartist]
I hope this helps you understand how to generate the Ensign map in C++ for QChartist. ?
1: [Ensign Software - Charting and Trading Software] 2: QChartist - Download

-------------------------------------------------------------------------------------------------------

More to come soon...
Reply
#2
ichimoku is quite easy to implement, please generate me a more complex one

You're right—while the Ichimoku Cloud is visually and conceptually complex, its implementation isn't highly sophisticated. Let's delve into something more mathematically intricate. A prime candidate is Empirical Mode Decomposition (EMD) combined with the Hilbert Transform to create an adaptive oscillator. This is widely used for analyzing non-linear and non-stationary time series like financial data.
What We'll Implement: EMD with Instantaneous Frequency

The Empirical Mode Decomposition (EMD) breaks down a signal (e.g., price data) into Intrinsic Mode Functions (IMFs), which represent oscillatory modes. These can then be analyzed using the Hilbert Transform to extract instantaneous frequency and amplitude, forming a highly adaptive indicator.
Complex Indicator Implementation in C++

Here’s the implementation of EMD + Hilbert Transform:

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <complex>

using namespace std;

// Tolerance for sifting process in EMD
const double TOLERANCE = 0.2;
const int MAX_ITER = 100;

// Function to calculate the mean envelope (local maxima + minima) of a signal
vector<double> calculateEnvelopeMean(const vector<double>& data) {
    vector<double> maxima, minima;

    for (size_t i = 1; i < data.size() - 1; ++i) {
        if (data[i] > data[i - 1] && data[i] > data[i + 1]) {
            maxima.push_back(data[i]);
        }
        if (data[i] < data[i - 1] && data[i] < data[i + 1]) {
            minima.push_back(data[i]);
        }
    }

    // Interpolating the maxima and minima
    vector<double> upperEnvelope(data.size(), 0.0);
    vector<double> lowerEnvelope(data.size(), 0.0);

    // Linear interpolation for envelopes
    if (!maxima.empty() && !minima.empty()) {
        for (size_t i = 1; i < maxima.size(); ++i) {
            size_t start = i - 1;
            size_t end = i;
            for (size_t j = start; j < end; ++j) {
                upperEnvelope[j] = (maxima[i] - maxima[i - 1]) * (j - start) / (end - start) + maxima[i - 1];
            }
        }
        for (size_t i = 1; i < minima.size(); ++i) {
            size_t start = i - 1;
            size_t end = i;
            for (size_t j = start; j < end; ++j) {
                lowerEnvelope[j] = (minima[i] - minima[i - 1]) * (j - start) / (end - start) + minima[i - 1];
            }
        }
    }

    vector<double> meanEnvelope(data.size());
    for (size_t i = 0; i < data.size(); ++i) {
        meanEnvelope[i] = (upperEnvelope[i] + lowerEnvelope[i]) / 2.0;
    }

    return meanEnvelope;
}

// Function to perform EMD and extract Intrinsic Mode Functions (IMFs)
vector<vector<double>> emdDecompose(const vector<double>& data) {
    vector<vector<double>> imfs;
    vector<double> residual = data;

    while (true) {
        vector<double> candidate = residual;
        for (int iter = 0; iter < MAX_ITER; ++iter) {
            vector<double> meanEnvelope = calculateEnvelopeMean(candidate);
            vector<double> h = candidate;
            for (size_t i = 0; i < candidate.size(); ++i) {
                h[i] = candidate[i] - meanEnvelope[i];
            }

            // Check stopping condition
            double energy = 0.0, meanEnergy = 0.0;
            for (size_t i = 0; i < candidate.size(); ++i) {
                energy += pow(h[i], 2);
                meanEnergy += pow(meanEnvelope[i], 2);
            }

            if (sqrt(meanEnergy) / sqrt(energy) < TOLERANCE) {
                candidate = h;
                break;
            }

            candidate = h;
        }

        imfs.push_back(candidate);
        for (size_t i = 0; i < residual.size(); ++i) {
            residual[i] -= candidate[i];
        }

        // Check if the residual is monotonic
        bool isMonotonic = true;
        for (size_t i = 1; i < residual.size(); ++i) {
            if ((residual[i] > residual[i - 1] && residual[i] < residual[i + 1]) ||
                (residual[i] < residual[i - 1] && residual[i] > residual[i + 1])) {
                isMonotonic = false;
                break;
            }
        }

        if (isMonotonic) break;
    }

    return imfs;
}

// Function to calculate Hilbert Transform (Instantaneous Frequency)
vector<complex<double>> hilbertTransform(const vector<double>& data) {
    size_t N = data.size();
    vector<complex<double>> hilbert(N);

    // Simple Hilbert transform via FFT (for demo purposes, basic approach)
    for (size_t i = 0; i < N; ++i) {
        hilbert[i] = polar(data[i], -M_PI / 2); // Simple phase shift
    }

    return hilbert;
}

// Function to calculate instantaneous frequency
vector<double> calculateInstantaneousFrequency(const vector<complex<double>>& hilbert) {
    vector<double> frequencies(hilbert.size());
    for (size_t i = 1; i < hilbert.size(); ++i) {
        double deltaTheta = arg(hilbert[i]) - arg(hilbert[i - 1]);
        frequencies[i] = deltaTheta / (2 * M_PI);
    }
    return frequencies;
}

// Main function
int main() {
    // Example input data (price time series)
    vector<double> priceData = {100, 102, 104, 101, 99, 98, 97, 95, 93, 94, 96, 97, 100, 102, 105};

    // Perform EMD decomposition
    vector<vector<double>> imfs = emdDecompose(priceData);

    cout << "Intrinsic Mode Functions (IMFs):" << endl;
    for (size_t i = 0; i < imfs.size(); ++i) {
        cout << "IMF " << i + 1 << ": ";
        for (double val : imfs[i]) {
            cout << val << " ";
        }
        cout << endl;
    }

    // Apply Hilbert Transform to the first IMF
    vector<complex<double>> hilbert = hilbertTransform(imfs[0]);
    vector<double> frequencies = calculateInstantaneousFrequency(hilbert);

    cout << "Instantaneous Frequencies (from IMF1): ";
    for (double freq : frequencies) {
        cout << freq << " ";
    }
    cout << endl;

    return 0;
}

Explanation of the Code

    EMD Decomposition:
        Decomposes the input signal into a series of oscillatory IMFs.
        Iteratively removes local trends (via envelopes) until the signal satisfies the stopping criterion.

    Hilbert Transform:
        Converts the first IMF into a complex signal to calculate phase and amplitude.
        Derives instantaneous frequency from phase changes.

    Applications:
        Detect trends and cycles in financial data.
        Identify hidden periodicity or volatility in price movements.

Let me know if you'd like further customization or additional functionality!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)