Array out of range in Need of help - page 5

 
Ihor Herasko:

I don't even know what else to add... I've basically given the basic examples. This is the code. That's why you may ask me what's unclear.

Greetings ! Igor a clear example of how to get a value . I have a line Low_D1_Level find the nearest bar in the history which value will be lower than Low_D1_Level

If I work with Structure without array, I get the same result as in the last code.

Write an example , and if you don't mind a description .

//+------------------------------------------------------------------+
//|                                                   Dark_Level.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

double Low_D1_Level;

struct BarData
{ 
   datetime time;         // время начала периода 
   double   open;         // цена открытия 
   double   high;         // наивысшая цена за период 
   double   low;          // наименьшая цена за период 
   double   close;        // цена закрытия 
   long     tick_volume;  // тиковый объем 
};
BarData Bar_data_D1[]; // обьявляем массив структуры в памяти 
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{

 return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
 Low_D1_Level   = iLow (_Symbol,PERIOD_D1,1);   // Возвращает значение минимальной цены бара  D1
 
// Bar_data_D1.low [i]; //Минимум свечи
// Bar_data_D1.low [i]= iLow (_Symbol,PERIOD_D1,1);
}
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
  • www.mql5.com
One Click Close The script allows users to easily close positions if their profit/loss reaches or exceeds a value specified in pips. Please set slippage value first. Sometimes some positions do not close due to high volatility of the market. Please set larger slippage or restart the script. The free demo version is: ...
 
Dark Kchlyzov:

If Low_D1_Level is the level of the previous day, then Min_D_Level is searched fromLow_D1_Level and it is equal to i=1 , or am I mistaken?

Sorry, I didn't get into the code, I asked to make sure you were doing it consciously.

Can you tell me what you want to get as a result. Any daily levels or what? Looking at the first line, constantly copying an array in ArrayCopyRates and then loops through it is not the most economical option. You could find a more elegant solution.

 
Aleksei Stepanenko :

I apologize, I did not delve into the code, I asked to make sure that you are doing this consciously.

You can say what you want to get in the end. Any daily levels or what? Looking at the first line, constantly copying the array to ArrayCopyRates and then looping through it is not the most economical option. You can find a more elegant solution.

I have been on the stock exchange for more than 5 years, and at the moment I live completely ( you do this consciously ). A year ago, when the understanding of trading on the stock exchange was already more or less strengthened,

It was decided to automate their knowledge in the trade, want to do a good DIY.

This is how MQL4 consciously came to me, at the moment the EA has 6000+ lines.

here is an example code when calculating the lot 1 year ago.

 // Примитивно но работало 
//+-------------------------------------------------------------------------+
//                       Функция расчета лота от прибыли                    +                                                   +
//+-------------------------------------------------------------------------+
// double Lots;    
//string lots;      
double FloatingLots()
  {
   double Lots1= 1200 ,Lots2= 2200 ,Lots3= 3200 ,Lots4= 4200 ,Lots5= 5200 ,Lots6= 6200 ,Lots7= 7200 ,Lots8= 8200 ,Lots9= 9200 ,Lots10= 10200 ;
   if (AccountBalance()<=Lots1){Lots= 0.1 ;}
   if (AccountBalance()>=Lots1 && AccountBalance()<=Lots2){Lots= 0.2 ;}
   if (AccountBalance()>=Lots2 && AccountBalance()<=Lots3){Lots= 0.3 ;}
   if (AccountBalance()>=Lots3 && AccountBalance()<=Lots4){Lots= 0.4 ;}
   if (AccountBalance()>=Lots4 && AccountBalance()<=Lots5){Lots= 0.5 ;}
   if (AccountBalance()>=Lots5 && AccountBalance()<=Lots6){Lots= 0.6 ;}
   if (AccountBalance()>=Lots6 && AccountBalance()<=Lots7){Lots= 0.7 ;}
   if (AccountBalance()>=Lots7 && AccountBalance()<=Lots8){Lots= 0.8 ;}
   if (AccountBalance()>=Lots8 && AccountBalance()<=Lots9){Lots= 0.9 ;}
   if (AccountBalance()>=Lots9){Lots= 1 ;}
   return (Lots);
  } 

