简体   繁体   English

Mql4 指标不会自动更新

[英]Mql4 indicator does not update automatically

i am experience some issue with an indicator that i am working on , can somebody please take a look and tell me why its causing this issue ?我遇到了我正在处理的指标的一些问题,有人可以看看并告诉我为什么会导致这个问题吗?

to put it simply the indicator is not refreshing简单地说,指标不刷新

Explanation: when i attach the indicator to the chart and leave it on, after sometime when i attach another instance of the same indicator with similar parameters then then new indicator shows different lines then the one that was previously attached to the chart even if i dont attach the new indicator , and simply double click on the currently attached indicator and then click on the OK button it changes the lines for the previously drawn candles see the screenshot please说明:当我将指标附加到图表并保持打开状态时,一段时间后,当我附加具有类似参数的同一指标的另一个实例时,新指标会显示与之前附加到图表的线不同的线,即使我没有附加新指标,只需双击当前附加的指标,然后单击“确定”按钮,它会更改先前绘制的蜡烛线,请查看屏幕截图在此处输入图片说明

Sometimes the change is too much and sometimes the change is not too much , but there is always some changes , depending on after how many bars i double click and press OK on the indicator有时变化太大,有时变化不大,但总有一些变化,这取决于我在指标上双击并按确定后多少条。

i will highly appreciate if someone can point what am i doing wrong, thanks如果有人能指出我做错了什么,我将不胜感激,谢谢

Here is my code :这是我的代码:

#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);
  }

I think the issue is that you got to declare all 7 variable of the USD and EUR in a buffer and like this.... and put them in a separate for loop我认为问题是你必须在缓冲区中声明美元和欧元的所有 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM