任何菜鸟问题,为了不给论坛添乱。专业人士,不要路过。没有你就无处可去 - 6. - 页 987

 
mario_SC--:

我不知道你想用这段代码证明什么,但我知道一个事实,我无法融入审查员的行列......因此,如果你想得到帮助,你就得自己成为一个提问者。这样的循环很容易在一定条件下循环,只有机会才能让它不发生。
 

为什么在调试指标 时,调试器会 "崩溃"(因为它访问了数组的边界),但同时在图表上一切都能正常绘制?

MT4 build 950, Alpari demo.

该指标已被附上。

//+------------------------------------------------------------------+
//|                                     FX5_MACD_Divergence_V1.1.mq4 |
//|                                                              FX5 |
//|                                                    hazem@uk2.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, FX5"
#property link      "hazem@uk2.net"
//----
#property indicator_separate_window
#property indicator_buffers 4
#property  indicator_color1 Green
#property  indicator_color2 Red
#property  indicator_color3 Magenta
#property  indicator_color4 Blue
//----
#define  arrowsDisplacement 0.0001
//---- input parameters
extern string separator1 = "*** MACD Settings ***";
extern int    fastEMA = 12;
extern int    slowEMA = 26;
extern int    signalSMA = 9;
extern string separator2 = "*** Indicator Settings ***";
extern bool   drawIndicatorTrendLines = true;
extern bool   drawPriceTrendLines = true;
extern bool   displayAlert = true;
//---- buffers
double bullishDivergence[];
double bearishDivergence[];
double macd[];
double signal[];
//----
static datetime lastAlertTime;
static string   indicatorName;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexStyle(2, DRAW_LINE);
   SetIndexStyle(3, DRAW_LINE);
//----   
   SetIndexBuffer(0, bullishDivergence);
   SetIndexBuffer(1, bearishDivergence);
   SetIndexBuffer(2, macd);
   SetIndexBuffer(3, signal);   
//----   
   SetIndexArrow(0, 233);
   SetIndexArrow(1, 234);
