Discussing the article: "William Gann methods (Part I): Creating Gann Angles indicator" - page 2

 
Vitaly Muzichenko #:

If you have taken a course and it didn't work out - and it won't work out, which is logical - you will be told that you are not correctly comparing the stars between the planets.

You're missing the point! Who has figured out how Gunn traded, will not teach anyone. That's why all the courses from information gypsies are a complete fake.

 
Bogard_11 #:

You're missing the point! Whoever figured out how Gunn traded won't teach anyone. That's why all the courses from information gypsies are nothing but bogus.

You are telling the truth, Dear :-)
 
Gunn was a brilliant trader, and astrologer, and numerologist, a mathematician who believed in magic numbers. A great soothsayer who predicted the beginning and end of the First and Second World Wars. He had a huge number of students, but as his followers claim, he did not give his strategy to anyone. Had a huge turnover of money, and by the end of his life came with a modest sum of $100000. I will look forward to the next articles about Gunn's genius personality, very interesting.
 
Eva-oren #:
Gunn was a brilliant trader, and astrologer, and numerologist, a mathematician who believed in magic numbers. A great soothsayer who predicted the beginning and end of the First and Second World Wars. He had a huge number of students, but as his followers claim, he did not give his strategy to anyone. Had a huge turnover of money, and by the end of his life came with a modest sum of $100000. I will look forward to the next articles about Gunn's genius personality, very interesting.

Forgot to mention, he had a private jet, which was a rarity in those days. Plus $100,000 back then, that's at least a multh of green now, if not 10 mulths.

P.S. - he passed on the strategy. In his writings. Who wanted, collected from different chapters of the complete TC. Gunn scattered it all so no one could get it for free.

 
Found a way to trade on google

 
Ivan Butko #:
Found a way of trading on Google

in the second picture - I don't understand the principle :-(

 

I'll give you a picture. Who understands Gunn, will immediately understand the principle of working with corners, where to look for a long entry and where to roll over.


 
Disclaimer: I don't know MQL5 programming syntax for indicators.

But I think the angle line algorithm is not right (see attached angle line indicator I wrote in another software), here is my dialogue with DeepSeek:

下面代码是通达信的代码,里面计算斜率的方法才是正确的,请阅读理解后,把上面priceShift 的计算方法改为下列代码正确的范式:

涨周期数:= IF(低点k位置 > 高点k位置, 低点k位置 - 高点k位置 + 1, 低点k位置), NODRAW;
跌周期数:= IF(高点k位置 > 低点k位置, 高点k位置 - 低点k位置 + 1, 高点k位置), NODRAW;

天线:= CONST(IF(高点k位置 = 1, H, REF(H, 高点k位置 - 1))), NODRAW;
地线:= CONST(IF(低点k位置 = 1, L, REF(L, 低点k位置 - 1))), NODRAW;

上涨天数:= IF(ISVALID(地线), BARSLAST(L = 地线), DRAWNULL), NODRAW;
下跌天数:= IF(ISVALID(天线), BARSLAST(H = 天线), DRAWNULL), NODRAW;

上涨高度:= IF(低点k位置 > 高点k位置, 天线 - 地线, HHV(H, 上涨天数) - 地线), NODRAW;
下跌高度:= IF(高点k位置 > 低点k位置, 天线 - 地线, 天线 - LLV(L, 下跌天数)), NODRAW;

上涨斜率:= IF(上涨天数 > 0, ROUND2(上涨高度 / 涨周期数, 4), 0), NODRAW;
下跌斜率:= IF(下跌天数 > 0, ROUND2(下跌高度 / 跌周期数, 4), 0), NODRAW;