And here is the same function after half a year

 //+-------------------------------------------------------------------------+
//                  Функция расчета лота от прибыли  V 1.1                                                        +
//+-------------------------------------------------------------------------+
//double Lots; // переменная для расчёта лота и вывода в кнопке   
double FloatingLots()
{
 double S_lots = 0.1 ;
 double i;
 for ( i = 1000 ; i <= AccountBalance();i+= 1000 )
    {
     if (i > (AccountBalance())- 1000 )
       {
        Lots = S_lots; break ;
       }
     else S_lots+= 0.1 ;
    }
 return (S_lots);

Here's the reason for creating this thread.

I noticed purely by chance and visually when I started to run the adviser on long periods, if the second condition was removed in the cycle, an error occurred (out of the array) and the second condition simply masked the actual error.

Here is the Function that needs to be debugged, and it's time to study Structures, Classes.

Do not judge strictly for writing code -:)

 глоб. переменные
//+------------------------------------------------------------------+
//|                        Функция Level 
//+------------------------------------------------------------------+
double   Bar_data_D1 [][6]; // Копирует в массив данные баров указанного графика и возвращает количество скопированных баров D1
double   Bar_data_W1 [][6]; // Копирует в массив данные баров указанного графика и возвращает количество скопированных баров W1
double   Bar_data_MN [][6];
double   High_D1_Level;     // Возвращает значение максимальной цены бара D1
double   Low_D1_Level;      // Возвращает значение минимальной цены бара  D1
double   High_W1_Level;     // Возвращает значение максимальной цены бара W1
double   Low_W1_Level ;     // Возвращает значение минимальной цены бара  W1
double   High_MN1_Level;    // Возвращает значение максимальной цены бара MN1
double   Low_MN1_Level;     // Возвращает значение минимальной цены бара  MN1
double   Max_D_Level;       // ближайшей максимальный D уровень
double   Min_D_Level ;      // ближайшей минимальный  D уровень
double   Max_W_Level ;      // ближайшей максимальный W уровень
double   Min_W_Level ;      // ближайшей минимальный  W уровень
double   Max_MN_Level ;     // ближайшей максимальный MN уровень
double   Min_MN_Level ;     // ближайшей минимальный  MN уровень

