金字塔决策交易系统

 找回密码
 

微信登录

微信扫一扫,快速登录

搜索
查看: 47|回复: 1

咨询下大佬,MT5的FVG指标改动后为什么一直错误呢?

[复制链接]

48

主题

164

帖子

164

积分

等级: 免费版

注册:
2024-1-11
曾用名:
发表于 2025-11-3 22:06 | 显示全部楼层 |阅读模式
咨询下大佬,MT5的FVG指标改动金字塔指标后为什么一直错误呢?
是哪儿出了问题呢,请大佬帮忙修改下。

一、原代码
//+------------------------------------------------------------------+
//|                                         Fair Value Gap Indicator |
//|                                       Copyright 2024, Hieu Hoang |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, hieuhoangcntt@gmail.com"
#property indicator_chart_window
#property indicator_buffers 0
double _low, _high;
string object_names[];
datetime pre_time = 0;
const int bull = 5;
const int bear = 5;
int c_bull;
int c_bear;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool isGreenCandle(double open, double close)
  {
   return open < close;
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool isRedCandle(double open, double close)
  {
   return !isGreenCandle(open, close);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool isBullFVG(int index,
               const double &open[],
               const double &high[],
               const double &low[],
               const double &close[])
  {

   if(isGreenCandle(open[index-1], close[index-1]) &&
      high[index-2] < low[index] && high[index-2] < _low
     )
      return true;
   return false;
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool isBearFVG(int index,
               const double &open[],
               const double &high[],
               const double &low[],
               const double &close[])
  {

   if(isRedCandle(open[index-1], close[index-1]) &&
      low[index-2] > high[index] && low[index-2] > _high
     )
      return true;
   return false;
  }
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void create_object(string name, color clrColor,const datetime time1, const datetime time2, const double low, const double high)
  {
   ArrayResize(object_names, ArraySize(object_names) + 1);
   object_names[ArraySize(object_names) - 1] = name;
   ObjectCreate(0, name, OBJ_RECTANGLE, 0, time1, low, time2, high);
   ObjectSetInteger(0, name, OBJPROP_COLOR, clrColor);
   ObjectSetInteger(0, name, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSetInteger(0, name, OBJPROP_FILL, true);
   ObjectSetInteger(0, name, OBJPROP_RAY_RIGHT, true);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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(pre_time == time[rates_total - 1])
      return(rates_total);
   pre_time = time[rates_total - 1];
   delete_objects();
   _low = low[rates_total - 1];
   _high = high[rates_total - 1];
   c_bull = 0;
   c_bear = 0;
   for(int i = rates_total - 2; i >= 2; i--)
     {
      _low = _low < low ? _low : low;
      _high = _high > high ? _high: high;
      if(c_bull < bull && isBullFVG(i, open, high, low, close))
        {
         create_object("Buy range " + high[i-2] + " ↗ " + low, clrBlue, time[i-2], time[rates_total-1], low, high[i-2]);
         c_bull ++;
         if(c_bull >= bull && c_bear >= bear)
            break;
        }
      else if(c_bear < bear && isBearFVG(i, open, high, low, close))
           {
            create_object("Sell range " + low[i-2] + " ↘ " + high, clrRed, time[i-2], time[rates_total-1], high, low[i-2]);
            c_bear ++;
            if(c_bull >= bull && c_bear >= bear)
              break;
           }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
void delete_objects()
  {
   for(int i = 0; i < ArraySize(object_names); i++)
      ObjectDelete(0, object_names);
   ArrayResize(object_names, 0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   pre_time = 0;
   delete_objects();
  }
//+------------------------------------------------------------------+

二、帮修改代码

// Fair Value Gap Indicator for Pyramid v7.20
// Converted from MT4

VARIABLE:
    BullCount=0,
    BearCount=0,
    CurrentLow=0,
    CurrentHigh=0,
    PreTime=0,
    i=0,
    IsGreenCandle=False,
    IsRedCandle=False,
    IsBullFVG=False,
    IsBearFVG=False;

CONST:
    BullLimit=5,
    BearLimit=5;

// 主程序
Begin
    // 如果是新K线才开始计算
    If Time[0] <> PreTime Then
    Begin
        PreTime := Time[0];

        // 删除所有图形对象 - 金字塔v7.20使用DELETEDRAW(0)
        DELETEDRAW(0);

        CurrentLow := Low[0];
        CurrentHigh := High[0];
        BullCount := 0;
        BearCount := 0;

        // 从倒数第二根K线开始向前遍历
        For i = BarCount - 2 DownTo 2 Do
        Begin
            // 更新当前最低价和最高价
            If Low < CurrentLow Then CurrentLow := Low;
            If High > CurrentHigh Then CurrentHigh := High;

            // 判断是否为阳线
            IsGreenCandle := Open[i-1] < Close[i-1];
            // 判断是否为阴线
            IsRedCandle := Open[i-1] > Close[i-1];

            // 判断是否为看涨FVG
            IsBullFVG := IsGreenCandle AND (High[i-2] < Low) AND (High[i-2] < CurrentLow);

            // 判断是否为看跌FVG
            IsBearFVG := IsRedCandle AND (Low[i-2] > High) AND (Low[i-2] > CurrentHigh);

            // 检查看涨FVG
            If BullCount < BullLimit And IsBullFVG Then
            Begin
                // 在金字塔中绘制矩形
                DRAWRECTANGLE('BuyFVG_' + NumToStr(i, 0), 0, Time[i-2], Low, Time[BarCount-1], High[i-2], ColorBlue);

                // 设置矩形属性
                SETDRAWSTYLE('BuyFVG_' + NumToStr(i, 0), 0);  // 实线
                SETDRAWFILL('BuyFVG_' + NumToStr(i, 0), 1); // 填充

                BullCount := BullCount + 1;

                If BullCount >= BullLimit And BearCount >= BearLimit Then
                    Break;
            End
            // 检查看跌FVG  
            Else If BearCount < BearLimit And IsBearFVG Then
            Begin
                // 在金字塔中绘制矩形
                DRAWRECTANGLE('SellFVG_' + NumToStr(i, 0), 0, Time[i-2], High, Time[BarCount-1], Low[i-2], ColorRed);

                // 设置矩形属性
                SETDRAWSTYLE('SellFVG_' + NumToStr(i, 0), 0);  // 实线
                SETDRAWFILL('SellFVG_' + NumToStr(i, 0), 1); // 填充

                BearCount := BearCount + 1;

                If BullCount >= BullLimit And BearCount >= BearLimit Then
                    Break;
            End;
        End;
    End;
End;

// 指标卸载时清理对象
OnExit:
Begin
    DELETEDRAW(0); // 删除所有图形对象
    PreTime := 0;
End;

请问大佬,怎么修改呢



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号? 微信登录

x
回复

使用道具 举报

44

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
发表于 2025-11-4 08:48 | 显示全部楼层
这个没法直接用的,需要给出中文描述工作人员进行编写
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 微信登录

本版积分规则

手机版|小黑屋|上海金之塔信息技术有限公司 ( 沪ICP备13035422号 )

GMT+8, 2025-11-8 15:23 , Processed in 0.100337 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表