Learning logic - page 13

 
xrust:

always killed the logic of such a construction in cyclic operands :

I've always been killed by nested if's - why make such a nesting in an empty space?

completely incomprehensible ...

If you don't understand it, I can only sympathize.

If you ask me, the standard logic is clearer and more understandable:

Your logic is not standard. It's wrong.
 
xrust:

I find it much more logical to put brackets either on one line or in one column. It is very difficult to understand code in which it is not clear where a block starts or ends. Well, if the purpose of such formatting is to hide the sense of the code from enemies, then the goal is achieved.
 
TheXpert:
I've always been killed by nested if's -- why make such nesting at the source?

If it's not clear, I can only sympathise.

Your logic is not standard. It's wrong.

Correction, it's just a phrase that sticks out :-)

--

Unconventional logic doesn't mean it's wrong.

--

when the path of non-standard logic is shorter than that of standard logic -- with equal input and output conditions --

then to hell with standards!

Then I'm all for non-standard logic.

--

yes the crunch code is hard to read...

...although I have seen very short and hard to read code ...

for maintenance - replication this code is not ideal .

If you write it for circulation, you usually have to take care of your colleagues to maintain it .

if you write code with the expectation that someone will break it!

Ideally, it is LOGIC to go through the trouble - you write correctly but make code that is not readable.

 
drknn:

I don't understand where the puncture is? And why the second one? If it's the second, then where's the first?

The code that was scolded really isn't super, it's perfect to confuse!

 

2 Vinin . Victor, why call the order selection function all the time? It's easier to fill in all the variables in one loop.

 

I think it's pretty good:

int time;
int FindLastOpenTime(int type, int imagic)
{
  
  for(int i = OrdersTotal() -1 ;i>=0;i--)
  {
     if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        if(OrderSymbol()==Symbol() && OrderType()==type && OrderMagicNumber()==magic && OrderOpenTime()>time)
                 {     
                    time=OrderOpenTime();
                 }
  }
  return(time);
}  
 

In MQL the behaviour of && and || operators is different than in C++, so it makes sense to separate conditions.

FION:

2 Vinin - Victor, why call the order selection function all the time? It's easier to fill all variables in one loop.

It's up to everyone.
 
TheXpert:

...It depends.


It's clear. What is the point of code optimization anyway? In reducing the number of lines? I see the only sense in increasing the code speed, and this can be achieved by reducing the number of calls of cyclic functions, for example. Or by excluding of indicator calculation repetitions. Approximately so.
 
FION:

I only see the point in increasing the speed of the code

By and large, speed is not crucial in 90% of cases. The point is to initially make the code so that it is as easy to build and read as possible.

Then, if time is crucial, we optimize the speed.

 

Transferring here from here