int      Max_D_Num ;        // ближайшей максимальный день (номер бара)  
int      Min_D_Num ;        // ближайшей минимальный  день (номер бара)
int      Max_D_Volume ;     // ближайшей максимальный день (Объём)  
int      Min_D_Volume ;     // ближайшей минимальный  день (Объём)
datetime Max_D_Time;        // 
datetime Min_D_Time;        //
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|                        Функция Level v 1.0
//+------------------------------------------------------------------+
void Level()
{
 ArrayCopyRates(Bar_data_D1, _Symbol , PERIOD_D1 ); // Копирует в массив данные баров указанного графика и возвращает количество скопированных баров
 ArrayCopyRates(Bar_data_W1, _Symbol , PERIOD_W1 ); // Копирует в массив данные баров указанного графика и возвращает количество скопированных баров
 ArrayCopyRates(Bar_data_MN, _Symbol , PERIOD_MN1 ); // Копирует в массив данные баров указанного графика и возвращает количество скопированных баров
 
 High_D1_Level  = iHigh ( _Symbol , PERIOD_D1 , 1 );   // Возвращает значение максимальной цены бара D1
 Low_D1_Level   = iLow ( _Symbol , PERIOD_D1 , 1 );   // Возвращает значение минимальной цены бара  D1
 High_W1_Level  = iHigh ( _Symbol , PERIOD_W1 , 1 );   // Возвращает значение максимальной цены бара W1
 Low_W1_Level   = iLow ( _Symbol , PERIOD_W1 , 1 );   // Возвращает значение минимальной цены бара  W1 
 High_MN1_Level = iHigh ( _Symbol , PERIOD_MN1 , 1 );   // Возвращает значение максимальной цены бара MN1
 Low_MN1_Level  = iLow ( _Symbol , PERIOD_MN1 , 1 );   // Возвращает значение минимальной цены бара  MN1
 
//--- Max_D_Level
 for ( int i = 1 ; i< ArrayRange (Bar_data_D1, 0 ) ;i++)
    {
     //Print(" i = ",i);
     if (Bar_data_D1 [i][ 3 ]>= 0 )
       {
         if (Bar_data_D1 [i][ 3 ] > High_D1_Level)  
          {
           Max_D_Level = Bar_data_D1 [i][ 3 ]; break ;
          }
       }
    } 
    
//--- Min_D_Leve  
 for ( int i = 1 ; i< ArrayRange (Bar_data_D1, 0 ) ;i++)
    {
     Print ( "i = " ,i, " Bar_data_D1 [i][2] = " ,Bar_data_D1 [i][ 2 ]);
     if (Bar_data_D1 [i][ 2 ]>= 0 )
       {
         if ( Bar_data_D1 [i][ 2 ] < Low_D1_Level)
          {
           Min_D_Level = Bar_data_D1 [i][ 2 ]; break ;
          }
       }   
    } 
    
    
//--- Max_W_Level
 for ( int i = 1 ; i< ArrayRange (Bar_data_D1, 0 ) ;i++)
    {
     //Print(" i = ",i);
     if (Bar_data_D1 [i][ 3 ]>= 0 )
       {
         if (Bar_data_W1 [i][ 3 ] > High_W1_Level)    
          {
           Max_W_Level = Bar_data_W1 [i][ 3 ]; break ;
          }
       }  
    } 
    
//--- Min_W_Level 
 for ( int i = 1 ; i< ArrayRange (Bar_data_D1, 0 ) ;i++)
    {
     // Print(" i = ",i);
     if (Bar_data_D1 [i][ 2 ]>= 0 )
       {
         if (Bar_data_W1 [i][ 2 ] < Low_W1_Level)
          {
           Min_W_Level = Bar_data_W1 [i][ 2 ]; break ;
          }
       }  
    } 

 //+-----------------------High_D1_Level-----------------------------+  
 if ( ObjectFind ( "High_D1" )!=High_D1_Level) 
   {
     ObjectDelete ( "High_D1" );
     if ( ObjectFind ( "High_D1" )!= 0 )
      {
       ObjectCreate ( "High_D1" , OBJ_HLINE , 0 , Time[ 0 ],High_D1_Level);
       ObjectSet( "High_D1" , OBJPROP_COLOR , clrMaroon );
       ObjectSet( "High_D1" , OBJPROP_WIDTH , 1 );
      }
   } 
 if ( ObjectFind ( "High_D1_label" )!=High_D1_Level)
   {
     ObjectDelete ( "High_D1_label" ); 
     if ( ObjectFind ( "High_D1_label" ) != 0 )
      {
       ObjectCreate ( "High_D1_label" , OBJ_TEXT , 0 , Time[ 13 ], High_D1_Level);
       ObjectSetText( "High_D1_label" , "High_D1: " + DoubleToStr(High_D1_Level, _Digits ), 8 , "Verdana" , Brown);
      }
   } 
 //+-------------------------Low_D1_Level----------------------------+ 
 if ( ObjectFind ( "Low_D1" )!=Low_D1_Level) 
   {
     ObjectDelete ( "Low_D1" );
     if ( ObjectFind ( "Low_D1" )!= 0 )
      {
       ObjectCreate ( "Low_D1" , OBJ_HLINE , 0 , Time[ 0 ],Low_D1_Level);
       ObjectSet( "Low_D1" , OBJPROP_COLOR , clrMaroon );
       ObjectSet( "Low_D1" , OBJPROP_WIDTH , 1 );
      }
   } 
   
 if ( ObjectFind ( "Low_D1_label" )!=Low_D1_Level)
   {
     ObjectDelete ( "Low_D1_label" ); 
     if ( ObjectFind ( "Low_D1_label" ) != 0 )
      {
       ObjectCreate ( "Low_D1_label" , OBJ_TEXT , 0 , Time[ 13 ], Low_D1_Level);
       ObjectSetText( "Low_D1_label" , "Low_D1: " + DoubleToStr(Low_D1_Level, _Digits ), 8 , "Verdana" , Brown);
      }
   } 
   
     //+-----------------------Max_D_Level-----------------------------+  
 if ( ObjectFind ( "Max_D" )!=Max_D_Level) 
   {
     ObjectDelete ( "Max_D" );
     if ( ObjectFind ( "Max_D" )!= 0 )
      {
       ObjectCreate ( "Max_D" , OBJ_HLINE , 0 , Time[ 0 ],Max_D_Level);
       ObjectSet( "Max_D" , OBJPROP_COLOR , clrMaroon );
       ObjectSet( "Max_D" , OBJPROP_WIDTH , 1 );
      }
   } 
 if ( ObjectFind ( "Max_D_label" )!=Max_D_Level)
   {
     ObjectDelete ( "Max_D_label" ); 
     if ( ObjectFind ( "Max_D_label" ) != 0 )
      {
       ObjectCreate ( "Max_D_label" , OBJ_TEXT , 0 , Time[ 30 ], Max_D_Level);
       ObjectSetText( "Max_D_label" , "Max_D: " + DoubleToStr(Max_D_Level, _Digits ), 8 , "Verdana" , Brown);
      }
   } 
 //+-------------------------Min_D_Level----------------------------+ 
 if ( ObjectFind ( "Min_D" )!= Min_D_Level) 
   {
     ObjectDelete ( "Min_D" );
     if ( ObjectFind ( "Min_D" )!= 0 )
      {
       ObjectCreate ( "Min_D" , OBJ_HLINE , 0 , Time[ 0 ],Min_D_Level);
       ObjectSet( "Min_D" , OBJPROP_COLOR , clrMaroon );
       ObjectSet( "Min_D" , OBJPROP_WIDTH , 1 );
      }
   } 
   
 if ( ObjectFind ( "Min_D_label" )!=Min_D_Level)
   {
     ObjectDelete ( "Min_D_label" ); 
     if ( ObjectFind ( "Min_D_label" ) != 0 )
      {
       ObjectCreate ( "Min_D_label" , OBJ_TEXT , 0 , Time[ 30 ], Min_D_Level);
       ObjectSetText( "Min_D_label" , "Min_D: " + DoubleToStr(Min_D_Level, _Digits ), 8 , "Verdana" , Brown);
      }
   }  
 //+-----------------------High_W1_Level-----------------------------+         
 if ( ObjectFind ( "High_W1" )!=High_W1_Level) 
   {
     ObjectDelete ( "High_W1" );
     if ( ObjectFind ( "High_W1" )!= 0 )
      {
       ObjectCreate ( "High_W1" , OBJ_HLINE , 0 , Time[ 0 ],High_W1_Level);
       ObjectSet( "High_W1" , OBJPROP_COLOR , clrMaroon );
       ObjectSet( "High_W1" , OBJPROP_WIDTH , 1 );
      }
   } 
 if ( ObjectFind ( "High_W1_label" )!=High_W1_Level)
   {
     ObjectDelete ( "High_W1_label" ); 
     if ( ObjectFind ( "High_W1_label" ) != 0 )
      {
       ObjectCreate ( "High_W1_label" , OBJ_TEXT , 0 , Time[ 47 ], High_W1_Level);
       ObjectSetText( "High_W1_label" , "High_W1: " + DoubleToStr(High_W1_Level, _Digits ), 8 , "Verdana" , Brown);
      }
   } 
 //+-------------------------Low_W1_Level----------------------------+       
 if ( ObjectFind ( "Low_W1" )!=Low_W1_Level) 
   {
     ObjectDelete ( "Low_W1" );
     if ( ObjectFind ( "Low_W1" )!= 0 )
      {
       ObjectCreate ( "Low_W1" , OBJ_HLINE , 0 , Time[ 0 ],Low_W1_Level);
       ObjectSet( "Low_W1" , OBJPROP_COLOR , clrMaroon );
       ObjectSet( "Low_W1" , OBJPROP_WIDTH , 1 );
      }
   } 
   
 if ( ObjectFind ( "Low_W1_label" )!=Low_W1_Level)
   {
     ObjectDelete ( "Low_W1_label" ); 
     if ( ObjectFind ( "Low_W1_label" ) != 0 )
      {
       ObjectCreate ( "Low_W1_label" , OBJ_TEXT , 0 , Time[ 47 ], Low_W1_Level);
       ObjectSetText( "Low_W1_label" , "Low_W1: " + DoubleToStr(Low_W1_Level, _Digits ), 8 , "Verdana" , Brown);
      }
   }  
   
   
 //+-----------------------Max_W_Level-----------------------------+         
 if ( ObjectFind ( "Max_W" )!=Max_W_Level) 
   {
     ObjectDelete ( "Max_W" );
     if ( ObjectFind ( "Max_W" )!= 0 )
      {
       ObjectCreate ( "Max_W" , OBJ_HLINE , 0 , Time[ 0 ],Max_W_Level);
       ObjectSet( "Max_W" , OBJPROP_COLOR , clrMaroon );
       ObjectSet( "Max_W" , OBJPROP_WIDTH , 1 );
      }
   } 
 if ( ObjectFind ( "Max_W_label" )!= Max_W_Level)
   {
     ObjectDelete ( "Max_W_label" ); 
     if ( ObjectFind ( "Max_W_label" ) != 0 )
      {
       ObjectCreate ( "Max_W_label" , OBJ_TEXT , 0 , Time[ 64 ], Max_W_Level);
       ObjectSetText( "Max_W_label" , "Max_W: " + DoubleToStr(Max_W_Level, _Digits ), 8 , "Verdana" , Brown);
      }
   } 
 //+-------------------------Min_W_Level----------------------------+       
 if ( ObjectFind ( "Min_W" )!=Min_W_Level) 
   {
     ObjectDelete ( "Min_W" );
     if ( ObjectFind ( "Min_W" )!= 0 )
      {
       ObjectCreate ( "Min_W" , OBJ_HLINE , 0 , Time[ 0 ],Min_W_Level);
       ObjectSet( "Min_W" , OBJPROP_COLOR , clrMaroon );
       ObjectSet( "Min_W" , OBJPROP_WIDTH , 1 );
      }
   } 
   
 if ( ObjectFind ( "Min_W_label" )!= Min_W_Level)
   {
     ObjectDelete ( "Min_W_label" ); 
     if ( ObjectFind ( "Min_W_label" ) != 0 )
      {
       ObjectCreate ( "Min_W_label" , OBJ_TEXT , 0 , Time[ 64 ], Min_W_Level);
       ObjectSetText( "Min_W_label" , "Min_W: " + DoubleToStr(Min_W_Level, _Digits ), 8 , "Verdana" , Brown);
      }
   }
 //+-----------------------High_MN1_Level-----------------------------+         
 if ( ObjectFind ( "High_MN1" )!=High_MN1_Level) 
   {
     ObjectDelete ( "High_MN1" );
     if ( ObjectFind ( "High_MN1" )!= 0 )
      {
       ObjectCreate ( "High_MN1" , OBJ_HLINE , 0 , Time[ 0 ],High_MN1_Level);
       ObjectSet( "High_MN1" , OBJPROP_COLOR , clrMaroon );
       ObjectSet( "High_MN1" , OBJPROP_WIDTH , 1 );
      }
   } 
 if ( ObjectFind ( "High_MN1_label" )!=High_MN1_Level)
   {
     ObjectDelete ( "High_MN1_label" ); 
     if ( ObjectFind ( "High_MN1_label" ) != 0 )
      {
       ObjectCreate ( "High_MN1_label" , OBJ_TEXT , 0 , Time[ 81 ], High_MN1_Level);
       ObjectSetText( "High_MN1_label" , "High_MN1: " + DoubleToStr(High_MN1_Level, _Digits ), 8 , "Verdana" , Brown);
      }
   } 
 //+-------------------------Low_MN1_Level----------------------------+       
 if ( ObjectFind ( "Low_MN1" )!=Low_MN1_Level) 
   {
     ObjectDelete ( "Low_MN1" );
     if ( ObjectFind ( "Low_MN1" )!= 0 )
      {
       ObjectCreate ( "Low_MN1" , OBJ_HLINE , 0 , Time[ 0 ],Low_MN1_Level);
       ObjectSet( "Low_MN1" , OBJPROP_COLOR , clrMaroon );
       ObjectSet( "Low_MN1" , OBJPROP_WIDTH , 1 );
      }
   } 
   
 if ( ObjectFind ( "Low_MN1_label" )!=Low_MN1_Level)
   {
     ObjectDelete ( "Low_MN1_label" ); 
     if ( ObjectFind ( "Low_MN1_label" ) != 0 )
      {
       ObjectCreate ( "Low_MN1_label" , OBJ_TEXT , 0 , Time[ 81 ], Low_MN1_Level);
       ObjectSetText( "Low_MN1_label" , "Low_MN1: " + DoubleToStr(Low_MN1_Level, _Digits ), 8 , "Verdana" , Brown);
      }
   }       
}
 
Dark Kchlyzov:

Here's the function to debug.

OK, and can you tell me what you want to end up with?

 
Aleksei Stepanenko:

Ok, can you tell me what you want to end up with?

Here is the shortened version run on AUDUSD 2020

Why doesn't it go further in the array ?



//+------------------------------------------------------------------+
//|                                                   Test_Level.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
double   Bar_data_D1 [][6]; // Копирует в массив данные баров указанного графика и возвращает количество скопированных баров D1
double   Low_D1_Level;      // Возвращает значение минимальной цены бара  D1
double   Min_D_Level ;      // ближайшей минимальный  D уровень
datetime  Time_Day;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   Level();
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  On_Timer();
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                        Функция Level 
//+------------------------------------------------------------------+
void Level()
{
 ArrayCopyRates(Bar_data_D1,_Symbol,PERIOD_D1); // Копирует в массив данные баров указанного графика и возвращает количество скопированных баров

 Low_D1_Level   = iLow (_Symbol,PERIOD_D1,1);   // Возвращает значение минимальной цены бара  D1
    
//--- Min_D_Leve  
 //for(int i = 1; i<ArrayRange(Bar_data_D1,0) ;i++)
 for(int i = 1; ;i++)
    {
     Print(" i = ",i," Bar_data_D1 [i][2] = ",Bar_data_D1 [i][2]);
     if(Bar_data_D1 [i][2]>=0)
       {
        if( Bar_data_D1 [i][2] < Low_D1_Level)
          {
           Min_D_Level = Bar_data_D1 [i][2];break;
          }
       }   
    } 

 //+-------------------------Low_D1_Level----------------------------+ 
 if(ObjectFind("Low_D1")!=Low_D1_Level) 
   {
    ObjectDelete("Low_D1");
    if(ObjectFind("Low_D1")!=0)
      {
       ObjectCreate("Low_D1",OBJ_HLINE, 0, Time[0],Low_D1_Level);
       ObjectSet("Low_D1", OBJPROP_COLOR, clrMaroon);
       ObjectSet("Low_D1", OBJPROP_WIDTH, 1);
      }
   } 
   
 if(ObjectFind("Low_D1_label")!=Low_D1_Level)
   {
    ObjectDelete("Low_D1_label"); 
    if(ObjectFind("Low_D1_label") != 0)
      {
       ObjectCreate("Low_D1_label", OBJ_TEXT, 0, Time[13], Low_D1_Level);
       ObjectSetText("Low_D1_label", "Low_D1: " + DoubleToStr(Low_D1_Level,_Digits), 8,"Verdana", Brown);
      }
   } 
   
 //+-------------------------Min_D_Level----------------------------+ 
 if(ObjectFind("Min_D")!= Min_D_Level) 
   {
    ObjectDelete("Min_D");
    if(ObjectFind("Min_D")!=0)
      {
       ObjectCreate("Min_D",OBJ_HLINE, 0, Time[0],Min_D_Level);
       ObjectSet("Min_D", OBJPROP_COLOR, clrMaroon);
       ObjectSet("Min_D", OBJPROP_WIDTH, 1);
      }
   } 
   
 if(ObjectFind("Min_D_label")!=Min_D_Level)
   {
    ObjectDelete("Min_D_label"); 
    if(ObjectFind("Min_D_label") != 0)
      {
       ObjectCreate("Min_D_label", OBJ_TEXT, 0, Time[30], Min_D_Level);
       ObjectSetText("Min_D_label", "Min_D: " + DoubleToStr(Min_D_Level,_Digits), 8,"Verdana", Brown);
      }
   }  
 
}
//+------------------------------------------------------------------+
//|        функция удаление всех объектов созданных советником
//+------------------------------------------------------------------+
void DestroyObject()
{
 int tot=ObjectsTotal();
 for( int i=tot; i>=0; i--)
    {
     
     if(ObjectName(i)=="Low_MN1"){ObjectDelete(0,"Low_MN1");Print("<< Объект Low_MN удалён >>");}
     if(ObjectName(i)=="Low_MN1_label"){ObjectDelete(0,"Low_MN1_label");Print("<< Объект Low_MN1_label удалён >>");}
     

     if(ObjectName(i)=="Min_D"){ObjectDelete(0,"Min_D");Print("<< Объект Min_D удалён >>");}
     if(ObjectName(i)=="Min_D_label"){ObjectDelete(0,"Min_D_label");Print("<< Объект Min_D_label удалён >>");}


   }
}
//+-------------------------------------------------------------------------+   
//                         функция Timer                    
//+-------------------------------------------------------------------------+
void On_Timer()
{

     
 if(Day()!= Time_Day)
   {
    Level();
    Time_Day = Day();
   }
}
 

You're asking me why it doesn't work, and I'm trying to get the gist in words, because there might be a better solution to your problem, which is what I'm trying to find out.

Explain what you are trying to achieve.
 
Aleksei Stepanenko:

You ask me why it doesn't work, and I'm trying to get the gist in words, because there might be a better solution to your problem, which is what I'm trying to find out.

Explain what you want to get.

So far I see _so_

 
Vitaly Muzichenko:

So far I see _that_.

Yes, that's how human perception works. I, too, when I'm really passionate about an idea, I can barely hear the other person's arguments. Oh, well...

 
Vitaly Muzichenko:

So far I see _ so_.

There is a levelLow_D1_Level , then we need to get the value of the next level Min_D_Level, which will be the next lowest in the history and will be lower than Low_D1_Level.

I do not know how to explain further. If you run the code in the tester with the visualization in my opinion everything is visible.

And in general, if you come to the post, please be so kind as to at least read the essence.

That's completely beside the point:

What's the "XY problem"?

It's a mistake that often wastes the time of both the person asking for help and the people trying to answer it. It is also called the "Hammer Problem". In short, people tend to ask about their unsuccessful attempts to solve the problem, rather than about the problem itself. It ends up going something like this:

  • A person wants to do X.
  • He doesn't know how to do X, but guesses that doing Y might lead to success.
  • However, the person also doesn't know how to do Y.
  • At this point he decides to ask other people for help.
  • Everyone tries to help the person with problem Y, wondering because it is unclear why anyone would even need such a thing.
  • After a lot of questioning and a lot of wasted time, it finally becomes clear that the person really wanted to solve X, and that Y can't help him at all.
 
Vitaly Muzichenko:

So far I see _so_.

So I guess you still haven't found your X and Y !!!