Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1935

 

What is wrong, with 2 parameters VLine in the tester gives error 2022.03.24 18:24:27.615 TestGenerator: unmatched data error (volume limit 263 at 2022.03.18 14:30 exceeded)

If the first parameter time1 is removed, everything is fine.

bool FlagOpOr=false;
bool FlagClOr=false;
bool Work=true;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

   
//---
   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[])
  {

//---
     static bool FlagNDay=true, FlagVLRed=false,FlagVLBlue=false;
  static datetime Data = 0, NData=0;
  Data = Day();
 if(NData!=Data){FlagVLRed=true; FlagVLBlue=true;NData=Data;} 
if(FlagVLRed==true && Hour()==0){ VLine(1,clrRed); FlagVLRed=false;}
if(FlagVLBlue==true &&  Hour()==1){ VLine(1,clrBlue); FlagVLBlue=false;  }
      
    
  
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+

void OnDeinit(const int reason)//int deinit(void)void
  {
   int i;
   int obj_total=ObjectsTotal();
   for(i=obj_total-1;i>=0;i--)
     {
 string     sn=ObjectName(i);
      string Head=StringSubstr(sn,0,4);// Извлекаем первые 4 сим
      if(Head == "VLin")
        {
          ObjectDelete(sn);       

       }
     }
   
    Comment("");
   return;
  }
 
  //+------------------------------------------------------------------+
  bool VLine( int time1=0, color clr = clrRed ){
  string  var1=TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS);
     string NameLine="VLine_" +  "_"+var1;
            bool   created=ObjectCreate(0,NameLine,OBJ_VLINE,0,TimeCurrent(),0);
            if(created)// если создался - сделаем ему тюнинг
              {              
               //--- точка привязки сверху, чтобы не наезжать на бар
               ObjectSetInteger(0,NameLine,OBJPROP_STYLE,STYLE_SOLID);
               //--- последний штрих - покрасим
               ObjectSetInteger(0,NameLine,OBJPROP_COLOR,clr);
               //--- установим толщину линии 
               ObjectSetInteger(0,NameLine,OBJPROP_WIDTH,2); 
                
              }
              else return(false );time1=0;
              return(true);
              }
 

Good afternoon to all. I have 20-40 charts open during trading. I have to spend a lot of time to find the right one at the bottom of all the instruments or in the top menu item "window". If I could use a script to accelerate it, I put a script in the input parameters, type the necessary symbol and it will open as if it was found with my eyes and clicked. How to implement such a thing?

 
DanilaMactep #:

Good afternoon to all. I have 20-40 charts open during trading. I have to spend a lot of time to find the right one at the bottom of all the instruments or in the top menu item "window". If I could use a script to accelerate it, I put a script in the input parameters, type the necessary symbol and it will open as if it was found with my eyes and clicked. How can this be done?

As logic, the script should find out how many charts/windows are open and for which instruments, remember them (symbols and chart_idies) and then, according to the number of instruments, draw a panel with buttons with the instrument name written on them. On pressing the button, the chart with the required instrument changes its property to expanded (it can be collapsed) and over all, and the script closes.

 
Valeriy Yastremskiy #:

Logically, the script should find out how many charts/windows are open and for which instruments, remember them (symbols and chart_idies), then, according to the number of instruments, draw a panel with buttons with the instrument name written on them. On pressing the button, the chart with the desired instrument changes its property to expanded (it can be collapsed) and over all, and the script closes.

Bad logic - what difference does it make - in which buttons to look - at the bottom, in the menu window or in the buttons drawn by the script? Must somehow be done so that when you enter the desired symbol in the input parameters, and the script has opened this window for you - so it would be easier and faster. Does anyone have such a miracle, please share?
 

Hello!

I am looking for an EA, a grid operator.

Opens market orders in a grid.

Closes the orders when the grid reaches a certain (%) profit.

I have seen such an Expert Advisor, and now I can not find it.

I have seen such an Expert Advisor, and now I cannot find it.

 
DanilaMactep #:
Bad logic - what difference does it make in which buttons to look - at the bottom, in the menu window or in the buttons drawn by the script? Must somehow be done so, that entered the desired symbol in the input parameters, and the script has opened this window for you - so easier and faster would be. Does anyone have such a miracle, please share?
Open a new window (opens without EA and with default template) or raise or expand an already open window.
Look at the attached code, there's a chart enumeration and drawing on the chart by condition. Maybe it will help.
 
I can't figure out what's wrong. There is a while loop in the indicator, but it seems to work fine. At first during testing everything works, but in one and the same place the program hangs, the terminal, too, I have to delete the source code from the terminal. On other currencies it hangs too. I put comments all around the program and it eventually reachesComment(rates_total+"\n "+prev_calculated); before return and stops. And the comment shows we got numbers like 3247 and 3247, which means that the condition to work (rates_total>prev_calculated) is not fulfilled and the program must not do anything. Why does it hang?
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[])
  {
   if(rates_total>prev_calculated)
     { 
         Comment("0");
          if(Count==0)
             total = rates_total-4;
          else
             total = rates_total - prev_calculated+2;

          if(total>10000)
             total=10000;

          for(int i=total; i>2; i--)
            {
            }
       
          while(begin<size-2)
            {
            }
      Count++;
     }  
     Comment(rates_total+"\n"+prev_calculated);          //виснет здесь(коммент 3247 и 3247)
   return(rates_total);
  }
 
Aleksandr Kononov Comment(rates_total+"\n "+prev_calculated); before return and stops. And the comment shows we got numbers like 3247 and 3247, which means that the condition to work (rates_total>prev_calculated) is not fulfilled and the program must not do anything. Why does it hang?

Read the documentation carefully.

If the expression is true, the operator is executed until the expression becomes false.
What are the variables in the loop condition? And if the initial condition is true, when does it become false to exit the loop?
Оператор цикла while - Операторы - Основы языка - Справочник MQL4
Оператор цикла while - Операторы - Основы языка - Справочник MQL4
  • docs.mql4.com
Оператор цикла while - Операторы - Основы языка - Справочник MQL4
 
Alexey Viktorov #:

Read the documentation carefully.

What are these variables in loop condition? And if the initial condition is true, when does it become false to exit the loop?

The loops are just for understanding what they are. You will get a lot of code there if you write them. The question is why the work stops before return, although nothing even happens on this tick. In the comment rates total equals prev calculated, so we do nothing at all.

 
The indicator works if anything, but hangs on some conditions
Reason: