Questions from a "dummy" - page 147

 
alph:

If price closes below the moving average and Momentum is below the average, open a sell trade. On a buy trade, it is the other way round.

It turns out that if the condition is not fulfilled, then no action is needed. If so, then in the last line of the function write return(false) and see if it will satisfy your tactic step by step.
 
Yedelkin:
So, if the condition is not met, you don't need to do anything? If so, then in the last line of the function write return(false) and see if it will satisfy your tactic step by step.
Is it in void OnTick() ?
 
alph:
Is it in void OnTick() ?

It was about timeOntrade apparently.

But I'm personally confused by the non-returnable result, which can be converted to the desired form sooner or later.

What confuses me is this

bool timeOntrade(int TradeHour)
   {
   MqlDateTime timeOntrade;
 
alph:
Is this in void OnTick() ?

Right here:

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(false);
   }

Try putting false on the last line and see if this approach is consistent with the tactic you have chosen. I.e., "scroll" the Expert Advisor's work with this change in mind.

 
Interesting:
I was talking about timeOntrade apparently.
In timontrade just false at the end will not give the desired result, but in my variant it really opens deals by the clock, tested. My version of code with clock in this form I got somewhere here on forum, it works after screwing it in. Only the minutes I managed to screw in via timontrade two. I'm sure the full code should be a third shorter at least.
 
alph:
In timeOntrade just false at the end will not give the desired result, but in my variant opens trades by the hour is real, tested.
What happens if timeOntrade.hour = 5?
 
Interesting:
What happens if timeOntrade.hour = 5?

The deal certainly won't be done, because in...

//Basis 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();//

...send to open only at specified time

Документация по MQL5: Стандартные константы, перечисления и структуры / Структуры данных / Структура исторических данных
Документация по MQL5: Стандартные константы, перечисления и структуры / Структуры данных / Структура исторических данных
  • www.mql5.com
Стандартные константы, перечисления и структуры / Структуры данных / Структура исторических данных - Документация по MQL5
 
alph:
In timontrade, it's exactly false at the end that won't produce the desired result...
Well look at your code yourself. The condition if(timeOntrade.hour==4 || timeOntrade.hour==15 || timeOntrade.hour==16) is useless in its current form. Because no matter what result it produces, your bool timeOntrade() function will always return true.
 

alph, this is what Yedelkin is talking about.

These variants of the function are identical in our mind

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);
   timeOntrade.hour= 0;
   timeOntrade.min = 0;
   timeOntrade.sec = 1;
   return(true);
   }
 
Interesting:

By the way, in this variant the tester's result by profit is small, but the ratio seems to me to be good.

Now I am testing on larger timeframes without time reference, maybe the result will be better.

Reason: