[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 309

 
artmedia70:

That's right: it's good manners to tidy up your own rubbish...

But in this context, how can you tell if the "rubbish" needs to be cleaned up now or vice versa: it's not rubbish - it's the necessary data for further calculations.

As I understand it, deinit() should be used to clean up the trash, but... it is executed not only when chart of a trade instrument is deleted, when Expert Advisor is removed from it, but also when TF is changed. In this case, all of the accumulated data for the TF will be lost and the Expert Advisor will restart working with a zero array when it returns to the previous timeframe. The same will happen if we change any of parameters of the Expert Advisor.

It turns out that in some situations "rubbish collection" is a complex logical process, not a simple change of the array size.


Well, it's not complicated. In the loop, initialize the array with values. Then we work with the resulting array. When the work is done, we make it zero in length. If in doubt, you may do it at the end of the code just before return(0).
 

Please suggest the code below to read the log file. Automatically reads the current log file by date and outputs it to the printer.

Where:

while (result>0) {

The file is being assembled from parts. But I don't need the whole file, just the last line. Help to correct, please.

void ReadWrite() {
   string tekTime=TimeStr1(CurTime(),1);
   string path=TerminalPath()+"\\logs\\"+tekTime+".log";
   string title="Чтение из файла";
   string msg;
   int result;
   int handle=_lopen(path,4);
   if (handle<0) {
      msg="Ошибка открытия файла";
      //MessageBox(msg,title,MB_OK|MB_ICONERROR);
      Print(msg);
      return;
   }
   result=_llseek (handle,0,0);
   string buffer="";
   //string char="x                      ";
   string char="x                                                                                                                                                                                                                                                         ";
   int count=0;
   result=_lread (handle,char,250);
   while (result>0) {
      buffer=buffer+char;
      char="x                                                                                                                                                                                                                                                         ";
      count++;
      result=_lread (handle,char,250);
   }
   result=_lclose (handle);
   msg=StringTrimRight(buffer);
   //MessageBox(msg,title,MB_OK|MB_ICONINFORMATION);
   Print(msg);
}

//------------------расчет времени----------------
string TimeStr1(int taim,int tip)
{
   string sTaim;
   string sTaim1,sTaim2,sTaim3;
   if (tip==1) 
   {
      int GD=TimeYear(taim);                  
      int MN=TimeMonth(taim);                  
      int DD=TimeDay(taim);  
      
      sTaim1 = DoubleToStr(GD,0);
      if (MN<10) sTaim2 = StringConcatenate(sTaim2,"0"+DoubleToStr(MN,0));
      else sTaim2 = StringConcatenate(sTaim2,DoubleToStr(MN,0));
      if (DD<10) sTaim3 = StringConcatenate("0",DoubleToStr(DD,0));
      else sTaim3 = DoubleToStr(DD,0);
      sTaim=sTaim1+sTaim2+sTaim3;
   }
   return(sTaim);
}
 
drknn:

Well, it is not difficult. In the loop, the array is initialized with values. Then we worked with the resulting array. When the work is over, we make it a zero-length array. If in doubt, you may do it at the end of the code just before return(0).

I was misunderstood.

In the context of the conversation (if I understood the premise of this conversation correctly), the loop is the EA itself. After all, every time a tick comes, the array either increases or stays the same depending on whether a new value needs to be written to it.

How can we know that the work is finished, and not just a person, for example, changes the timeframe? Even by accident... In this case, deinit() will be called and all data will be lost. The Expert Advisor will start to store (write in a dynamic array) them anew, based on the values obtained in the new timeframe(a new cycle).

I mean it.

 
artmedia70:

I wasn't understood.

In the context of our discussion (if I understood the premise of this discussion correctly), the cycle is the work of the Expert Advisor itself. After all, every time a tick comes the array is either increased or remains unchanged, depending on whether a new value needs to be written to it.

How can you tell if a job is finished and not just a person changing timeframes, for example? Even by accident... In this case, deinit() will be called and all data will be lost. The Expert Advisor will start to accumulate them (write them into a dynamic array) anew, based on the values obtained in the new timeframe(a new cycle).

My point is this.

If you go into details, you can use this function. It will tell you what the reason for deinitialisation is.
 

I have noticed one specific feature of the terminal. Since the order profit calculation does not consider the OrderSwap(), I want it to close the order at once.


It means we should use this formula to close the order with a profit:

(OrderProfit()+OrderSwap()+OrderCommission())>0

I've never worked with commission and commission is not used on demo, that's why I can't check it on account.

Are my calculations correct?

 
Zhunko:
If you go into details, you can use this function. It will tell you the reason for deinitialisation.

Quite right... :)

Forgot about it. Now, with my habit of using "foolproof", we'll use it...

 
artmedia70:

ObjectGetValueByShift() to help you

And how you're going to work with it - only you know...


Thank you, kind man!
 
Two questions.

1. How do I write/enter the first and subsequent variables double abc[10] in the array double ab=a*b?
2. How to write the eleventh variable into an array, removing the first one?

The order in which the variables are written in the array (forward or backward) does not matter. The variables in the array are needed to determine the arithmetic mean.
 
Can I change the lot size of a pending order?
 
Parn25:
Can I change the lot size of a pending order?


No, you can't.

everything you can change is explained here https://docs.mql4.com/ru/trading/OrderModify

Reason: