please give me a help

mfpg
36
mfpg  

Good morning. 

I wrote a code, but MT5 tell me ——2022.06.07 10:03:04.912 ask (USDJPY,H1) array out of range in 'ask.mq5' (276,22);

I add a line at 275: ArrayResize(sig_USD,shiftbars); but it does not work anyway. can you give me a help please?

Vladimir Karputov
Moderator
306178
mfpg:

Good morning. 

I wrote a code, but MT5 tell me ——2022.06.07 10:03:04.912 ask (USDJPY,H1) array out of range in 'ask.mq5' (276,22);

I add a line at 275: ArrayResize(sig_USD,shiftbars); but it does not work anyway. can you give me a help please?

Please, insert code correctly: when editing a post, click   Code and paste your code in the popup window
QW147147
35
QW147147  
I need help my account and my broker isn't showing in my mt5 account.. Pls suggest me what to do..big amount in my account
mfpg
36
mfpg  
Vladimir Karputov #:
Please, insert code correctly: when editing a post, click    and paste your code in the popup window

sorry, when I  submit the code ,it says "Message may not exceed 64000 characters", acctrualy, the code is not so long. again, I submit the ask.mq5 as attachment.

Files:
ask.mq5  48 kb
Vladimir Karputov
Moderator
306178
mfpg # :

sorry, when I  submit the code ,it says "Message may not exceed 64000 characters", acctrualy, the code is not so long. again, I submit the ask.mq5 as attachment.

I saw your biggest mistake - you create a million (figuratively) indicator handles on each tick: this is a BIG MISTAKE!!! Remember: according to the MQL5 style, the indicator handle MUST be created ONCE and it must be done in OnInit!!!

mfpg
36
mfpg  
Vladimir Karputov #:

I saw your biggest mistake - you create a million (figuratively) indicator handles on each tick: this is a BIG MISTAKE!!! Remember: according to the MQL5 style, the indicator handle MUST be created ONCE and it must be done in OnInit!!!

thanks for your reply.

II reduced it a bit and modified the initialization position of the handle,

but it still reported an overflow error.

Please help me to look at the problem again, thank you.

#property copyright "2022, syh"
#property version   "1.1"
#property indicator_separate_window

#property indicator_buffers 8
#property indicator_plots   8

input bool USD=true;

input int shiftbars        = 3000;     // number of bars for calculating the indicator

input int X=1;
input int Y=2;
input int _pow=3;
input int _t2=4;

// results of currency lines                       
double USDplot[];


int sig_USD[];
//MA
double iMA1_UJ[],iMA2_UJ[],iMA3_UJ[],
       iMA1_EU[],iMA2_EU[],iMA3_EU[],
       iMA1_UF[],iMA2_UF[],iMA3_UF[],
       iMA1_GU[],iMA2_GU[],iMA3_GU[],
       iMA1_UC[],iMA2_UC[],iMA3_UC[],
       iMA1_AU[],iMA2_AU[],iMA3_AU[],
       iMA1_NU[],iMA2_NU[],iMA3_NU[];

color Color_USD = Red;                       // USD line color

int   wid_BOLD =  3;                         //Lines width for current chart
int   wid_THIN =  1;

int              i;
int         y_pos = 0; // Y coordinate variable for the informatory objects  
datetime   arrTime[];  // Array with the last known time of a zero valued bar (needed for synchronization)  
int        bars_tf[];  // To check the number of available bars in different currency pairs  
int      countVal = 0; // Number of executable Rates  
int      countedK = 0;  //记录已经计算过指标的个数;

int iMA1_UJ_H,iMA2_UJ_H,iMA3_UJ_H;
int sig1=0 , sig2=0 , sig3=0 , sig4=0 , sig5=0 , sig6=0 , sig7=0 ,  j=0 , _i;
int limit=shiftbars;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorSetInteger(INDICATOR_DIGITS,1);
   string nameInd="LPV";

   IndicatorSetString(INDICATOR_SHORTNAME,nameInd);
      ArraySetAsSeries(iMA1_UJ,true);    ArrayInitialize(iMA1_UJ,EMPTY_VALUE);
      ArraySetAsSeries(iMA2_UJ,true);    ArrayInitialize(iMA2_UJ,EMPTY_VALUE);
      ArraySetAsSeries(iMA3_UJ,true);    ArrayInitialize(iMA3_UJ,EMPTY_VALUE);
      
      ArraySetAsSeries(iMA1_EU,true);    ArrayInitialize(iMA1_EU,EMPTY_VALUE);
      ArraySetAsSeries(iMA2_EU,true);    ArrayInitialize(iMA2_EU,EMPTY_VALUE);
      ArraySetAsSeries(iMA3_EU,true);    ArrayInitialize(iMA3_EU,EMPTY_VALUE);

      ArraySetAsSeries(iMA1_UF,true);    ArrayInitialize(iMA1_UF,EMPTY_VALUE);
      ArraySetAsSeries(iMA2_UF,true);    ArrayInitialize(iMA2_UF,EMPTY_VALUE);
      ArraySetAsSeries(iMA3_UF,true);    ArrayInitialize(iMA3_UF,EMPTY_VALUE);

      ArraySetAsSeries(iMA1_GU,true);    ArrayInitialize(iMA1_GU,EMPTY_VALUE);
      ArraySetAsSeries(iMA2_GU,true);    ArrayInitialize(iMA2_GU,EMPTY_VALUE);
      ArraySetAsSeries(iMA3_GU,true);    ArrayInitialize(iMA3_GU,EMPTY_VALUE);

      ArraySetAsSeries(iMA1_UC,true);    ArrayInitialize(iMA1_UC,EMPTY_VALUE);
      ArraySetAsSeries(iMA2_UC,true);    ArrayInitialize(iMA2_UC,EMPTY_VALUE);
      ArraySetAsSeries(iMA3_UC,true);    ArrayInitialize(iMA3_UC,EMPTY_VALUE);

      ArraySetAsSeries(iMA1_AU,true);    ArrayInitialize(iMA1_AU,EMPTY_VALUE);
      ArraySetAsSeries(iMA2_AU,true);    ArrayInitialize(iMA2_AU,EMPTY_VALUE);
      ArraySetAsSeries(iMA3_AU,true);    ArrayInitialize(iMA3_AU,EMPTY_VALUE);

      ArraySetAsSeries(iMA1_NU,true);    ArrayInitialize(iMA1_NU,EMPTY_VALUE);
      ArraySetAsSeries(iMA2_NU,true);    ArrayInitialize(iMA2_NU,EMPTY_VALUE);
      ArraySetAsSeries(iMA3_NU,true);    ArrayInitialize(iMA3_NU,EMPTY_VALUE);

      iMA1_UJ_H =iMA( "USDJPY", 0, 5  , 0, MODE_SMA, PRICE_CLOSE );   if(CopyBuffer(iMA1_UJ_H ,0, 0, shiftbars ,iMA1_UJ )<=0) return(0);
      iMA2_UJ_H =iMA( "USDJPY", 0, 10 , 0, MODE_SMA, PRICE_CLOSE );   if(CopyBuffer(iMA2_UJ_H ,0, 0, shiftbars ,iMA2_UJ )<=0) return(0);
      iMA3_UJ_H =iMA( "USDJPY", 0, 20 , 0, MODE_SMA, PRICE_CLOSE );   if(CopyBuffer(iMA3_UJ_H ,0, 0, shiftbars ,iMA3_UJ )<=0) return(0);

//================================================================================      
//初始化格式;
   if(USD) { countVal++;  SetIndexBuffer(0,USDplot,INDICATOR_DATA);  PlotIndexSetString(0,PLOT_LABEL,"USDplot");  PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,shiftbars);  PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE);  PlotIndexSetInteger(0,PLOT_LINE_COLOR,Color_USD);  PlotIndexSetInteger(0,PLOT_LINE_WIDTH,wid_BOLD);  ArraySetAsSeries(USDplot,true);  ArrayInitialize(USDplot,EMPTY_VALUE);  f_draw("USD",Color_USD); }
   ArrayResize(arrTime,countVal-1);
   ArrayResize(bars_tf,countVal-1);
  return(1);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int     rates_total, // size of incoming time series
                const int prev_calculated, // processing of bars on the previous request
                const datetime&    time[], // Time
                const double&      open[], // Open
                const double&      high[], // High
                const double&       low[], // Low
                const double&     close[], // Close
                const long& tick_volume[], // Tick Volume
                const long&      volume[], // Real Volume
                const int&       spread[]) // Spread
  {
   //int limit=shiftbars;
   countedK = prev_calculated;
   if(prev_calculated>0)
     {limit=1;}
   else
     {limit=shiftbars;}

   if (USD)
      {
        for(i=limit;i>=0;i--)//for(j=limit-1;j>=0;j--)
           { sig1=0 ; sig2=0 ; sig3=0 ; sig4=0 ; sig5=0 ; sig6=0 ; sig7=0 ;
             if (iMA1_UJ[i] >iMA2_UJ[i] ) sig1=sig1+1 ; else sig1=sig1-1 ;    if (iMA1_EU[i] >iMA2_EU[i] ) sig2=sig2+1 ; else sig2=sig2-1 ;
             if (iMA1_UJ[i] >iMA3_UJ[i] ) sig1=sig1+2 ; else sig1=sig1-2 ;    if (iMA1_EU[i] >iMA3_EU[i] ) sig2=sig2+2 ; else sig2=sig2-2 ;
             if (iMA2_UJ[i] >iMA3_UJ[i] ) sig1=sig1+2 ; else sig1=sig1-2 ;    if (iMA2_EU[i] >iMA3_EU[i] ) sig2=sig2+2 ; else sig2=sig2-2 ;

             if (iMA1_UF[i] >iMA2_UF[i] ) sig3=sig3+1 ; else sig3=sig3-1 ;    if (iMA1_GU[i] >iMA2_GU[i] ) sig4=sig4+1 ; else sig4=sig4-1 ;
             if (iMA1_UF[i] >iMA3_UF[i] ) sig3=sig3+2 ; else sig3=sig3-2 ;    if (iMA1_GU[i] >iMA3_GU[i] ) sig4=sig4+2 ; else sig4=sig4-2 ;
             if (iMA2_UF[i] >iMA3_UF[i] ) sig3=sig3+2 ; else sig3=sig3-2 ;    if (iMA2_GU[i] >iMA3_GU[i] ) sig4=sig4+2 ; else sig4=sig4-2 ;
             
             if (iMA1_UC[i] >iMA2_UC[i] ) sig5=sig5+1 ; else sig5=sig5-1 ;    if (iMA1_AU[i] >iMA2_AU[i] ) sig6=sig6+1 ; else sig6=sig6-1 ;
             if (iMA1_UC[i] >iMA3_UC[i] ) sig5=sig5+2 ; else sig5=sig5-2 ;    if (iMA1_AU[i] >iMA3_AU[i] ) sig6=sig6+2 ; else sig6=sig6-2 ;
             if (iMA2_UC[i] >iMA3_UC[i] ) sig5=sig5+2 ; else sig5=sig5-2 ;    if (iMA2_AU[i] >iMA3_AU[i] ) sig6=sig6+2 ; else sig6=sig6-2 ;

             if (iMA1_NU[i] >iMA2_NU[i] ) sig7=sig7+1 ; else sig7=sig7-1 ;
             if (iMA1_NU[i] >iMA3_NU[i] ) sig7=sig7+2 ; else sig7=sig7-2 ;
             if (iMA2_NU[i] >iMA3_NU[i] ) sig7=sig7+2 ; else sig7=sig7-2 ;
//ArrayResize(sig_USD,shiftbars);
             sig_USD[i]=+sig1-sig2+sig3-sig4+sig5-sig6-sig7;

           }

//=====================      
        for(i=limit-1;i>=0;i--) 
           {
            USDplot[i]=MathPow(X*sig_USD[i]+Y*sig_USD[StringToInteger(DoubleToString(MathFloor(i/_t2),0))],_pow)/MathPow(1000,_pow);
           }
     }
   return(rates_total);
  }

//+------------------------------------------------------------------+
///                        Auxiliary functions
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
///        Drawing objects
//+------------------------------------------------------------------+   

