Questions from a "dummy" - page 148

 
Yedelkin:
Well look at your code yourself. The condition if(timeOntrade.hour==4 || timeOntrade.hour==15 || timeOntrade.hour==16) is useless in its present form. Because no matter what result it produces, your bool function timeOntrade() will always return true.
It sounds logical. That's what I'm interested in. I think I wrote unnecessary unnecessary things and may have missed the necessary thing.
 
Interesting:

alph, this is what Yedelkin is talking about.

These variants of the function are identical in our mind

I see now.
 
alph:
Sounds logical, that's why I'm interested. It seems to me that I wrote unnecessary unnecessary things and may have missed the necessary ones.


There is one more thing that is not clear to me yet

   timeOntrade.hour= 0;
   timeOntrade.min = 0;
   timeOntrade.sec = 1;
   if(timeOntrade.hour==4 || timeOntrade.hour==15 || timeOntrade.hour==16) return(true);

That is, if I understand correctly, we first assign the clock to 0 and then compare it.

Where is the logic?
 
Interesting:


One more point, which is not yet clear to me

That is, if I understand correctly, we first assign the clock to 0 and then compare it.

Where is the logic?
I have not yet removed the line with true, but it seems to me, if you remove it, already in ontik there will be no comparison with clock as a specific value or parameter.
 
alph:
I haven't removed the line with true yet, but it seems to me, if we remove it, there will be no comparison with clock as a specific value or parameter in ontik.

At the moment these options are identical in my opinion

bool timeOntrade(int TradeHour)
   {
   MqlDateTime timeOntrade;
   TimeTradeServer(timeOntrade);
   if(timeOntrade.hour!=TradeHour) return(false);
   timeOntrade.hour= 0;
   timeOntrade.min = 0;
   timeOntrade.sec = 1;
   if(timeOntrade.hour==4 || timeOntrade.hour==15 || timeOntrade.hour==16) return(true);
   return(true);
   }

bool timeOntrade(int TradeHour)
   {
   MqlDateTime timeOntrade;
   TimeTradeServer(timeOntrade);
   if(timeOntrade.hour!=TradeHour) return(false);
   return(true);
   }

In general, I don't understand why values need to be assigned.

That is, as far as I understand, the best option is

bool timeOntrade(int TradeHour)
   {
   MqlDateTime timetrade;
   TimeTradeServer(timetrade);
   if(timetrade.hour!=TradeHour) return(false);
   return(true);
   }
In this case, if the current server time (only for clock) is not equal to the set one, then it returns false, otherwise it returns true.
 
Interesting:

At the moment these options are identical

I actually don't understand why we need to assign values?

To write this:

void OnTick()

{...

//-----------------------------------------------------------------------------------------+

//Base for switching to Open

MqlRates rt[1];

if(CopyRates(Symbol(),MyTframe,0,1,rt)<0) return;

if(rt[0].tick_volume>1) return;

if(!PositionSelect(_Symbol) && (timeOntrade(4) || ((timeOntrade(15) || timeOntrade(16))&& timeOntrade2(0)))) Open();//go to position opening

timeOntrade.min = 0;

This is clearly unnecessary in this context


   timeOntrade.min = 0;
   timeOntrade.sec = 1;
 

alph:

To put this in:

void OnTick()

Try this option. If not then I don't understand what you're trying to get...

bool timeOntrade(int TradeHour)
   {
   MqlDateTime timetrade;
   TimeTradeServer(timetrade);
   if(timetrade.hour!=TradeHour) return(false);
   return(true);
   }
 
Interesting:

Try this option. If not then I don't understand what you're trying to get...

Yes, yes, and in:

 bool timeOntrade2(int TradeMin)  
   {
   MqlDateTime timetrade2;
   TimeTradeServer(timetrade);
   if(timetrade.min!=TradeMin) return(false);
   return(true);
   }
 
alph:

Yes, yes, and in:

Then already so (to be sure). But, in principle, you got me right

 bool timeOntrade2(int TradeMin)  
   {
   MqlDateTime timetrade;
   TimeTradeServer(timetrade);
   if(timetrade.min!=TradeMin) return(false);
   return(true);
   }
 
Interesting:

Then it's like this (to be sure). But, in principle, you got me right

Thank you! Is the rest of the code correct?