int AnaliseFunc (string sy, int tf)
{
   
   CurAsk   =MarketInfo(Symbol(),MODE_ASK);
   CurBid   =MarketInfo(Symbol(),MODE_BID);
   OpnPrice =iOpen(NULL,PERIOD_M5,0);
   OpnPrice1=iOpen(NULL,PERIOD_M5,1);
   ClsPrice1=iClose(NULL,PERIOD_M5,1);
         
   if (sy=="" || sy=="0") sy=Symbol();
double
   BB_1  =iCustom(sy,tf,"BB_MA",13,1,1,1),
   BB_2  =iCustom(sy,tf,"BB_MA",13,1,1,2),
   BB_3  =iCustom(sy,tf,"BB_MA",13,1,1,3),
   AO1   =iAO(sy,tf,1),
   AO2   =iAO(sy,tf,2),
   AO3   =iAO(sy,tf,3),
   AC1   =NormalizeDouble(iAC(sy,tf,1),8)*1000,
   AC2   =NormalizeDouble(iAC(sy,tf,2),8)*1000,
   AC3   =NormalizeDouble(iAC(sy,tf,3),8)*1000,
   AC4   =NormalizeDouble(iAC(sy,tf,4),8)*1000,
   AC5   =NormalizeDouble(iAC(sy,tf,5),8)*1000,
   SpMan1=iCustom(sy,tf,"SpearmanRankCorr",14,1000,30,true,0,1),
   SpMan2=iCustom(sy,tf,"SpearmanRankCorr",14,1000,30,true,0,2),
   DeM_1 =iDeMarker(sy,tf,14,1),
   DeM_2 =iDeMarker(sy,tf,14,2),
   Mom_1 =iMomentum(sy,tf,14,PRICE_CLOSE,1),
   Mom_2 =iMomentum(sy,tf,14,PRICE_CLOSE,2),
   Mom_3 =iMomentum(sy,tf,14,PRICE_CLOSE,3);
   
//---------------- Проверка на разворот BB_MA -------------------------------------------------------   
   
   if (BB_1>BB_2 && BB_2<=BB_3 && BB_1<0)                               // Найден разворот BB вверх
      {
      switch (tf)
         {
            case 1:     TrBBTurnUP_M1 =true;  TrBBTurnDN_M1=false;      // Флаг разворота вверх на М1
            case 5:     TrBBTurnUP_M5 =true;  TrBBTurnDN_M5=false;      // Флаг разворота вверх на М5
            case 15:    TrBBTurnUP_M15=true;  TrBBTurnDN_M15=false;     // Флаг разворота вверх на М15 
            case 30:    TrBBTurnUP_M30=true;  TrBBTurnDN_M30=false;     // Флаг разворота вверх на М30 
            case 60:    TrBBTurnUP_H1 =true;  TrBBTurnDN_H1=false;      // Флаг разворота вверх на H1
            case 240:   TrBBTurnUP_H4 =true;  TrBBTurnDN_H4=false;      // Флаг разворота вверх на H4
            case 1440:  TrBBTurnUP_D1 =true;  TrBBTurnDN_D1=false;      // Флаг разворота вверх на D1
            case 10080: TrBBTurnUP_W1 =true;  TrBBTurnDN_W1=false;      // Флаг разворота вверх на W1
            case 43200: TrBBTurnUP_MN =true;  TrBBTurnDN_MN=false;      // Флаг разворота вверх на MN
         }
      }
   if (BB_1<BB_2 && BB_2>=BB_3 && BB_1>0)                               // Найден разворот BB вниз
      {
      switch (tf)
         {
            case 1:     TrBBTurnUP_M1 =false;  TrBBTurnDN_M1=true;      // Флаг разворота вниз на М1
            case 5:     TrBBTurnUP_M5 =false;  TrBBTurnDN_M5=true;      // Флаг разворота вниз на М5
            case 15:    TrBBTurnUP_M15=false;  TrBBTurnDN_M15=true;     // Флаг разворота вниз на М15 
            case 30:    TrBBTurnUP_M30=false;  TrBBTurnDN_M30=true;     // Флаг разворота вниз на М30 
            case 60:    TrBBTurnUP_H1 =false;  TrBBTurnDN_H1=true;      // Флаг разворота вниз на H1
            case 240:   TrBBTurnUP_H4 =false;  TrBBTurnDN_H4=true;      // Флаг разворота вниз на H4
            case 1440:  TrBBTurnUP_D1 =false;  TrBBTurnDN_D1=true;      // Флаг разворота вниз на D1
            case 10080: TrBBTurnUP_W1 =false;  TrBBTurnDN_W1=true;      // Флаг разворота вниз на W1
            case 43200: TrBBTurnUP_MN =false;  TrBBTurnDN_MN=true;      // Флаг разворота вниз на MN
         }
      }
//---------------------- Проверка на разворот Momentum -----------------------------------------------
   
   if (Mom_1>Mom_2 && Mom_2<=Mom_3 && Mom_1<100.0)
      {
      switch (tf)
         {
            case 1:     TrMomTurnUP_M1 =true;  TrMomTurnDN_M1=false;      // Флаг разворота вверх на М1
            case 5:     TrMomTurnUP_M5 =true;  TrMomTurnDN_M5=false;      // Флаг разворота вверх на М5
            case 15:    TrMomTurnUP_M15=true;  TrMomTurnDN_M15=false;     // Флаг разворота вверх на М15 
            case 30:    TrMomTurnUP_M30=true;  TrMomTurnDN_M30=false;     // Флаг разворота вверх на М30 
            case 60:    TrMomTurnUP_H1 =true;  TrMomTurnDN_H1=false;      // Флаг разворота вверх на H1
            case 240:   TrMomTurnUP_H4 =true;  TrMomTurnDN_H4=false;      // Флаг разворота вверх на H4
            case 1440:  TrMomTurnUP_D1 =true;  TrMomTurnDN_D1=false;      // Флаг разворота вверх на D1
            case 10080: TrMomTurnUP_W1 =true;  TrMomTurnDN_W1=false;      // Флаг разворота вверх на W1
            case 43200: TrMomTurnUP_MN =true;  TrMomTurnDN_MN=false;      // Флаг разворота вверх на MN
         }
      }
      
   if (Mom_1<Mom_2 && Mom_2>=Mom_3 && Mom_1>100.0)
      {
      switch (tf)
         {
            case 1:     TrMomTurnUP_M1 =false;  TrMomTurnDN_M1=true;      // Флаг разворота вверх на М1
            case 5:     TrMomTurnUP_M5 =false;  TrMomTurnDN_M5=true;      // Флаг разворота вверх на М5
            case 15:    TrMomTurnUP_M15=false;  TrMomTurnDN_M15=true;     // Флаг разворота вверх на М15 
            case 30:    TrMomTurnUP_M30=false;  TrMomTurnDN_M30=true;     // Флаг разворота вверх на М30 
            case 60:    TrMomTurnUP_H1 =false;  TrMomTurnDN_H1=true;      // Флаг разворота вверх на H1
            case 240:   TrMomTurnUP_H4 =false;  TrMomTurnDN_H4=true;      // Флаг разворота вверх на H4
            case 1440:  TrMomTurnUP_D1 =false;  TrMomTurnDN_D1=true;      // Флаг разворота вверх на D1
            case 10080: TrMomTurnUP_W1 =false;  TrMomTurnDN_W1=true;      // Флаг разворота вверх на W1
            case 43200: TrMomTurnUP_MN =false;  TrMomTurnDN_MN=true;      // Флаг разворота вверх на MN
         }
      }
Reason: