Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1436

 
Yuriy Bykov #:

Then it seems that this is the case. Apparently, during genetic optimisation, the parameters responsible for turning oscillators on/off are strongly dominant with respect to oscillator parameters. That is, when breeding the next generation, one parent that has the gene for the switched off oscillator will kill a bunch of offspring from other parents with the switched on gene for this oscillator. That is, these descendants will be discarded by the condition of incorrect parameters, will not give offspring, and evolution will quickly come to a deadlock.
Try to look at the behaviour of the tester at full optimization on a short interval of the testing period. Will there be unnecessary omissions of combinations in this case?


Yes, the problem is in the combination: genetic algorithm + blocking of certain combinations. With full optimisation everything works correctly, but full optimisation will take an unrealistically long time.

I was hoping that I could somehow show the optimiser that such variants are unacceptable and that he should not even try to use them and focus on other variants. In fact, it happens as you wrote.

 
Alexey Petrov #:

You can create a freelance job and choose from among the developers who apply for your job

https://www.mql5.com/fr/job

Thank you, I've posted my ad and I hope I can finally find a solution :)
 

Hello!


How does the code that allows the Expert Advisor to trade at certain hours look like in MQL5? I can't port it from MQL4.


void OnTick()

{

double PriceBid=MarketInfo(0,MODE_BID);

double time = Hour() + Minute()*0.01;

Comment("datum ",inpoint,

"\n", "step ",iter,

"n", "time ",time,

"n," "price," Bid,

"\n", "price", PriceBid);

if(time <= Stop_work_time)

{

//if(Type==BUY || Type==ALL)newbuyorder();

//if(Type==SELL || Type==ALL)newsellorder();

in();

takestop();

stoporders();

connected();

delorders();

}

else

{

takestop();

delorders();

}

}

Files:
kachinmind.mq4  38 kb
 
EfremovSergey allows an Expert Advisor to trade at certain hours look like in MQL5? I can't port it from MQL4.


void OnTick()

{

double PriceBid=MarketInfo(0,MODE_BID);

double time = Hour() + Minute()*0.01;

Comment("datum ",inpoint,

"{n", "step ",iter,

"n", "time",time,

"n," "price," Bid,

"\n", "price", PriceBid);

if(time <= Stop_work_time)

{

//if(Type==BUY || Type==ALL)newbuyorder();

//if(Type==SELL || Type==ALL)newsellorder();

in();

takestop();

stoporders();

connected();

delorders();

}

else

{

takestop();

delorders();

}

}

The implementation of this task in mq5 can be repeated using

MqlDateTime
 

Good morning and good mood everyone!

Dear experts!!! Could you please tell me what is wrong in this code (the part where the error appears periodically is highlighted in yellow)?

//+------------------------------------------------------------------+
//|                                            Proba (version_1).mq5 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//--- Global variables
MqlRates pArray[];
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   ArraySetAsSeries(pArray,true);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(!DownwardTrendline())
     {
      Print("Ошибка при создании линии DownwardTrendline!!! ", GetLastError());
      return;
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool DownwardTrendline()
  {
   int candles=(int)ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR,0);
   double pHigh[];
   ArraySetAsSeries(pHigh,true);
   CopyHigh(_Symbol,_Period,0,candles,pHigh);
   int candleHigh = ArrayMaximum(pHigh,0,candles);
   int Data = CopyRates(_Symbol,_Period,0,candles,pArray);
   ObjectDelete(0,"DnwardTrendline");
   ObjectCreate(0,"DnwardTrendline",OBJ_TREND,0,pArray[candleHigh].time,
                pArray[candleHigh].high,pArray[0].time,pArray[0].high);
   ObjectSetInteger(0,"DnwardTrendline",OBJPROP_COLOR,Blue);
   ObjectSetInteger(0,"DnwardTrendline",OBJPROP_STYLE,STYLE_SOLID);
   ObjectSetInteger(0,"DnwardTrendline",OBJPROP_WIDTH,3);
   ObjectSetInteger(0,"DnwardTrendline",OBJPROP_RAY_RIGHT,true);
   return(true);
  }
//+------------------------------------------------------------------+

Why periodically, then works in the strategy tester, then does not work and in the log appears this message:


Regards, Vladimir.

 
MrBrooklin #:

Good morning and good mood, everyone!

Dear experts!!! Please tell me what is wrong in this code (the part of the code where the error appears periodically is highlighted in yellow):

Why periodically, then works in the strategy tester, then does not work and in the log appears this message:


Regards, Vladimir.

Put a check after the line

   int Data = CopyRates(_Symbol,_Period,0,candles,pArray);

if Data < 1 something, somehow shout.

 
Alexey Viktorov #:

Put a check after the line

if Data < 1 something, shout out somehow.

Good morning Alexey, thanks for the hint! I will try it now.

Regards, Vladimir.

 

Instead of:

   int Data = CopyRates(_Symbol,_Period,0,candles,pArray);

I put it in:

   if(CopyRates(_Symbol,_Period,0,candles,pArray)==-1)
     {
      Print("Ошибка копирования исторических данных в массив pArray[]!!!", GetLastError());
      return(false);
     }

and everything worked. It draws theline steadily and as it should, but only now at each new start of the Expert Advisor in the strategy tester messages appear periodically:

2023.01.20 11:23:37.064 2022.01.03 03:21:49   Ошибка копирования исторических данных в массив pArray[]!!!4003
2023.01.20 11:23:37.064 2022.01.03 03:21:49   Ошибка при создании линии DownwardTrendline!!! 4003

Will this, then will somehow negatively affect the code or can I "forget" about it?

Regards, Vladimir.

 
MrBrooklin strategy tester:

Will this, then, somehow negatively affect the code or can I "forget" about it?

Regards, Vladimir.

What prevents you from doing this

bool .....()
{
if(Data>0)
{
..................
................

return true;
}
return false;
}
 
Vladimir Deryagin #:

What's stopping you from doing this

Hello, Vladimir! It's age. Brains are not as flexible and fast as young ones. )))

Thank you for your option.

Regards, Vladimir.

P.S. Fixed. Everything works perfectly!!! Once again, thank you all very much for your help!
Reason: