簡體   English   中英

Mql4 指標不會自動更新

[英]Mql4 indicator does not update automatically

我遇到了我正在處理的指標的一些問題,有人可以看看並告訴我為什么會導致這個問題嗎?

簡單地說,指標不刷新

說明:當我將指標附加到圖表並保持打開狀態時,一段時間后,當我附加具有類似參數的同一指標的另一個實例時,新指標會顯示與之前附加到圖表的線不同的線,即使我沒有附加新指標,只需雙擊當前附加的指標,然后單擊“確定”按鈕,它會更改先前繪制的蠟燭線,請查看屏幕截圖在此處輸入圖片說明

有時變化太大,有時變化不大,但總有一些變化,這取決於我在指標上雙擊並按確定后多少條。

如果有人能指出我做錯了什么,我將不勝感激,謝謝

這是我的代碼:

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

我認為問題是你必須在緩沖區中聲明美元和歐元的所有 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