揭秘黑幕 发表于 2020-8-21 10:00:05

学习了,不错

1毛硬币 发表于 2020-8-29 10:21:25

谢谢楼主分享

波托菲诺 发表于 2020-11-16 19:50:02

{:1_186:}

法尔考2012 发表于 2021-7-12 15:58:41

谢谢

brigand4th 发表于 2021-7-14 18:47:11

顶下

shuiqing119 发表于 2021-7-17 23:49:24

{:1_179:}

上海金复 发表于 2021-7-21 10:00:32

{:1_179:}

博信黄金 发表于 2021-7-23 21:51:29

支持下

小风 发表于 2025-6-22 22:52:34

{:1_189:}

费克斯坦_7224 发表于 2025-6-23 17:30:34

//+------------------------------------------------------------------+
//|                                                   PriceAlert.mq4 |
//|                        Copyright 2023, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 0

// 全局变量
datetime lastAlertTime;
bool   alertTriggered = false;

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

//+------------------------------------------------------------------+
//| 自定义指标迭代函数                                                |
//+------------------------------------------------------------------+
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[])
{
   // 仅在新K线或价格变动时检查
   if(Time != lastAlertTime || !alertTriggered)
   {
      // 获取前两根K线的最高价和最低价
      double prevHigh1 = iHigh(Symbol(), Period(), 1);
      double prevHigh2 = iHigh(Symbol(), Period(), 2);
      double prevLow1= iLow(Symbol(), Period(), 1);
      double prevLow2= iLow(Symbol(), Period(), 2);
      
      // 计算上下轨
      double upperBand = MathMax(prevHigh1, prevHigh2) * 1.001;
      double lowerBand = MathMin(prevLow1, prevLow2) * 0.999;
      
      // 获取当前价格(使用最新报价)
      double currentPrice = SymbolInfoDouble(Symbol(), SYMBOL_BID);
      
      // 检查突破条件
      if(currentPrice > upperBand)
      {
         TriggerAlert("UP", upperBand, currentPrice);
         alertTriggered = true;
         lastAlertTime = Time;
      }
      else if(currentPrice < lowerBand)
      {
         TriggerAlert("DOWN", lowerBand, currentPrice);
         alertTriggered = true;
         lastAlertTime = Time;
      }
      else
      {
         alertTriggered = false;
      }
   }
   
   return(rates_total);
}

//+------------------------------------------------------------------+
//| 触发报警函数                                                   |
//+------------------------------------------------------------------+
void TriggerAlert(string direction, double bandPrice, double currentPrice)
{
   string message = StringFormat("%s 突破警报! %s 当前价: %.5f, 触发价: %.5f",
                                 Symbol(),
                                 (direction == "UP") ? "向上" : "向下",
                                 currentPrice,
                                 bandPrice);
   
   // 弹出窗口报警
   Alert(message);
   
   // 播放声音报警(需将sound.wav放入MT4的sounds目录)
   PlaySound("alert.wav");
   
   // 发送通知到手机/邮箱(需在MT4设置中启用通知)
   SendNotification(message);
}
//+------------------------------------------------------------------+
页: 1 2 [3] 4
查看完整版本: 求助编个报警指标