//----
   indicatorName = "FX5_MACD_Divergence_v1.1(" + fastEMA + ", " + 
                                 slowEMA + ", " + signalSMA + ")";
   SetIndexDrawBegin(3, signalSMA);
   IndicatorDigits(Digits + 2);
   IndicatorShortName(indicatorName);

   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   for(int i = ObjectsTotal() - 1; i >= 0; i--)
     {
       string label = ObjectName(i);
       if(StringSubstr(label, 0, 19) != "MACD_DivergenceLine")
           continue;
       ObjectDelete(label);   
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int countedBars = IndicatorCounted();
   if(countedBars < 0)
       countedBars = 0;
   CalculateIndicator(countedBars);
//---- 
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CalculateIndicator(int countedBars)
  {
   for(int i = Bars - countedBars; i >= 0; i--)
     {
       CalculateMACD(i);
       CatchBullishDivergence(i + 2);
       CatchBearishDivergence(i + 2);
     }              
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CalculateMACD(int i)
  {
   macd[i] = iMACD(NULL, 0, fastEMA, slowEMA, signalSMA, 
                   PRICE_CLOSE, MODE_MAIN, i);
   
   signal[i] = iMACD(NULL, 0, fastEMA, slowEMA, signalSMA, 
                     PRICE_CLOSE, MODE_SIGNAL, i);         
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CatchBullishDivergence(int shift)
  {
   if(IsIndicatorTrough(shift) == false)
       return;  
   int currentTrough = shift;
   int lastTrough = GetIndicatorLastTrough(shift);
//----   
   if(macd[currentTrough] > macd[lastTrough] && 
      Low[currentTrough] < Low[lastTrough])
     {
       bullishDivergence[currentTrough] = macd[currentTrough] - 
                                          arrowsDisplacement;
       //----
       if(drawPriceTrendLines == true)
           DrawPriceTrendLine(Time[currentTrough], Time[lastTrough], 
                              Low[currentTrough], 
                             Low[lastTrough], Green, STYLE_SOLID);
       //----
       if(drawIndicatorTrendLines == true)
          DrawIndicatorTrendLine(Time[currentTrough], 
                                 Time[lastTrough], 
                                 macd[currentTrough],
                                 macd[lastTrough], 
                                 Green, STYLE_SOLID);
       //----
       if(displayAlert == true)
          DisplayAlert("Classical bullish divergence on: ", 
                        currentTrough);  
     }
//----   
   if(macd[currentTrough] < macd[lastTrough] && 
      Low[currentTrough] > Low[lastTrough])
     {
       bullishDivergence[currentTrough] = macd[currentTrough] - 
                                          arrowsDisplacement;
       //----
       if(drawPriceTrendLines == true)
           DrawPriceTrendLine(Time[currentTrough], Time[lastTrough], 
                              Low[currentTrough], 
                              Low[lastTrough], Green, STYLE_DOT);
       //----
       if(drawIndicatorTrendLines == true)                            
           DrawIndicatorTrendLine(Time[currentTrough], 
                                  Time[lastTrough], 
                                  macd[currentTrough],
                                  macd[lastTrough], 
                                  Green, STYLE_DOT);
       //----
       if(displayAlert == true)
           DisplayAlert("Reverse bullish divergence on: ", 
                        currentTrough);   
     }      
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CatchBearishDivergence(int shift)
  {
   if(IsIndicatorPeak(shift) == false)
       return;
   int currentPeak = shift;
   int lastPeak = GetIndicatorLastPeak(shift);
//----   
   if(macd[currentPeak] < macd[lastPeak] && 
      High[currentPeak] > High[lastPeak])
     {
       bearishDivergence[currentPeak] = macd[currentPeak] + 
                                        arrowsDisplacement;
      
       if(drawPriceTrendLines == true)
           DrawPriceTrendLine(Time[currentPeak], Time[lastPeak], 
                              High[currentPeak], 
                              High[lastPeak], Red, STYLE_SOLID);
                            
       if(drawIndicatorTrendLines == true)
           DrawIndicatorTrendLine(Time[currentPeak], Time[lastPeak], 
                                  macd[currentPeak],
                                  macd[lastPeak], Red, STYLE_SOLID);

       if(displayAlert == true)
           DisplayAlert("Classical bearish divergence on: ", 
                        currentPeak);  
     }
   if(macd[currentPeak] > macd[lastPeak] && 
      High[currentPeak] < High[lastPeak])
     {
       bearishDivergence[currentPeak] = macd[currentPeak] + 
                                        arrowsDisplacement;
       //----
       if(drawPriceTrendLines == true)
           DrawPriceTrendLine(Time[currentPeak], Time[lastPeak], 
                              High[currentPeak], 
                              High[lastPeak], Red, STYLE_DOT);
       //----
       if(drawIndicatorTrendLines == true)
           DrawIndicatorTrendLine(Time[currentPeak], Time[lastPeak], 
                                  macd[currentPeak],
                                  macd[lastPeak], Red, STYLE_DOT);
       //----
       if(displayAlert == true)
           DisplayAlert("Reverse bearish divergence on: ", 
                        currentPeak);   
     }   
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool IsIndicatorPeak(int shift)
  {
   if(macd[shift] >= macd[shift+1] && macd[shift] > macd[shift+2] && 
      macd[shift] > macd[shift-1])
       return(true);
   else 
       return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool IsIndicatorTrough(int shift)
  {
   if(macd[shift] <= macd[shift+1] && macd[shift] < macd[shift+2] && 
      macd[shift] < macd[shift-1])
       return(true);
   else 
       return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int GetIndicatorLastPeak(int shift)
  {
   for(int i = shift + 5; i < Bars; i++)
     {
       if(signal[i] >= signal[i+1] && signal[i] >= signal[i+2] &&
          signal[i] >= signal[i-1] && signal[i] >= signal[i-2])
         {
           for(int j = i; j < Bars; j++)
             {
               if(macd[j] >= macd[j+1] && macd[j] > macd[j+2] &&
                  macd[j] >= macd[j-1] && macd[j] > macd[j-2])
                   return(j);
             }
         }
     }
   return(-1);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int GetIndicatorLastTrough(int shift)
  {
    for(int i = shift + 5; i < Bars; i++)
      {
        if(signal[i] <= signal[i+1] && signal[i] <= signal[i+2] &&
           signal[i] <= signal[i-1] && signal[i] <= signal[i-2])
          {
            for (int j = i; j < Bars; j++)
              {
                if(macd[j] <= macd[j+1] && macd[j] < macd[j+2] &&
                   macd[j] <= macd[j-1] && macd[j] < macd[j-2])
                    return(j);
              }
          }
      }
    return(-1);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DisplayAlert(string message, int shift)
  {
   if(shift <= 2 && Time[shift] != lastAlertTime)
     {
       lastAlertTime = Time[shift];
       Alert(message, Symbol(), " , ", Period(), " minutes chart");
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DrawPriceTrendLine(datetime x1, datetime x2, double y1, 
                        double y2, color lineColor, double style)
  {
   string label = "MACD_DivergenceLine_v1.0# " + DoubleToStr(x1, 0);
   ObjectDelete(label);
   ObjectCreate(label, OBJ_TREND, 0, x1, y1, x2, y2, 0, 0);
   ObjectSet(label, OBJPROP_RAY, 0);
   ObjectSet(label, OBJPROP_COLOR, lineColor);
   ObjectSet(label, OBJPROP_STYLE, style);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DrawIndicatorTrendLine(datetime x1, datetime x2, double y1, 
                            double y2, color lineColor, double style)
  {
   int indicatorWindow = WindowFind(indicatorName);
   if(indicatorWindow < 0)
       return;
   string label = "MACD_DivergenceLine_v1.0$# " + DoubleToStr(x1, 0);
   ObjectDelete(label);
   ObjectCreate(label, OBJ_TREND, indicatorWindow, x1, y1, x2, y2, 
                0, 0);
   ObjectSet(label, OBJPROP_RAY, 0);
   ObjectSet(label, OBJPROP_COLOR, lineColor);
   ObjectSet(label, OBJPROP_STYLE, style);
  }
//+------------------------------------------------------------------+
 
r772ra:
在你的问题中,关于在看涨的蜡烛之后的剩余时间里寻找最高的汇率,关于服务器时间的时区 部分由于某种原因被遗漏了。任务与当天的界限严格挂钩,而这些界限在不同的公司是不同的。 属于不同日子的烛台是不同的。根据服务器的时区,你发现的最高值将属于不同的日子。这对你的情况来说正常吗?
 
大家好!

不是一个新手,但有一个 "愚蠢 "的问题,因为我几乎没有遇到过这种情况。

假设有一个 已经设定的挂单
我们使用指标来移动其价格。
在某一时刻,订单不能被修改,因为新的价格已经进入了禁止的范围,因为像Ask/Bid +/- MarketInfo(Symbol(), MODE_STOPLEVEL / MODE_FREEZELEVEL)这样的停止符号。

但订单必须由 "市场 "打开。

在这种情况下,我们能做什么?

我们是否可以删除挂单并在市场边上开一个新的挂单?

或者,是否有可能将挂单改为开单?
 
mt4trade:
大家好!

不是一个新手,但有一个 "愚蠢 "的问题,因为我几乎没有遇到过这种情况。

假设有一个已经设定的挂单。
我们使用指标来移动其价格。
在某一时刻,订单不能被修改,因为新的价格已经进入了禁止的范围,因为像Ask/Bid +/- MarketInfo(Symbol(), MODE_STOPLEVEL / MODE_FREEZELEVEL)这样的停止符号。

但订单必须由 "市场 "打开。

在这种情况下,我们能做什么?

我们是否可以删除挂单并在市场边上开一个新的挂单?

或者待定订单可以以某种方式转变为公开订单?
如果它与价格如此接近,价格会发现它,但不是,也许它是一个止损点更好!"。如果是限制性的,那就耐心等待。试着在测试器中进行实验,优化将决定最佳的变体!好运!
 

请帮助。

当我在一个独立的图表上安装EA 时,EA不能工作,因为start()函数没有启动。

我怎样才能实现从建立图表的EA,或从附属于此图表的EA进行图表更新?

 
borilunad:
如果在这么近的地方,价格会自己找到它,如果不是,也许是停在那里是最好的!而极限一,则是耐心。试着在测试器中进行实验,优化后将确定最佳的变体!好运!
谢谢你!这一切都很清楚。但我想知道我的问题的答案--如果我绝对必须使订单成功,无论价格会涨到什么程度,该怎么做? 应该删除挂单 并开立一个普通的订单,还是有一些其他的变体?
 
mt4trade:
谢谢你!但我需要一个问题的答案--如果不管现在价格走到哪里,都必须触发订单,我应该怎么做?我应该删除挂单并开立一个普通的订单吗?
对我来说,如果你遵循你的策略,那就去做吧!我不建议半途而废,否则没有确定的结果(正面或负面),你无法确定你的策略是否合理。就这样吧!
 
borilunad:
对我来说,如果你遵循你的策略,那就遵循它!我不建议中途改变它,否则没有确定的结果(正面或负面),你无法确定你的策略的合理性。就这样吧!
再次感谢您!你说的很对,但与问题无关。再次强调:如果挂单的计算价格已经达到了禁止范围,而且不能修改,但必须(根据策略)在计算价格上触发--你如何把它 "变成 "触发的?要删除它并作为一个正常的打开?还是有其他的选择?请准确回答这个问题。
 
mt4trade:
再次感谢您!你说的很对,但与问题无关。:)再次强调:如果一个挂单的计算价格已经达到了禁止范围,并且不能修改,但必须(根据策略)在计算价格上触发--我如何将其 "变成 "已触发的订单?要删除它并作为一个正常的打开?还是有其他的选择?请准确回答这个问题。
这种做法存在不一致之处。如果预计在冻结区开仓(不能修改)的是一个挂单,那么该订单最初应该以不同的价格,在这个冻结区的边界处下单。这就是为什么你的方法不被许多人接受。

具体到你的问题。首先删除挂单,然后立即在当前价格开立头寸。问题是,在这些行动中,价格可能会离开冻结区(更糟糕),头寸将以错误的价格开仓。另一个选择是不创建挂单,在程序中的一个变量中存储开仓的值。将其与当前价格进行比较,如果满足条件(考虑到冻结区),你就开仓。