📅 财经日历 📊 实时波动 📈 大盘云图 📶 行情走势 🆚 投机情绪 🚀 今日热点

    请各位大神帮忙修改一下代码,感激不尽!

    2026-06-09 · 167 阅读
    下面是源代码,编辑检查没错误,也能加载,但就是不显示颜色区域和箭头。


    //+------------------------------------------------------------------+
    //| 机构猎杀识别与强平线区域.mq4 |
    //| 终极定稿版:扫止损/爆仓反转策略 |
    //| 优化:信号及时性 + RSI阈值外部可调 |
    //+------------------------------------------------------------------+
    #property copyright "Copyright 2026"
    #property link      ""
    #property version   "1.04"
    #property strict

    #property indicator_chart_window
    #property indicator_buffers 4
    #property indicator_plots   4

    //--- 填充区域
    #property indicator_label1  "LiquidationZoneHigh"
    #property indicator_type1   DRAW_FILLING
    #property indicator_color1  clrRed, clrFireBrick

    #property indicator_label2  "LiquidationZoneLow"
    #property indicator_type2   DRAW_FILLING
    #property indicator_color2  clrForestGreen, clrDarkGreen

    //--- 信号箭头 做多绿色 / 做空红色
    #property indicator_label3  "BuySignal"
    #property indicator_type3   DRAW_ARROW
    #property indicator_color3  clrLime
    #property indicator_width3  2

    #property indicator_label4  "SellSignal"
    #property indicator_type4   DRAW_ARROW
    #property indicator_color4  clrRed
    #property indicator_width4  2

    //--- 输入参数
    input int      InpATRPeriod      = 14;        // ATR周期
    input double   InpZoneATRMult    = 1.2;       // 强平区宽度倍数
    input int      InpLookback       = 38;        // 高低点回溯周期(黄金H1推荐35~40)
    input int      InpBollPeriod     = 20;        // 布林带周期
    input double   InpBollDev        = 2.0;       // 布林带偏差
    input int      InpRSIPeriod      = 14;        // RSI周期
    input int      MaxDrawLines      = 80;        // 最大绘制止损线数量
    input int      InpMAPeriod       = 50;        // 趋势均线周期
    input int      RSI_Buy_Level     = 40;        // 做多RSI阈值
    input int      RSI_Sell_Level    = 60;        // 做空RSI阈值

    //--- 指标缓冲区
    double ZoneUpperBuffer[];
    double ZoneLowerBuffer[];
    double BuyArrowBuffer[];
    double SellArrowBuffer[];

    //--- 动态线条数组
    string stopLossLines[];
    int    lineCount = 0;

    //+------------------------------------------------------------------+
    //| 初始化函数                                                        |
    //+------------------------------------------------------------------+
    int OnInit()
    {
       SetIndexBuffer(0,ZoneUpperBuffer,INDICATOR_DATA);
       SetIndexBuffer(1,ZoneLowerBuffer,INDICATOR_DATA);
       SetIndexBuffer(2,BuyArrowBuffer,INDICATOR_DATA);
       SetIndexBuffer(3,SellArrowBuffer,INDICATOR_DATA);

       PlotIndexSetInteger(2,PLOT_ARROW,241);
       PlotIndexSetInteger(3,PLOT_ARROW,242);
       PlotIndexSetInteger(2,PLOT_ARROW_SHIFT,15);
       PlotIndexSetInteger(3,PLOT_ARROW_SHIFT,-15);

       ArrayInitialize(ZoneUpperBuffer,EMPTY_VALUE);
       ArrayInitialize(ZoneLowerBuffer,EMPTY_VALUE);
       ArrayInitialize(BuyArrowBuffer,EMPTY_VALUE);
       ArrayInitialize(SellArrowBuffer,EMPTY_VALUE);

       ArrayResize(stopLossLines,MaxDrawLines);
       lineCount = 0;

       return(INIT_SUCCEEDED);
    }

    //+------------------------------------------------------------------+
    //| 反初始化函数                                                      |
    //+------------------------------------------------------------------+
    void OnDeinit(const int reason)
    {
       for(int i=0; i<lineCount; i++)
       {
          if(ObjectFind(0,stopLossLines[i]) != -1)
             ObjectDelete(0,stopLossLines[i]);
       }
       lineCount = 0;
       ArrayFree(stopLossLines);
    }

    //+------------------------------------------------------------------+
    //| 主计算函数                                                        |
    //+------------------------------------------------------------------+
    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[])
    {
       // 优化:修正起始位,提升信号及时性
       int start = prev_calculated - 1;
       if(start < 0) start = 0;

       if(rates_total < InpLookback + 20)
          return(rates_total);

       double atr[];
       double keyHigh[],keyLow[];
       double bollUpper[],bollLower[];
       double maLine[];

       ArrayResize(atr,rates_total);
       ArrayResize(keyHigh,rates_total);
       ArrayResize(keyLow,rates_total);
       ArrayResize(bollUpper,rates_total);
       ArrayResize(bollLower,rates_total);
       ArrayResize(maLine,rates_total);

       // 计算ATR
       for(int i=start; i<rates_total; i++)
          atr[i] = iATR(_Symbol,_Period,InpATRPeriod,i);

       // 计算区间高低点(强平区锚点)
       for(int i=start; i<rates_total; i++)
       {
          int barStart = i - InpLookback;
          if(barStart < 0) barStart = 0;

          double hh = high[i];
          double ll = low[i];
          for(int j=barStart; j<=i; j++)
          {
             if(high[j] > hh) hh = high[j];
             if(low[j]  < ll) ll = low[j];
          }
          keyHigh[i] = hh;
          keyLow[i]  = ll;
       }

       // 计算布林带
       for(int i=start; i<rates_total; i++)
       {
          bollLower[i] = iBands(_Symbol,_Period,InpBollPeriod,InpBollDev,0,PRICE_CLOSE,MODE_LOWER,i);
          bollUpper[i] = iBands(_Symbol,_Period,InpBollPeriod,InpBollDev,0,PRICE_CLOSE,MODE_UPPER,i);
       }

       // 计算趋势均线
       for(int i=start; i<rates_total; i++)
          maLine[i] = iMA(_Symbol,_Period,InpMAPeriod,0,MODE_SMA,PRICE_CLOSE,i);

       // 绘制强平猎杀区间带
       for(int i=start; i<rates_total; i++)
       {
          double zoneW = atr[i] * InpZoneATRMult;
          ZoneUpperBuffer[i] = keyHigh[i] + zoneW;
          ZoneLowerBuffer[i] = keyLow[i]  - zoneW;
       }

       // 全量刷新时清空旧止损线
       if(start == 0)
       {
          for(int i=0; i<lineCount; i++)
          {
             if(ObjectFind(0,stopLossLines[i])!=-1)
                ObjectDelete(0,stopLossLines[i]);
          }
          lineCount = 0;
       }

       // 优化:i=start+2 减少信号滞后,双K线确认足够使用
       for(int i=start+2; i<rates_total; i++)
       {
          BuyArrowBuffer[i]  = EMPTY_VALUE;
          SellArrowBuffer[i] = EMPTY_VALUE;

          if(atr[i] <= Point) continue;

          // 1. 判定整体大趋势
          bool TrendUp   = (close[i] > maLine[i]);  // 整体多头趋势
          bool TrendDown = (close[i] < maLine[i]);  // 整体空头趋势

          // 2. 当前K线 影线+真假突破判断
          double upShadow   = high[i] - MathMax(open[i],close[i]);
          double downShadow = MathMin(open[i],close[i]) - low[i];
          bool currFakeDown = (low[i] < ZoneLowerBuffer[i]) && (close[i] > ZoneLowerBuffer[i]) && (downShadow > atr[i] * 0.5);
          bool currFakeUp   = (high[i] > ZoneUpperBuffer[i]) && (close[i] < ZoneUpperBuffer[i]) && (upShadow > atr[i] * 0.5);

          // 3. 前一根K线(双K线连续确认,防骗线)
          int pre = i - 1;
          double preUpShadow   = high[pre] - MathMax(open[pre],close[pre]);
          double preDownShadow = MathMin(open[pre],close[pre]) - low[pre];
          bool preFakeDown = (low[pre] < ZoneLowerBuffer[pre]) && (close[pre] > ZoneLowerBuffer[pre]) && (preDownShadow > atr[pre] * 0.5);
          bool preFakeUp   = (high[pre] > ZoneUpperBuffer[pre]) && (close[pre] < ZoneUpperBuffer[pre]) && (preUpShadow > atr[pre] * 0.5);

          // 4. 布林带位置过滤
          bool nearBollLow = (close[i] <= bollLower[i] + atr[i] * 0.2);
          bool nearBollUp  = (close[i] >= bollUpper[i] - atr[i] * 0.2);

          // 5. RSI取值
          double rsiVal = iRSI(_Symbol,_Period,InpRSIPeriod,PRICE_CLOSE,i);

          //==================== 做多信号 ====================
          // 逻辑:整体空头趋势 → 价格下探猎杀区、假跌破(扫散户多单止损) → 反手做多
          if(TrendDown && currFakeDown && preFakeDown && nearBollLow && rsiVal < RSI_Buy_Level && lineCount < MaxDrawLines)
          {
             BuyArrowBuffer[i] = low[i] - atr[i] * 0.3;
             string objName = StringFormat("SL_BUY_%d_%I64d",i,time[i]);
             double slPrice = low[i] - atr[i];

             if(ObjectCreate(0,objName,OBJ_HLINE,0,time[i],slPrice))
             {
                ObjectSetInteger(0,objName,OBJPROP_STYLE,STYLE_DOT);
                ObjectSetInteger(0,objName,OBJPROP_COLOR,clrRed);
                ObjectSetInteger(0,objName,OBJPROP_WIDTH,1);
                stopLossLines[lineCount++] = objName;
             }
          }

          //==================== 做空信号 ====================
          // 逻辑:整体多头趋势 → 价格上探猎杀区、假突破(扫散户空单止损) → 反手做空
          if(TrendUp && currFakeUp && preFakeUp && nearBollUp && rsiVal > RSI_Sell_Level && lineCount < MaxDrawLines)
          {
             SellArrowBuffer[i] = high[i] + atr[i] * 0.3;
             string objName = StringFormat("SL_SELL_%d_%I64d",i,time[i]);
             double slPrice = high[i] + atr[i];

             if(ObjectCreate(0,objName,OBJ_HLINE,0,time[i],slPrice))
             {
                ObjectSetInteger(0,objName,OBJPROP_STYLE,STYLE_DOT);
                ObjectSetInteger(0,objName,OBJPROP_COLOR,clrLime);
                ObjectSetInteger(0,objName,OBJPROP_WIDTH,1);
                stopLossLines[lineCount++] = objName;
             }
          }
       }

       return(rates_total);
    }
    //+------------------------------------------------------------------+

    ""
    还没有人打赏,支持一下
    回复

    举报

     

    回答|共 4 个

    Muriel LV3

    发表于 2026-6-9 15:31:17 | 显示全部楼层

    代码有些乱,有些语法都是MT5的

    伤心的笔 LV4

    发表于 2026-6-9 15:35:15 | 显示全部楼层

    这样的?
    GBPUSDM15.png
    猎杀_修复版.mq4

    641386452 LV6

    发表于 2026-6-9 15:47:36 | 显示全部楼层

    楼上的,非常感谢,好人啊,一定发财,你全家发财,你亲戚朋友都发财啊

    捉鱼的羊 LV5

    发表于 2026-6-9 22:59:47 | 显示全部楼层


    这个严重滞后,不能实时..
    您需要登录后才可以回帖 登录 | 注册

    提醒: 禁止引战、谩骂、灌水内容

    微信二维码

    有问题联系客服