找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
首页论坛EAHub 外汇论坛
查看: 10|回复: 0

指标无错误,但不工作,求编程达人指点帮改错,源码如下

[复制链接]

4万

主题

54

回帖

4万

积分

管理员

积分
45954
发表于 2026-8-22 19:24:00 | 显示全部楼层 |阅读模式
自己做了个多货币对均线交叉报警指标,但不工作,希望有高人指点修改

//+------------------------------------------------------------------+
//|                     MA cross.mq4 - I found it at fxfisherman.com |
//|                        Copyright 2012, www.forex-programming.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, www.forex-programming.com"
#property link      "www.forex-programming.com"

#property indicator_chart_window
extern string s1="-- MA settings --";
extern int    Fast_MA  = 5 ;
extern int    Slow_MA  = 10 ;
extern string s2="-- Alert settings --";
extern bool   ScreenAlert     =true,
              PushAlert       =false;

double        USDJPYFast1, USDJPYSlow1,USDCADFast1, USDCADSlow1,EURUSDFast1, EURUSDSlow1,GBPUSDFast1, GBPUSDSlow1;
double        USDJPYFast2, USDJPYSlow2,USDCADFast2, USDCADSlow2,EURUSDFast2, EURUSDSlow2,GBPUSDFast2, GBPUSDSlow2;
datetime      New_Time=0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   int limit=Bars-counted_bars;
   if (limit<0) limit=0;

   // define MAs values
   for (int i=limit; i>=0; i--)
      {
       USDJPYFast1=iMA("USDJPY#", PERIOD_M1, Fast_MA, 0, MODE_SMA, PRICE_CLOSE, 1);
       USDJPYSlow1=iMA("USDJPY#", PERIOD_M1, Slow_MA, 0, MODE_SMA, PRICE_CLOSE, 1);
       USDCADFast1=iMA("USDCAD#", PERIOD_M1, Fast_MA, 0, MODE_SMA, PRICE_CLOSE, 1);
       USDCADSlow1=iMA("USDCAD#", PERIOD_M1, Slow_MA, 0, MODE_SMA, PRICE_CLOSE, 1);      
       EURUSDFast1=iMA("EURUSD#", PERIOD_M1, Fast_MA, 0, MODE_SMA, PRICE_CLOSE, 1);
       EURUSDSlow1=iMA("EURUSD#", PERIOD_M1, Slow_MA, 0, MODE_SMA, PRICE_CLOSE, 1);
       GBPUSDFast1=iMA("GBPUSD#", PERIOD_M1, Fast_MA, 0, MODE_SMA, PRICE_CLOSE, 1);
       GBPUSDSlow1=iMA("GBPUSD#", PERIOD_M1, Slow_MA, 0, MODE_SMA, PRICE_CLOSE, 1);
        USDJPYFast2=iMA("USDJPY#", PERIOD_M1, Fast_MA, 0, MODE_SMA, PRICE_CLOSE, 2);
       USDJPYSlow2=iMA("USDJPY#", PERIOD_M1, Slow_MA, 0, MODE_SMA, PRICE_CLOSE, 2);
       USDCADFast2=iMA("USDCAD#", PERIOD_M1, Fast_MA, 0, MODE_SMA, PRICE_CLOSE, 2);
       USDCADSlow2=iMA("USDCAD#", PERIOD_M1, Slow_MA, 0, MODE_SMA, PRICE_CLOSE, 2);      
       EURUSDFast2=iMA("EURUSD#", PERIOD_M1, Fast_MA, 0, MODE_SMA, PRICE_CLOSE, 2);
       EURUSDSlow2=iMA("EURUSD#", PERIOD_M1, Slow_MA, 0, MODE_SMA, PRICE_CLOSE, 2);
       GBPUSDFast2=iMA("GBPUSD#", PERIOD_M1, Fast_MA, 0, MODE_SMA, PRICE_CLOSE, 2);
       GBPUSDSlow2=iMA("GBPUSD#", PERIOD_M1, Slow_MA, 0, MODE_SMA, PRICE_CLOSE, 2);

      }

   // Alert
      {
       // buy alert
       if ((New_Candle() && USDJPYFast1 > USDJPYSlow1 && USDJPYFast2 <= USDJPYSlow2))
         {
          if (ScreenAlert) Alert("BUY - "+"USDJPY");
          if (PushAlert) SendNotification("BUY -"+"USDJPY");
         }
       // sell alert
       if ((New_Candle() && USDJPYFast1 < USDJPYSlow1 && USDJPYFast2 >= USDJPYSlow2))
         {
          if (ScreenAlert) Alert("SELL - "+"USDJPY");
          if (PushAlert) SendNotification("SELL - "+"USDJPY");
         }
       // buy alert
       if ((New_Candle() && USDCADFast1 > USDCADSlow1 && USDCADFast2 <= USDCADSlow2))
         {
          if (ScreenAlert) Alert("BUY - "+"USDCAD");
          if (PushAlert) SendNotification("BUY -"+"USDCAD");
         }
       // sell alert
       if ((New_Candle() && USDCADFast1 < USDCADSlow1 && USDCADFast2 >= USDCADSlow2))
         {
          if (ScreenAlert) Alert("SELL - "+"USDCAD");
          if (PushAlert) SendNotification("SELL - "+"USDCAD");
         }
      // buy alert
       if ((New_Candle() && EURUSDFast1 > EURUSDSlow1 && EURUSDFast2 <= EURUSDSlow2))
         {
          if (ScreenAlert) Alert("BUY - "+"EURUSD");
          if (PushAlert) SendNotification("BUY -"+"EURUSD");
         }
       // sell alert
       if ((New_Candle() && EURUSDFast1 < EURUSDSlow1 && EURUSDFast2 >= EURUSDSlow2))
         {
          if (ScreenAlert) Alert("SELL - "+"EURUSD");
          if (PushAlert) SendNotification("SELL - "+"EURUSD");
         }
      // buy alert
       if ((New_Candle() && GBPUSDFast1 > GBPUSDSlow1 && GBPUSDFast2 <= GBPUSDSlow2))
         {
          if (ScreenAlert) Alert("BUY - "+"GBPUSD");
          if (PushAlert) SendNotification("BUY -"+"GBPUSD");
         }
       // sell alert
       if ((New_Candle() && USDJPYFast1 < GBPUSDSlow1 && GBPUSDFast2 >= GBPUSDSlow2))
         {
          if (ScreenAlert) Alert("SELL - "+"GBPUSD");
          if (PushAlert) SendNotification("SELL - "+"GBPUSD");
         }
      }

   return(0);
  }

//+------------------------------------------------------------------+
//| Define new candle                                                |
//+------------------------------------------------------------------+
bool New_Candle()
  {
   if (New_Time!=Time[0])
     {
      New_Time=Time[0];
      return(true);
     }
    else
     {
      return(false);
     }
  }

//+------------------------------------------------------------------+
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|EAHub外汇论坛

GMT+8, 2026-10-11 22:02 , Processed in 0.101964 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

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