However, DeepSeek gave me a modification code that didn't seem to work for me:
//+------------------------------------------------------------------+
//| Plotting the Venn sector line & nbsp; |
//+------------------------------------------------------------------+
void DrawGannFan(double extremum, datetime extremumTime)
{
    // Define the Gann angle and the corresponding name.
    double angles[] = {82.5, 75, 71.25, 63.75, 45, 26.25, 18.75, 15, 7.5};
    string angleNames[] = {"1x8", "1x4", "1x3", "1x2", "1x1", "2x1", "3x1", "4x1", "8x1"};

    // Get the number of periods from the extreme point to the current K-line
    int extremumBar = iBarShift(_Symbol, PERIOD_CURRENT, extremumTime);
    int currentBar = 0; // Current K-line is 0
    int barDiff = currentBar - extremumBar; // Cycle number difference
    
    // Calculate the price height difference
    double priceDiff;
    if(isTrendUp)
    {
        // Uptrend: calculates the height from the extreme low to the current maximum price
        double currentHigh = iHigh(_Symbol, PERIOD_CURRENT, 0);
        priceDiff = currentHigh - extremum;
    }
    else
    {
        // Downtrend: calculates the height from the extreme high to the current low price
        double currentLow = iLow(_Symbol, PERIOD_CURRENT, 0);
        priceDiff = extremum - currentLow;
    }
    
    // Calculate the base slope (slope of the 1x1 line)
    double baseSlope = (barDiff > 0) ? priceDiff / barDiff : 0;
    
    // Draw sector lines for each angle
    for(int i = 0; i < ArraySize(angles); i++)
    {
        string label = "GannFan_" + angleNames[i];  // Object labels
        double angle = angles[i];                  // Current angle
        
        // Calculate the slope multiplier based on the angle
        double slopeMultiplier = MathTan(angle * M_PI / 180.0) / MathTan(45 * M_PI / 180.0);
        
        // Calculate price offset (based on underlying slope and angle multiplier)
        double priceShift = baseSlope * barDiff * slopeMultiplier * _Point;
        double endPrice;
        
        // Calculation of closing price based on trend direction
        if(isTrendUp)
        {
            endPrice = extremum + priceShift;
        }
        else
        {
            endPrice = extremum - priceShift;
            angle = -angle; // Reversal angle in downtrend
        }

        // Create a trendline object
        if(ObjectCreate(0, label, OBJ_TREND, 0, extremumTime, extremum, TimeCurrent(), endPrice))
        {
            // Set trendline properties
            ObjectSetInteger(0, label, OBJPROP_COLOR, GannFanColor);
            ObjectSetInteger(0, label, OBJPROP_STYLE, STYLE_SOLID);
            ObjectSetInteger(0, label, OBJPROP_WIDTH, 1);
            ObjectSetInteger(0, label, OBJPROP_RAY_RIGHT, true);
            ObjectSetString(0, label, OBJPROP_TOOLTIP, "Gann Fan " + angleNames[i]);
        }
        else
        {
            Print("Failed to create Gann Fan line: ", GetLastError());
        }
    }
}

//+------------------------------------------------------------------+
//|| Plotting a Reverse Gann Fan Line & nbsp; &nbsp ; ||
//+------------------------------------------------------------------+
void DrawOppositeGannFan(double extremum, datetime extremumTime)
{
    // Define the Gann angle and the corresponding name.
    double angles[] = {82.5, 75, 71.25, 63.75, 45, 26.25, 18.75, 15, 7.5};
    string angleNames[] = {"1x8", "1x4", "1x3", "1x2", "1x1", "2x1", "3x1", "4x1", "8x1"};

    // Get the number of periods from the extreme point to the current K-line
    int extremumBar = iBarShift(_Symbol, PERIOD_CURRENT, extremumTime);
    int currentBar = 0; // Current K-line is 0
    int barDiff = currentBar - extremumBar; // Cycle number difference
    
    // Calculate the price height difference
    double priceDiff;
    if(!isTrendUp)
    {
        // Reverse trend (up): calculates the height from the extreme low to the current maximum price
        double currentHigh = iHigh(_Symbol, PERIOD_CURRENT, 0);
        priceDiff = currentHigh - extremum;
    }
    else
    {
        // Reverse trend (downward): calculates the height from the extreme high to the current low price
        double currentLow = iLow(_Symbol, PERIOD_CURRENT, 0);
        priceDiff = extremum - currentLow;
    }
    
    // Calculate the base slope (slope of the 1x1 line)
    double baseSlope = (barDiff > 0) ? priceDiff / barDiff : 0;
    
    // Draw sector lines for each angle
    for(int i = 0; i < ArraySize(angles); i++)
    {
        string label = "OppositeGannFan_" + angleNames[i];  // Object labels
        double angle = angles[i];                          // Current angle
        
        // Calculate the slope multiplier based on the angle
        double slopeMultiplier = MathTan(angle * M_PI / 180.0) / MathTan(45 * M_PI / 180.0);
        
        // Calculate price offset (based on underlying slope and angle multiplier)
        double priceShift = baseSlope * barDiff * slopeMultiplier * _Point;
        double endPrice;
        
        // Calculation of the closing price based on the direction of the reverse trend
        if(!isTrendUp)
        {
            endPrice = extremum + priceShift;
        }
        else
        {
            endPrice = extremum - priceShift;
            angle = -angle; // Reversal angle in downtrend
        }

        // Create a trendline object
        if(ObjectCreate(0, label, OBJ_TREND, 0, extremumTime, extremum, TimeCurrent(), endPrice))
        {
            // Set trendline properties
            ObjectSetInteger(0, label, OBJPROP_COLOR, GannFanColor);
            ObjectSetInteger(0, label, OBJPROP_STYLE, STYLE_SOLID);
            ObjectSetInteger(0, label, OBJPROP_WIDTH, 1);
            ObjectSetInteger(0, label, OBJPROP_RAY_RIGHT, true);
            ObjectSetString(0, label, OBJPROP_TOOLTIP, "Opposite Gann Fan " + angleNames[i]);
        }
        else
        {
            Print("Failed to create Opposite Gann Fan line: ", GetLastError());
        }
    }
}





