【问题标题】:Mql4 indicator does not update automaticallyMql4 指标不会自动更新
【发布时间】:2021-12-21 13:23:57
【问题描述】:

我正在处理的指标遇到一些问题,有人可以看看并告诉我为什么会导致这个问题吗?

简而言之,指标不刷新

解释: 当我将指标附加到图表并保持打开状态时,有时当我附加具有相似参数的同一指标的另一个实例时,然后新指标显示不同的线,然后是先前附加到图表的线 即使我没有附加新指标,只需双击当前附加的指标,然后单击确定按钮,它就会更改先前绘制的蜡烛线 请看截图

有时变化太大,有时变化不大,但总有一些变化,这取决于我双击多少条柱并在指标上按确定

如果有人能指出我做错了什么,我将不胜感激,谢谢

这是我的代码:

#property copyright ""
#property link      ""
#property version   ""
#property description ""


//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_type1 DRAW_LINE
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
#property indicator_color1 Yellow
#property indicator_label1 "USD"

#property indicator_type2 DRAW_LINE
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
#property indicator_color2 Aqua
#property indicator_label2 "EUR"

                         

//--- indicator buffers
double Buffer1[];
double Buffer2[];

//--- Rsi Value
extern int R_Value = 5;
double myPoint; //initialized in OnInit



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
  string per = R_Value;
  per = StringConcatenate("RSI(",per,")");
  IndicatorShortName(per);
  printf(per);


   IndicatorBuffers(2);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, EMPTY_VALUE);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, EMPTY_VALUE);

   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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 limit = rates_total - prev_calculated;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, 0);
      ArrayInitialize(Buffer2, 0);
     }
   else
      limit++;

   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
  if (i >= MathMin(5000-1, rates_total-1-50)) continue;    
  
  //Indicator Buffer 1
  double EURUSDs=0;
  double GBPUSDs=0;
  double AUDUSDs=0;
  double NZDUSDs=0;
  
  double USDCADs=0;
  double USDCHFs=0;
  double USDJPYs=0;
                      
        EURUSDs = iRSI("EURUSD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
        double USD1 = 100-EURUSDs;
        GBPUSDs = iRSI("GBPUSD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
        double USD2 = 100-GBPUSDs;
        AUDUSDs = iRSI("AUDUSD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
        double USD3 = 100-AUDUSDs; 
    NZDUSDs = iRSI("NZDUSD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
    double USD4 = 100-NZDUSDs;
        double USD5 = iRSI("USDCAD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
        double USD6 = iRSI("USDCHF",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
        double USD7 = iRSI("USDJPY",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
    
    double USDtotal= (USD1+USD2+USD3+USD4+USD5+USD6+USD7);
        double USDtota2= USDtotal/7;
  
       
     {
     Buffer1[i] = USDtota2;
     }

     
    


  //Indicator Buffer 2
  
   EURUSDs=0;
  double EURGBPs=0;
  double EURJPYs=0;
  double EURAUDs=0;
  double EURCADs=0;
  double EURCHFs=0;
  double EURNZDs=0; 
         
         
        double EUR1 =  iRSI("EURUSD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
    double EUR2 =  iRSI("EURGBP",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
        double EUR3 =  iRSI("EURJPY",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
        double EUR4 =  iRSI("EURAUD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
        double EUR5 =  iRSI("EURCAD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
        double EUR6 =  iRSI("EURCHF",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
        double EUR7 =  iRSI("EURNZD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
        
    double EURtotal= (EUR1+EUR2+EUR3+EUR4+EUR5+EUR6+EUR7);
        double EURtota2= EURtotal/7; 
    
     {
     Buffer2[i] = EURtota2;
     }

    }
   return(rates_total);
  }

【问题讨论】:

    标签: mql4 metatrader4 mql5 mql mt4


    【解决方案1】:

    我认为问题在于你必须在缓冲区中声明 USD 和 EUR 的所有 7 个变量,就像这样......并将它们放在单独的 for 循环中

    for(int i = limit-1; i >= 0; i--)
    EUR1[i] =  iRSI("EURUSD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
    EUR2[i] =  iRSI("EURGBP",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
    EUR3[i] =  iRSI("EURJPY",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
    EUR4[i] =  iRSI("EURAUD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
    EUR5[i] =  iRSI("EURCAD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
    EUR6[i] =  iRSI("EURCHF",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
    EUR7[i] =  iRSI("EURNZD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
    

    【讨论】:

      猜你喜欢
      • 2015-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-05
      • 1970-01-01
      • 2020-09-09
      • 2013-05-20
      相关资源
      最近更新 更多