[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 749

 
artmedia70:
Wise developers. If it were possible to call a script, I would charge a slip in it, but you can't either, apparently, because there's no need for a bunch of advisors at once... There's no easy way out for us :)
 

Gentlemen programmers. Could you please help me.

From the input variables.

extern bool UseHourTrade = True;
extern int FromHourTrade = 0;
extern int ToHourTrade = 23;

int start(){
if (UseHourTrade){
if (!(Hour()>=FromHourTrade && Hour()<=ToHourTrade)) {
Comment("Time for trade has not arrived yet!");
return(0);
}
}

I want to add second time period when trade should be done with other variables UseHourTrade2, FromHourTrade2, ToHourTrade2.

Please help. please tell me what should be added to start function. I have tried so many things that do not work.

I want to thank you in advance. I cannot help.

 
cyclik33:
extern bool UseHourTrade = True,
            UseHourTrade2 = True;
 extern int FromHourTrade = 0,
            FromHourTrade2 = 0,
            ToHourTrade = 23,
            FromHourTrade2 = 23;

int start(){
   if (UseHourTrade){
   if (!(Hour()>=FromHourTrade && Hour()<=ToHourTrade)) {
 Comment("Time for trade has not come else!");
 return(0);
 }
   if (UseHourTrade2){
   if (!(Hour()>=FromHourTrade && Hour()<=FromHourTrade2)) {
 Comment("Time for trade has not come else!");
 return(0);
 }
 }

Something like that, I guess.

SZY The code insertion button "SRC" is awkward to use, it's not easy to read.

 
Abzasc:

The conundrum is this.

The indicator at the very end of the code creates an object, which serves as a flag for another indicator.

After creating the object, I need to "sleep" the indicator for 5 seconds, then delete the object and sleep it for 60 seconds, after which it will go to the last retry and start over from the beginning with a new tick.

Trying to do this

It hangs until it seems to run out of time.

Any tips on how to do this?


The logic is this - both indicators know the name of the object and one additional object

the first one creates the object and does nothing while it's there - at the very beginning of the start we write the exit condition (return;)

the second one reads the object, does its business and sets an additional object

the first one, without seeing the main object, leaves doing nothing and immediately finds the second (additional object), reads the time of object creation (it is entered there by the second component in the description when creating), counts down the required pause (60 seconds) and deletes all objects - you may continue working ....

 
Abzasc:
It does not work in indicators. I do not understand the reason of doing it this way. Apparently, a constantly working indicator must be hypnotizing :)

The reason is that the indicator works in the interface flow, you cannot put it to sleep, because if you could "slow it down", at that moment you could not press any button in the terminal, for example "New order", or close an order, etc.
One more subtlety in this topic concerns the tester. In the real terminal, there are several threads, one interface thread is created separately for Expert Advisors (that is why it can be slowed down without consequences) and in the tester, it is the same for all, and all for one :)
That is why the Sleep() function works in such a specific way in test mode. If you put the tester's flow to sleep, then everything will stop working, including Expert Advisors, indicators, and tick generation, of course. Therefore, if I have understood your idea correctly, it can be tested only on a demo. If you want to slow down the interface flow, you may use the following function:

//+------------------------------------------------------------------+
//| MySleep function                                                 |
//+------------------------------------------------------------------+
void MySleep(int sec){
   int pause = TimeSeconds(TimeLocal()) + sec;
   if(pause >= 60)pause = pause - 60;
   while(TimeSeconds(TimeLocal()) != pause){}
}
//+------------------------------------------------------------------+
 
xrust:


counts down the desired pause (60 sec)

You can try it, but the important thing is how to pause... I'm stuck on this one.
 

Read carefully, I have explained everything, and it is not necessary to use a graph object at all, you can do with globals....

 
ToLik_SRGV:

The reason is that the indicator works in the interface stream, it cannot be put to sleep...

There you go... it's brightened up now, thank you.


Man, what rocks. Can't put it in one indicator, can't put it to sleep... I'll try to do it with global variables.
 
xrust:

Read carefully, I have explained everything, and it is not necessary to use a graph object at all, you can do with globals....

I think I got it. Deletion by time of existence is also a timer. But I will reread it once again:)
 
Abzasc:

... I'll try to make it work with global variables.

I think Rustam hinted about it correctly, because thread freezing is the last thing you should do, it's an extreme measure, and not only in MQL, but in all programming languages.