In the end, I had to ask DeepSeek to tweak your source code (it works fine and draws lines automatically):
#property copyright "Copyright 2024, Evgeniy Shtenco"  // Copyright information
#property link      "https://www.mql5.com/en/users/koshtenko"  // Author Links
#property version   "1.00"  // Indicator version number
#property indicator_chart_window  // Indicators are displayed in the chart window

// Input parameters
input int LookBackBars = 300;      // Number of K-lines analysed back
input color GannFanColor = clrBlue; // Vaughan's fan line colours

// Global variables
double extremumPrice;        // Extreme point price
datetime extremumTime;       // Extreme point time
double oppositeExtremumPrice; // Reverse Extreme Point Price
datetime oppositeExtremumTime; // Reverse polarity point time
bool isTrendUp;              // Trend direction flag (true for uptrend)

//+------------------------------------------------------------------+
//| Custom Indicator Initialisation Functions & nbsp; &nbsp ; ||
//+------------------------------------------------------------------+
int OnInit()
{
    return (INIT_SUCCEEDED);  // Successful initialisation
}

//+------------------------------------------------------------------+
//| Custom Indicator Reinitialisation Functions & nbsp; &nbsp ; ||
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
    {
        // Delete all Gann sector objects
        ObjectsDeleteAll(0, "GannFan_");
ObjectsDeleteAll(0, "OppositeGannFan_");
}

//+------------------------------------------------------------------+
//| Custom Indicator Calculation Functions & nbsp; &nbsp ; | | | | | | | |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,          // Current number of cycles
const int prev_calculated,      // Number of previously calculated cycles
const datetime & time[],         // Time arrays
                const double & open[],          // Array of opening prices
                const double & high[],           // Array of highest prices
                const double & low[],            // Array of lowest prices
                const double & close[],         // Closing Price Array
                const long & tick_volume[],      // Volume array
                const long & volume[],           // Real Volume Array
                const int & spread[])            // Array of point spreads
{
    if (rates_total < LookBackBars) return (0);  // Return if there is not enough data

    // Clear the previously drawn objects
    if (prev_calculated == 0) {
        ObjectsDeleteAll(0, "GannFan_");
        ObjectsDeleteAll(0, "OppositeGannFan_");
    }

    // Finding the extreme points in the last 300 K-lines
    FindExtremums(rates_total, high, low, time);

    // Drawing the Venn Fan Line
    DrawGannFan(extremumPrice, extremumTime);
    DrawOppositeGannFan(oppositeExtremumPrice, oppositeExtremumTime);

    return (rates_total);  // Returns the total number of columns processed
}

//+------------------------------------------------------------------+
//| Find extreme points within a specified number of K-lines. |
//+------------------------------------------------------------------+
void FindExtremums(const int rates_total, const double & high[], const double & low[], const datetime & time[])
{
    int startIndex = rates_total - LookBackBars;  // Start indexing (300 K-lines ago)
    int endIndex = rates_total - 1;               // End index (latest K-line)

    // Finding highs and lows
    int highestIndex = ArrayMaximum(high, startIndex, LookBackBars);
    int lowestIndex = ArrayMinimum(low, startIndex, LookBackBars);

    // Determine the direction of the trend (compare the timing of highs and lows)
    if (time[highestIndex] > time[lowestIndex]) {
        // Downtrend if the highest point is after the lowest point
        extremumPrice = high[highestIndex];
        extremumTime = time[highestIndex];
        oppositeExtremumPrice = low[lowestIndex];
        oppositeExtremumTime = time[lowestIndex];
        isTrendUp = false;
    }
    else {
        // otherwise uptrend
        extremumPrice = low[lowestIndex];
        extremumTime = time[lowestIndex];
        oppositeExtremumPrice = high[highestIndex];
        oppositeExtremumTime = time[highestIndex];
        isTrendUp = true;
    }
}

//+------------------------------------------------------------------+
//| Plotting the Venn sector line & nbsp; |
//+------------------------------------------------------------------+
void DrawGannFan(double extremum, datetime extremumTime)
{
    // Define the Gann angle and the corresponding name.
    double angles[] = { 82.5, 75, 71.25, 63.75, 45, 26.25, 18.75, 15, 7.5};
    string angleNames[] = { "1x8", "1x4", "1x3", "1x2", "1x1", "2x1", "3x1", "4x1", "8x1"};

    // Calculate the end time of the sector line (current time + 300 cycles)
    datetime endTime = TimeCurrent();  // Use the current time as the end time

    // Draw sector lines for each angle
    for (int i = 0; i < ArraySize(angles); i++)
    {
        string label = "GannFan_" + angleNames[i];  // Object labels
        double angle = angles[i];                  // Current angle

        // Calculate price offset (based on time difference)
        double secondsDiff = endTime - extremumTime;
        double priceShift = MathTan(angle * M_PI / 180.0) * secondsDiff / PeriodSeconds();
        double endPrice;

        // Calculation of closing price based on trend direction
        if (isTrendUp) {
            endPrice = extremum + priceShift;
        }
        else {
            endPrice = extremum - priceShift;
            angle = -angle; // Reversal angle in downtrend
        }

        // Create a trendline object
        if (ObjectCreate(0, label, OBJ_TREND, 0, extremumTime, extremum, endTime, endPrice)) {
            // Set trendline properties
            ObjectSetInteger(0, label, OBJPROP_COLOR, GannFanColor);
            ObjectSetInteger(0, label, OBJPROP_STYLE, STYLE_SOLID);
            ObjectSetInteger(0, label, OBJPROP_WIDTH, 1);
            ObjectSetInteger(0, label, OBJPROP_RAY_RIGHT, true);
            ObjectSetString(0, label, OBJPROP_TOOLTIP, "Gann Fan " + angleNames[i]);
        }
        else {
            Print("Failed to create Gann Fan line: ", GetLastError());
        }
    }
}

//+------------------------------------------------------------------+
//|| Plotting a Reverse Gann Fan Line & nbsp; &nbsp ; ||
//+------------------------------------------------------------------+
void DrawOppositeGannFan(double extremum, datetime extremumTime)
{
    // Define the Gann angle and the corresponding name.
    double angles[] = { 82.5, 75, 71.25, 63.75, 45, 26.25, 18.75, 15, 7.5};
    string angleNames[] = { "1x8", "1x4", "1x3", "1x2", "1x1", "2x1", "3x1", "4x1", "8x1"};

    // Calculate the end time of the sector line (current time)
    datetime endTime = TimeCurrent();

    // Draw sector lines for each angle
    for (int i = 0; i < ArraySize(angles); i++)
    {
        string label = "OppositeGannFan_" + angleNames[i];  // Object labels
        double angle = angles[i];                          // Current angle

        // Calculate price offset (based on time difference)
        double secondsDiff = endTime - extremumTime;
        double priceShift = MathTan(angle * M_PI / 180.0) * secondsDiff / PeriodSeconds();
        double endPrice;

        // Calculation of the ending price based on the direction of the opposite trend
        if (!isTrendUp) // Reverse trend
        {
            endPrice = extremum + priceShift;
        }
        else {
            endPrice = extremum - priceShift;
            angle = -angle; // Reversal angle in downtrend
        }

        // Create a trendline object
        if (ObjectCreate(0, label, OBJ_TREND, 0, extremumTime, extremum, endTime, endPrice)) {
            // Set trendline properties
            ObjectSetInteger(0, label, OBJPROP_COLOR, GannFanColor);
            ObjectSetInteger(0, label, OBJPROP_STYLE, STYLE_SOLID);
            ObjectSetInteger(0, label, OBJPROP_WIDTH, 1);
            ObjectSetInteger(0, label, OBJPROP_RAY_RIGHT, true);
            ObjectSetString(0, label, OBJPROP_TOOLTIP, "Opposite Gann Fan " + angleNames[i]);
        }
        else {
            Print("Failed to create Opposite Gann Fan line: ", GetLastError());
        }
    }
}

//+------------------------------------------------------------------+
//| Chart Event Handler Functions &nbsp nbsp; & & nbsp; |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,                  // Event ID
const long & lparam,            // Long integer parameters
                  const double & dparam,          // Double precision parameters
                  const string & sparam)         // String parameters
{
    // Redraw objects when the chart changes
    if (id == CHARTEVENT_CHART_CHANGE || id == CHARTEVENT_CLICK) {
        // Re-find the extremes and plot the Venn fan line.
        int rates_total = Bars(_Symbol, PERIOD_CURRENT);
        double high[], low[];
        datetime time[];
        ArraySetAsSeries(high, true);
        ArraySetAsSeries(low, true);
        ArraySetAsSeries(time, true);
        CopyHigh(_Symbol, PERIOD_CURRENT, 0, rates_total, high);
        CopyLow(_Symbol, PERIOD_CURRENT, 0, rates_total, low);
        CopyTime(_Symbol, PERIOD_CURRENT, 0, rates_total, time);

        FindExtremums(rates_total, high, low, time);
        DrawGannFan(extremumPrice, extremumTime);
        DrawOppositeGannFan(oppositeExtremumPrice, oppositeExtremumTime);
    }
}
Files: