[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 209

 
polycomp:
These are the functions, and the objects are the rectangles that appear on the graph.

Files:
 
polycomp:


Files:
 
We'll have to see, it will take time.
 
polycomp:
One of the possible reasons of code working differently after re-initialisation is the peculiarity of static variables initialisation in MT4. In isNewBar() function you use such variable. During primary initialization BarTime = 0. And at further reinitialization this variable will contain previous value (not 0). To check this assumption, make BarTime variable global and check how the code works.
 
polycomp:
alsu:

First, print something out of the library functions in Print, so that you know if they are called at all

Graphical objects are created in library functions . After the first call to the indicator, the objects are created and displayed in the terminal window.

When you call them again they are not present in the list of objects, which suggests that the external functions are not working when re-calculating the indicator for some reason, and the terminal is silent about it.

Ok. Instead of indirect signs, print ( " call of this function") in the indicator; we will see at once if this function is called.

You should be less arrogant, then the errors will be found faster)

 
polycomp:



In general, your problem is most likely in the function

bool isNewBar()
{
  static datetime BarTime;  
   bool res=false;
    
   if (BarTime!=Time[0]) 
      {
         BarTime=Time[0];  
         res=true;
      } 
   return(res);
}

The thing is, the statics isn't reset during reinitialization, so when you restart, your BarTime is always equal to the time of the last bar counted last time, i.e. isNewBar () is false until a new candle arrives. It would be better to move the function from the library to the mqh inluder and zeroize BarTime=0 explicitly in init ().

This is just a first glance at the code, so do not judge too severely if I am wrong.

 
polycomp:



I would start by removing this line from your library

#property library

Since you are not using a library, but an include file

 
alsu:

As far as I remember, you have to specifically remember this time when you set the pending order. You can memorise it directly in the comment to the order (or in magik, as a special perversion:).
Thank you very much.
 

QUESTION 1.

How to code this idea.

To set a pending order but make it convert to a market order only if the pending order set price coincides with the opening price of any TF60 candle

QUESTION 2.

How to code this idea.

If a pending order is converted into a market order, in 10 min we should set another pending order with the same values: open price, stop price, volume as in the previous pending order which was converted into a market order.

Thank you.

 
alsu:

Ok. Maybe, instead of judging by indirect signs, just type in the indicator itself: Print ("call of such and such function"); we'll see at once if it is called or not.

You should be less overconfident then the errors will be found faster).

alsu:

And in general your problem is most likely in the function

The thing is that the statics is not zeroed when reinitializing, so on restarting the BarTime is always equal to the time of the last bar counted last time, i.e. isNewBar () will be false until a new candle arrives. It would be better to move the function from the library to the mqh inluder and zeroize BarTime=0 explicitly in init ().

This is just a first glance at the code, so do not judge too severely if I am wrong.


Thank you very much!

Removed isNewBar () from library and put in indicator file. Everything works like clockwork!