The problem of transferring from MT4 to MT5. Or, more precisely, the inability to execute some algorithms in MT5 without'err. - page 9

 
Vict:

Yes, code with exceptions is much simpler and cleaner, constant error checking turns it into a mess. But there are a lot of problems in µl without exceptions. The developers didn't pull the crosses.

In my opinion, there is no difference.

With return codes - you need to write a macro like RETURN_IF_BAD_RESULT() and stick it in all functions that return results.

With exceptions - you need to write TRY-CACTH sections. Plus you have to remember which functions throw exception and which don't, add comments // exception to your code.

Something is a piece of cake, something is...

 
Vict:

Yes, code with exceptions is much simpler and cleaner, constant check of errors turns it into a tangled mess. But there are a lot of problems in µl without exceptions. The developers couldn't pull the crosses.

No, I'm not even talking about exceptions... alternatively, there might be an "evil cobbler"... who will turn all the trips outside the array into exceptions ))))

imho, you just need a way to break all of return with exit into OS... let it be some Exit(), you got the idea right, I don't want to multiply endless code spools - there's no sense to always wrap all function calls in

void OnStart()
{
if(!MyFuncReadOHLC_1()) return;
if(!MyFuncReadOHLC_2()) return;
....
}
 
Georgiy Merts:

In my opinion, there is no difference.

With return codes - you need to write a macro like RETURN_IF_BAD_RESULT() and stick it in all functions that return results.

With exceptions - you need to write TRY-CACTH sections. Plus - remember which functions throw an exception and which don't, add comments // exception to your code.

Something's a mess, something's a mess...

With exceptions I do not need to remember anything, often even TRY-CACTH is not needed (just will terminate the program crash), it is an EXCLUSIVE situation and normally does not happen, do not turn them into if-else blocks. For example - I wrote a vector-like (pathetic-like), instead of throwing exception on unsuccessful allocations I had to screw operator! and yank it at every insertion (although I'm forgetting about it), dubious benefit.

 
Igor Makanu:

imho, you just need to be able to break it all off with the OS...

Yeah, that's OK too, strange that it's not there ...

 
Vict:

Yes, nothing too, strange that it is not present ...

I just don't feel comfortable turning short programmes with readable code into some kind of monster, here is a typical template for MQL4 - check the "new bar", check indicators - work or not work with orders:

void OnTick()
  {
   int takeprofit,stoploss; 
   double lot;
   ENUM_CMD CMD1,CMD2,CMD3;
   CMD1 = ind1();
   CMD2 = ind2();
   CMD3 = ind3();
   if(NewBar())
     {
      DeleteOrdersLimits(Magic);
      if(CMD1==CMD_BUY && CMD2==CMD_BUY && CMD3==CMD_BUY)
        {
         CalcTakeProfitStopLoss(takeprofit,stoploss);
         lot=CalcLot(stoploss);
         if(ReversSignal)SELL_STOP_PR(Low[1],lot,Magic,stoploss,takeprofit); else BUY_STOP_PR(High[1],lot,Magic,stoploss,takeprofit);
        }
      if(CMD1==CMD_SELL && CMD2==CMD_SELL && CMD3==CMD_SELL)
        {
         CalcTakeProfitStopLoss(takeprofit,stoploss);
         lot=CalcLot(stoploss);
         if(ReversSignal)BUY_STOP_PR(High[1],lot,Magic,stoploss,takeprofit);else SELL_STOP_PR(Low[1],lot,Magic,stoploss,takeprofit);
        }
     }
  }
//+------------------------------------------------------------------+

in this example, the indicators "pull every tick" as they work on different TFs... it does not really matter.

I use OHLC data inind1(),ind2(),ind3() and inNewBar()

if i get a timeseries access error in one function call, what's the point of continuing to execute this code? - I need to exit to OS and wait for a new tick, i.e. in anyind1(),ind2(),ind3() and inNewBar() I check GetLastError() and on receiving an error immediately Exit() in OS with writing in EA log

 
Vict:

With exceptions I don't have to remember anything, often even TRY-CACTH is not needed (the program will simply terminate in an emergency), it is an EXCLUSIVE situation and doesn't happen normally, don't turn them into if-else blocks. For example - I wrote a vector-like (pathetic-like), instead of throwing exception on unsuccessful allocations I had to screw operator! and yank it at every insertion (although I'm forgetting about it), dubious benefit.

Well, come on, mate...

You say, "you don't need to remember anything", and then you continue: Often even TRY-CATCH is not needed. This same "often" means that somewhere block is needed and somewhere is not needed, and you need to remember it. The situation is the same as with return codes - if you request some resource and an exception occurs (error is returned), resources must be rejected. That is, in any case, you must remember which function throws an exception and which does not.

Oh, and about "exceptional situation"... Well, how can I say... Absence of quotes seems to be a reasonable reason for throwing an exception, but is it an "exceptional situation"?

 
Igor Makanu:

I just don't feel comfortable turning short programmes with readable code into some kind of monster, here is a typical template for MQL4 - check the "new bar", check indicators - work or not work with orders:

in this example, the indicators "pull every tick" as they work on different TFs... it does not really matter.

I use OHLC data inind1(),ind2(),ind3() and inNewBar()

if i get a timeseries access error in one function call, what's the point of continuing to execute this code? - I need to exit to OS and wait for a new tick, i.e. in any ind1(),ind2(),ind3() and inNewBar() I check GetLastError() and after getting an error immediately Exit() in OS with recording in EA log

What's the problem with calling return(iErrrCode) ?

 
Georgiy Merts:

And what is the problem to call return(iErrrCode) ?

Hm, I will try to show it in the code, I rewrote the code with exit if the OHLC data was processed incorrectly, it will look like this:

void OnTick()
  {
   int takeprofit,stoploss; 
   double lot;
   bool nb;
   ENUM_CMD CMD1,CMD2,CMD3;
   if(!ind1( CMD1 )) return;
   if(!ind2( CMD2 )) return;
   if(!ind3( CMD3 )) return;
   if(!NewBar( nb )) return;
   
   if( nb )
     {
      DeleteOrdersLimits(Magic);
      if(CMD1==CMD_BUY && CMD2==CMD_BUY && CMD3==CMD_BUY)
        {
         CalcTakeProfitStopLoss(takeprofit,stoploss);
         lot=CalcLot(stoploss);
         if(ReversSignal)SELL_STOP_PR(Low[1],lot,Magic,stoploss,takeprofit); else BUY_STOP_PR(High[1],lot,Magic,stoploss,takeprofit);
        }
      if(CMD1==CMD_SELL && CMD2==CMD_SELL && CMD3==CMD_SELL)
        {
         CalcTakeProfitStopLoss(takeprofit,stoploss);
         lot=CalcLot(stoploss);
         if(ReversSignal)BUY_STOP_PR(High[1],lot,Magic,stoploss,takeprofit);else SELL_STOP_PR(Low[1],lot,Magic,stoploss,takeprofit);
        }
     }
  }

now I get function values by reference and exit if function was processed incorrectly (in context of discussion - terminal didn't preparehistorical data by TF)

 
Georgiy Merts:

Well, come on, mate...

You say, "you don't need to remember anything", and then you continue: Often even TRY-CATCH is not needed. This same "often" means that somewhere block is needed and somewhere is not needed, and you need to remember it. The situation is the same as with return codes - if you request some resource and an exception occurs (error is returned), resources must be rejected. That is, in any case, you must remember which function throws an exception and which does not.

Oh, and about "exceptional situation"... Well, how can I say... Absence of quotes is a reasonable thing to throw an exception but is it an "exceptional situation"?

You have somehow used exceptions in your own way, wrongly, apparently. Generally, you shouldn't bother with whether this function throws an exception or not. Having TRY-CATCH is optional. And to avoid resource problems, get RAIIhttps://ru.wikipedia.org/wiki/%D0%9F%D0%BE%D0%BB%D1%83%D1%87%D0%B5%D0%BD%D0%B8%D0%B5_%D1%80%D0%B5%D1%81%D1%83%D1%80%D1%81%D0%B0_%D0%B5%D1%81%D1%82%D1%8C_%D0%B8%D0%BD%D0%B8%D1%86%D0%B8%D0%B0%D0%BB%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D1%8F, spinning up the stack will clean it all up.

And about "exceptional situation"... Well, how can I put it... Lack of quotations seems to be a reasonable excuse for throwing an exception, but is it an "exceptional situation"?
Exclusivity is up to the code author, but exceptions should not be analogous to if-else, of course.
 

Oddly enough, I didn't think of it before:

// Немедленное завершение, деструкторы не вызываются
void abort() {Alert(1/(uint)MathAbs(0));}

It gets rid of some mass of error checking, like memory allocation.