文章 "威廉·甘恩(William Gann)方法(第一部分):创建甘恩角度指标" - 页 2

 
Vitaly Muzichenko #:

如果你选修了一门课程,但没有成功--而且不会成功,这是合乎逻辑的--你会被告知,你没有正确地比较行星之间的星体。

你没抓住重点!谁搞清楚了冈恩是如何交易的,谁也教不了谁。这就是为什么所有信息吉普赛人的课程都是假的。

 
Bogard_11 #:

你没明白我的意思!不管是谁发现了冈恩交易的方法,他都不会教任何人。这就是为什么所有信息吉普赛人的课程都是假的。

你说的是实话,亲爱的 :-)
 
甘恩是一位杰出的商人、占星家和命理学家,一位相信神奇数字的数学家。他是一位伟大的占卜师,预测了第一次和第二次世界大战的开始和结束。他的学生人数众多,但正如他的追随者所说,他并没有把自己的策略告诉任何人。他有大量的资金周转,在他生命的最后时刻,他只得到了区区 10 万美元。我会期待下一篇关于冈恩天才个性的文章,非常有趣。
 
Eva-oren #:
甘恩是一位杰出的商人、占星家和命理学家,一位相信神奇数字的数学家。他是一位伟大的占卜师,预测了第一次和第二次世界大战的开始和结束。他的学生人数众多,但正如他的追随者所说,他并没有把自己的策略告诉任何人。他有大量的资金周转,在他生命的最后时刻,他只得到了区区10 万美元。我会期待下一篇关于冈恩天才个性的文章,非常有趣。

忘了说了,他有一架私人飞机,这在当时是非常罕见的。加上当年的10 万美元,即使不是10 倍,也至少是现在的 1 倍了。

附带一提--他传授了战略。在他的著作中。谁想要,从完整的 TC 的不同章节中收集。冈恩将其全部散失,因此没有人能免费得到它。

 
找到在谷歌上交易的方法

 
Ivan Butko #:
在 Google 上找到一种交易方式

在第二张图片中 - 我不明白其中的原理 :-(

 

我给你一张图片。了解古恩的人,马上就会明白拐角处的工作原理,知道在哪里寻找长切入点,在哪里翻滚。


 
声明:我不会MQL5的指标编程语法。

但我觉得角度线的算法不对(请看附件我在别的软件里的写的角度线指标),下面是我和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;

但是,DeepSeek给出的修改代码貌似我并不能使用:
//+------------------------------------------------------------------+
//| 绘制江恩扇形线                                                   |
//+------------------------------------------------------------------+
void DrawGannFan(double extremum, datetime extremumTime)
{
    // 定义江恩角度和对应的名称
    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"};

    // 获取极值点到当前K线的周期数
    int extremumBar = iBarShift(_Symbol, PERIOD_CURRENT, extremumTime);
    int currentBar = 0; // 当前K线是第0根
    int barDiff = currentBar - extremumBar; // 周期数差
    
    // 计算价格高度差
    double priceDiff;
    if(isTrendUp)
    {
        // 上升趋势:计算从极值低点到当前最高价的高度
        double currentHigh = iHigh(_Symbol, PERIOD_CURRENT, 0);
        priceDiff = currentHigh - extremum;
    }
    else
    {
        // 下降趋势:计算从极值高点到当前最低价的高度
        double currentLow = iLow(_Symbol, PERIOD_CURRENT, 0);
        priceDiff = extremum - currentLow;
    }
    
    // 计算基础斜率(1x1线的斜率)
    double baseSlope = (barDiff > 0) ? priceDiff / barDiff : 0;
    
    // 为每个角度绘制扇形线
    for(int i = 0; i < ArraySize(angles); i++)
    {
        string label = "GannFan_" + angleNames[i];  // 对象标签
        double angle = angles[i];                  // 当前角度
        
        // 根据角度计算斜率倍数
        double slopeMultiplier = MathTan(angle * M_PI / 180.0) / MathTan(45 * M_PI / 180.0);
        
        // 计算价格偏移量(基于基础斜率和角度倍数)
        double priceShift = baseSlope * barDiff * slopeMultiplier * _Point;
        double endPrice;
        
        // 根据趋势方向计算结束价格
        if(isTrendUp)
        {
            endPrice = extremum + priceShift;
        }
        else
        {
            endPrice = extremum - priceShift;
            angle = -angle; // 下降趋势时反转角度
        }

        // 创建趋势线对象
        if(ObjectCreate(0, label, OBJ_TREND, 0, extremumTime, extremum, TimeCurrent(), endPrice))
        {
            // 设置趋势线属性
            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());
        }
    }
}

