【问题标题】:Clicking refresh sometimes leads to different custom indicator results单击刷新有时会导致不同的自定义指标结果
【发布时间】:2018-01-31 15:25:27
【问题描述】:

我有一个奇怪的现象,我无法弄清楚。我开发了一个自定义指标来计算一个指数,然后我将做出交易决策。该指标使用三个时间段来检查趋势是否稳定。第一个是一分钟,第二个是 5 分钟,最后是 30 分钟。我计算了合适的柱,从中检查较大的时间段,以便它们与一分钟柱相对应。

我的测试表明这些数字计算正确。

此指标附加到一分钟图表。很多时候,我会右键单击并选择刷新,指标会在最后 5 - 10 分钟内发生变化!我找不到它会这样做的原因。我尝试在每分钟栏后单击刷新,有时它会改变,而其他时候则不会。但是,即使我在图表上每分钟点击一次,有时更改也会在 5 到 10 分钟后返回。

你能帮帮我吗?

为了您的帮助,我附上我的代码:

int start()                         // Special function start()
  {
   int i,                        // Bar index                           
       iLook = 0,
       iCurrMinute = 0,
       iMinFloor = 0,
       iMinsAdd = 0,
       Counted_bars,                // Number of counted bars
       iCalcVal,
       iTrendConsistency;                    

   double EMA_1min_10_current, EMA_1min_10_prev,    
          EMA_5min_10_current, EMA_5min_10_prev,
          EMA_30min_10_current, EMA_30min_10_prev,
          EMA_1min_20_current, EMA_1min_20_prev,    
          EMA_5min_20_current, EMA_5min_20_prev,
          EMA_30min_20_current, EMA_30min_20_prev,
          dblMinRemain = 0;

   datetime dtBarTime;
//--------------------------------------------------------------------
   Counted_bars=IndicatorCounted(); // Number of counted bars
   i=Bars-Counted_bars-1;           // Index of the first uncounted
   while(i>=0)                      // Loop for uncounted bars
     {
      iCalcVal = 0;
      iTrendConsistency = 0;
      dtBarTime = iTime(NULL,PERIOD_M1,i);

      //  Calculate trend consistency
      if (boolIncl1Min)
      {
         iLook = i;

         EMA_1min_10_current = iMA(NULL,PERIOD_M1,intMAShort,0,MODE_EMA,PRICE_CLOSE,iLook);
         EMA_1min_10_prev = iMA(NULL,PERIOD_M1,intMAShort,0,MODE_EMA,PRICE_CLOSE,iLook+1);    
         EMA_1min_20_current = iMA(NULL,PERIOD_M1,intMAMedium,0,MODE_EMA,PRICE_CLOSE,iLook);
         EMA_1min_20_prev = iMA(NULL,PERIOD_M1,intMAMedium,0,MODE_EMA,PRICE_CLOSE,iLook+1);

         if (EMA_1min_10_current > EMA_1min_20_current) iTrendConsistency++; 
         if (EMA_1min_10_current < EMA_1min_20_current) iTrendConsistency--;

         if (EMA_1min_10_current > EMA_1min_10_prev) iTrendConsistency++; 
         if (EMA_1min_10_current < EMA_1min_10_prev) iTrendConsistency--;

         if (EMA_1min_20_current > EMA_1min_20_prev) iTrendConsistency++; 
         if (EMA_1min_20_current < EMA_1min_20_prev) iTrendConsistency--;

         if (iClose(NULL,PERIOD_M1,iLook) > EMA_1min_10_current) iTrendConsistency++;
         if (iClose(NULL,PERIOD_M1,iLook) < EMA_1min_10_current) iTrendConsistency--;
      }

      if (boolIncl5Min) 
      {

         iLook = i;
         if (boolIncl1Min) iLook = iBarShift(NULL,PERIOD_M5,dtBarTime,true);

         EMA_5min_10_current = iMA(NULL,PERIOD_M5,intMAShort,0,MODE_EMA,PRICE_CLOSE,iLook);
         EMA_5min_10_prev = iMA(NULL,PERIOD_M5,intMAShort,0,MODE_EMA,PRICE_CLOSE,iLook+1);

         EMA_5min_20_current = iMA(NULL,PERIOD_M5,intMAMedium,0,MODE_EMA,PRICE_CLOSE,iLook);
         EMA_5min_20_prev = iMA(NULL,PERIOD_M5,intMAMedium,0,MODE_EMA,PRICE_CLOSE,iLook+1);

         if (EMA_5min_10_current > EMA_5min_20_current) iTrendConsistency++; 
         if (EMA_5min_10_current < EMA_5min_20_current) iTrendConsistency--;

         if (EMA_5min_10_current > EMA_5min_10_prev) iTrendConsistency++; 
         if (EMA_5min_10_current < EMA_5min_10_prev) iTrendConsistency--;

         if (EMA_5min_20_current > EMA_5min_20_prev) iTrendConsistency++; 
         if (EMA_5min_20_current < EMA_5min_20_prev) iTrendConsistency--;

         if (iClose(NULL,PERIOD_M5,iLook) > EMA_5min_10_current) iTrendConsistency++;
         if (iClose(NULL,PERIOD_M5,iLook) < EMA_5min_10_current) iTrendConsistency--;
      }

      if(boolIncl30Min)
      {  

         iLook = i;

         if (boolIncl1Min) iLook = iBarShift(NULL,PERIOD_M30,dtBarTime,true);

         EMA_30min_10_current = iMA(NULL,PERIOD_M30,intMAShort,0,MODE_EMA,PRICE_CLOSE,iLook);
         EMA_30min_10_prev = iMA(NULL,PERIOD_M30,intMAShort,0,MODE_EMA,PRICE_CLOSE,iLook+1);
         EMA_30min_20_current = iMA(NULL,PERIOD_M30,intMAMedium,0,MODE_EMA,PRICE_CLOSE,iLook);
         EMA_30min_20_prev = iMA(NULL,PERIOD_M30,intMAMedium,0,MODE_EMA,PRICE_CLOSE,iLook+1);

         if (EMA_30min_10_current > EMA_30min_20_current) iTrendConsistency++;
         if (EMA_30min_10_current < EMA_30min_20_current) iTrendConsistency--;

         if (EMA_30min_10_current > EMA_30min_10_prev) iTrendConsistency++; 
         if (EMA_30min_10_current < EMA_30min_10_prev) iTrendConsistency--;

         if (EMA_30min_20_current > EMA_30min_20_prev) iTrendConsistency++;
         if (EMA_30min_20_current < EMA_30min_20_prev) iTrendConsistency--;


         if (iClose(NULL,PERIOD_M30,iLook) > EMA_30min_10_current) iTrendConsistency++;
         if (iClose(NULL,PERIOD_M30,iLook) < EMA_30min_10_current) iTrendConsistency--;
      }



      Trend_Consistency[i]= iTrendConsistency;

      i--;                          // Calculating index of the next bar
     }

ps:boolIncl1Min 始终为 true..

【问题讨论】:

    标签: refresh mql4 indicator


    【解决方案1】:

    我终于找到了困扰我好几天的答案! 5 分钟或 30 分钟图表的条件在最近的柱期间发生变化。一分钟条记录每分钟 5 分钟和 30 分钟的情况。如果我点击刷新,过去的柱现在是固定的,因此可以最终计算出来。

    如果这些条件发生变化,则需要代码来更新过去的柱状图。

    感谢您考虑帮助我。

    【讨论】:

      猜你喜欢
      • 2018-02-07
      • 2021-09-30
      相关资源
      最近更新 更多