int f_draw(string name,color _color)
  {
   ObjectCreate(0,name,OBJ_LABEL,ChartWindowFind(),0,0);
   ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_RIGHT_UPPER);
   ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_RIGHT_UPPER);
   ObjectSetInteger(0,name,OBJPROP_XDISTANCE,0);
   ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y_pos);
   ObjectSetString(0,name,OBJPROP_TEXT,name);
   ObjectSetInteger(0,name,OBJPROP_COLOR,_color);
   y_pos+=15;
   return(0);
  }
Vladimir Karputov
Moderator
306178

Create a blank using the MQL5 Wizard - You will see that the 'MQL5 Wizard' creates arrays correctly...





mfpg
36
mfpg  
Vladimir Karputov #:

Create a blank using the MQL5 Wizard - You will see that the 'MQL5 Wizard' creates arrays correctly...





Thanks again, I have tried doing it (below).

The problem is that my indicator lines are from calculations on multiple array relationships.

MT5 reported an array overflow, could you please see the cause of the underflow? I really can't find the problem so I'm asking for your help.


//+------------------------------------------------------------------+
//|                                                         ask4.mq5 |
//|                                                              syh |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "syh"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot usd
#property indicator_label1  "usd"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double         usdBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,usdBuffer,INDICATOR_DATA);
   
//---
   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[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Vladimir Karputov
Moderator
306178
mfpg # :

Thanks again, I have tried doing it (below).

The problem is that my indicator lines are from calculations on multiple array relationships.

MT5 reported an array overflow, could you please see the cause of the underflow? I really can't find the problem so I'm asking for your help.


Now manually add two service arrays - they will store the values of two indicators.

mfpg
36
mfpg  
Vladimir Karputov #:

Now manually add two service arrays - they will store the values of two indicators.

like this  below?   I added  iMA1_UJ_H,iMA2_UJ_H;

//+------------------------------------------------------------------+
//|                                                         ask4.mq5 |
//|                                                              syh |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "syh"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot usd
#property indicator_label1  "usd"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double         usdBuffer[];
int            iMA1_UJ_H,iMA2_UJ_H;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,usdBuffer,INDICATOR_DATA);

   iMA1_UJ_H =iMA( "USDJPY", 0, 5  , 0, MODE_SMA, PRICE_CLOSE );
   iMA2_UJ_H =iMA( "USDJPY", 0, 10 , 0, MODE_SMA, PRICE_CLOSE );   
//---
   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[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2022.06.10
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
Vladimir Karputov
Moderator
306178

You forgot to link the 'iMA1_UJ_H,iMA2_UJ_H' arrays:

 //+------------------------------------------------------------------+
 //|                                                         ask4.mq5 |
 //|                                                              syh |
 //|                                             https://www.mql5.com |
 //+------------------------------------------------------------------+
 #property copyright "syh"
 #property link        "https://www.mql5.com"
 #property version    "1.00"
 #property indicator_separate_window
 #property indicator_buffers 3
 #property indicator_plots    1
 //--- plot usd
 #property indicator_label1    "usd"
 #property indicator_type1    DRAW_LINE
 #property indicator_color1    clrRed
 #property indicator_style1    STYLE_SOLID
 #property indicator_width1    1
 //--- indicator buffers
 double          usdBuffer[];
 double          iMA1_UJ_H_Buffer[];
 double          iMA2_UJ_H_Buffer[];
 //---
 int             iMA1_UJ_H,iMA2_UJ_H;
 //+------------------------------------------------------------------+
 //| Custom indicator initialization function                         |
 //+------------------------------------------------------------------+
 int OnInit ()
  {
 //--- indicator buffers mapping 
   SetIndexBuffer ( 0 ,usdBuffer, INDICATOR_DATA );
    SetIndexBuffer ( 1 ,iMA1_UJ_H_Buffer, INDICATOR_CALCULATIONS );
   SetIndexBuffer ( 2 ,iMA2_UJ_H_Buffer, INDICATOR_CALCULATIONS ); 
   iMA1_UJ_H = iMA ( "USDJPY" , 0 , 5 , 0 , MODE_SMA , PRICE_CLOSE );
   iMA2_UJ_H = iMA ( "USDJPY" , 0 , 10 , 0 , MODE_SMA , PRICE_CLOSE );
 //--- 
   return ( INIT_SUCCEEDED );
  }
***


Also, you didn't check: You don't check the result of handle creation. You must put a handle check.