//+------------------------------------------------------------------+
//| 绘制反向江恩扇形线                                               |
//+------------------------------------------------------------------+
void DrawOppositeGannFan(double extremum, datetime extremumTime)
{
    // 定义江恩角度和对应的名称
    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"};

    // 获取极值点到当前K线的周期数
    int extremumBar = iBarShift(_Symbol, PERIOD_CURRENT, extremumTime);
    int currentBar = 0; // 当前K线是第0根
    int barDiff = currentBar - extremumBar; // 周期数差
    
    // 计算价格高度差
    double priceDiff;
    if(!isTrendUp)
    {
        // 反向趋势(上升):计算从极值低点到当前最高价的高度
        double currentHigh = iHigh(_Symbol, PERIOD_CURRENT, 0);
        priceDiff = currentHigh - extremum;
    }
    else
    {
        // 反向趋势(下降):计算从极值高点到当前最低价的高度
        double currentLow = iLow(_Symbol, PERIOD_CURRENT, 0);
        priceDiff = extremum - currentLow;
    }
    
    // 计算基础斜率(1x1线的斜率)
    double baseSlope = (barDiff > 0) ? priceDiff / barDiff : 0;
    
    // 为每个角度绘制扇形线
    for(int i = 0; i < ArraySize(angles); i++)
    {
        string label = "OppositeGannFan_" + angleNames[i];  // 对象标签
        double angle = angles[i];                          // 当前角度
        
        // 根据角度计算斜率倍数
        double slopeMultiplier = MathTan(angle * M_PI / 180.0) / MathTan(45 * M_PI / 180.0);
        
        // 计算价格偏移量(基于基础斜率和角度倍数)
        double priceShift = baseSlope * barDiff * slopeMultiplier * _Point;
        double endPrice;
        
        // 根据反向趋势方向计算结束价格
        if(!isTrendUp)
        {
            endPrice = extremum + priceShift;
        }
        else
        {
            endPrice = extremum - priceShift;
            angle = -angle; // 下降趋势时反转角度
        }

        // 创建趋势线对象
        if(ObjectCreate(0, label, OBJ_TREND, 0, extremumTime, extremum, TimeCurrent(), endPrice))
        {
            // 设置趋势线属性
            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());
        }
    }
}





最后只能让DeepSeek在你的源代码里做了调整(可以正常使用,自动画线):
#property copyright "Copyright 2024, Evgeniy Shtenco"  // 版权信息
#property link      "https://www.mql5.com/en/users/koshtenko"  // 作者链接
#property version   "1.00"  // 指标版本号
#property indicator_chart_window  // 指标显示在图表窗口

// 输入参数
input int LookBackBars = 300;      // 分析回溯的K线数量
input color GannFanColor = clrBlue; // 江恩扇形线颜色

// 全局变量
double extremumPrice;        // 极值点价格
datetime extremumTime;       // 极值点时间
double oppositeExtremumPrice; // 反向极值点价格
datetime oppositeExtremumTime; // 反向极值点时间
bool isTrendUp;              // 趋势方向标志(true为上升趋势)

//+------------------------------------------------------------------+
//| 自定义指标初始化函数                                             |
//+------------------------------------------------------------------+
int OnInit()
{
    return (INIT_SUCCEEDED);  // 初始化成功
}

//+------------------------------------------------------------------+
//| 自定义指标反初始化函数                                           |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
    {
        // 删除所有江恩扇形线对象
        ObjectsDeleteAll(0, "GannFan_");
ObjectsDeleteAll(0, "OppositeGannFan_");
}

//+------------------------------------------------------------------+
//| 自定义指标计算函数                                               |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,          // 当前周期数
const int prev_calculated,      // 之前计算的周期数
const datetime & time[],         // 时间数组
                const double & open[],          // 开盘价数组
                const double & high[],           // 最高价数组
                const double & low[],            // 最低价数组
                const double & close[],         // 收盘价数组
                const long & tick_volume[],      // 成交量数组
                const long & volume[],           // 真实成交量数组
                const int & spread[])            // 点差数组
{
    if (rates_total < LookBackBars) return (0);  // 如果没有足够数据则返回

    // 清除之前绘制的对象
    if (prev_calculated == 0) {
        ObjectsDeleteAll(0, "GannFan_");
        ObjectsDeleteAll(0, "OppositeGannFan_");
    }

    // 在最近300根K线中寻找极值点
    FindExtremums(rates_total, high, low, time);

    // 绘制江恩扇形线
    DrawGannFan(extremumPrice, extremumTime);
    DrawOppositeGannFan(oppositeExtremumPrice, oppositeExtremumTime);

    return (rates_total);  // 返回处理的总柱数
}

//+------------------------------------------------------------------+
//| 在指定K线数量内寻找极值点                                       |
//+------------------------------------------------------------------+
void FindExtremums(const int rates_total, const double & high[], const double & low[], const datetime & time[])
{
    int startIndex = rates_total - LookBackBars;  // 开始索引(300根K线前)
    int endIndex = rates_total - 1;               // 结束索引(最新K线)

    // 寻找最高点和最低点
    int highestIndex = ArrayMaximum(high, startIndex, LookBackBars);
    int lowestIndex = ArrayMinimum(low, startIndex, LookBackBars);

    // 确定趋势方向(比较最高点和最低点的时间)
    if (time[highestIndex] > time[lowestIndex]) {
        // 如果最高点在最低点之后,则为下降趋势
        extremumPrice = high[highestIndex];
        extremumTime = time[highestIndex];
        oppositeExtremumPrice = low[lowestIndex];
        oppositeExtremumTime = time[lowestIndex];
        isTrendUp = false;
    }
    else {
        // 否则为上升趋势
        extremumPrice = low[lowestIndex];
        extremumTime = time[lowestIndex];
        oppositeExtremumPrice = high[highestIndex];
        oppositeExtremumTime = time[highestIndex];
        isTrendUp = true;
    }
}

//+------------------------------------------------------------------+
//| 绘制江恩扇形线                                                   |
//+------------------------------------------------------------------+
void DrawGannFan(double extremum, datetime extremumTime)
{
    // 定义江恩角度和对应的名称
    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"};

    // 计算扇形线的结束时间(当前时间+300个周期)
    datetime endTime = TimeCurrent();  // 使用当前时间作为结束时间

    // 为每个角度绘制扇形线
    for (int i = 0; i < ArraySize(angles); i++)
    {
        string label = "GannFan_" + angleNames[i];  // 对象标签
        double angle = angles[i];                  // 当前角度

        // 计算价格偏移量(基于时间差)
        double secondsDiff = endTime - extremumTime;
        double priceShift = MathTan(angle * M_PI / 180.0) * secondsDiff / PeriodSeconds();
        double endPrice;

        // 根据趋势方向计算结束价格
        if (isTrendUp) {
            endPrice = extremum + priceShift;
        }
        else {
            endPrice = extremum - priceShift;
            angle = -angle; // 下降趋势时反转角度
        }

        // 创建趋势线对象
        if (ObjectCreate(0, label, OBJ_TREND, 0, extremumTime, extremum, endTime, endPrice)) {
            // 设置趋势线属性
            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());
        }
    }
}

//+------------------------------------------------------------------+
//| 绘制反向江恩扇形线                                               |
//+------------------------------------------------------------------+
void DrawOppositeGannFan(double extremum, datetime extremumTime)
{
    // 定义江恩角度和对应的名称
    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"};

    // 计算扇形线的结束时间(当前时间)
    datetime endTime = TimeCurrent();

    // 为每个角度绘制扇形线
    for (int i = 0; i < ArraySize(angles); i++)
    {
        string label = "OppositeGannFan_" + angleNames[i];  // 对象标签
        double angle = angles[i];                          // 当前角度

        // 计算价格偏移量(基于时间差)
        double secondsDiff = endTime - extremumTime;
        double priceShift = MathTan(angle * M_PI / 180.0) * secondsDiff / PeriodSeconds();
        double endPrice;

        // 根据相反趋势方向计算结束价格
        if (!isTrendUp) // 反向趋势
        {
            endPrice = extremum + priceShift;
        }
        else {
            endPrice = extremum - priceShift;
            angle = -angle; // 下降趋势时反转角度
        }

        // 创建趋势线对象
        if (ObjectCreate(0, label, OBJ_TREND, 0, extremumTime, extremum, endTime, endPrice)) {
            // 设置趋势线属性
            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());
        }
    }
}

//+------------------------------------------------------------------+
//| 图表事件处理函数                                                 |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,                  // 事件ID
const long & lparam,            // 长整型参数
                  const double & dparam,          // 双精度参数
                  const string & sparam)         // 字符串参数
{
    // 当图表变化时重绘对象
    if (id == CHARTEVENT_CHART_CHANGE || id == CHARTEVENT_CLICK) {
        // 重新寻找极值点并绘制江恩扇形线
        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);
    }
}
附加的文件: