Is it possible to avoid many "ors" (||) in conditions causing the same action? - page 7

 

What a fruitful night I've had tonight! I've had so many interesting things thrown at me while I've slept, for which I am eternally grateful! And your mornings were wiser than evenings too!

A quick look through all the suggested stuff still raises questions as always, but for now I just want to find out if it's possible to do the last expression with only one Action(), as it's quite extensive:

if (!A) if (!B) if (!C) if (!D)
else Action();


It seems to me it could be faster. True, it doesn't preclude checking all conditions if only the last one is executed, or I'm wrong, which would be better for me.

What do you think?

 
FAQ:
Whoever doesn't like "fucking MQL4" might as well go on a run, run. Because it's unclear what he's doing here, despite all the merits and antiquity of the account.
Please explain it to the uninitiated!
 
Meat:
In general, the fastest option would be this:

However,else result=false line should better be combined with the first one, it won't affect speed.In general, if A, B, C and D contain simple conditions (with minimum arithmetic, without calls of all math functions and other stuff), then you won't get much performance gain from such optimization (unless this construction runs tens of millions of times, of course). But code overloading can be significant.

I wrote about it in one of the threads that everything must be handled rationally. For some reason, it seems to me that your code is full of more important places optimization of which would really give a huge performance gain. You should start with the basic algorithm. Most newbies have a dumb check of all conditions concerning TS or open orders at every tick. But in most cases, it is enough to check only boundary conditions, for example when haul or low reaches a certain value, or when a new bar appears. Only after that you can perform further checks.

Well, besides with resource-intensive calculations you need to think about moving these calculations to a DLL. Otherwise, to sit and wait for 13 minutes in fucking MQL4 (while you can get the same result for 2-3 minutes) seems to be unfortunate :)


although I absolutely agree with the first part.
 
icas:

It's even faster that way.

A tale comes to mind:

"There were two questions at a company board meeting:

1. The decision to build the synchrophasotron.

2. The decision to build a bicycle car park for employees.

On the first issue, the discussion lasted for 1 minute,

on the 2nd, the debate lasted more than 2 hours."

Yeah, right... About the bike park...
 
borilunad:

What a fruitful night I've had tonight! I've had so many interesting things thrown at me while I've slept, for which I am eternally grateful! And your mornings were wiser than evenings too!

A quick look through all the suggested stuff still raises questions as always, but for now I just want to find out if it's possible to do the last expression with only one Action(), as it's quite extensive:

It seems to me it could be faster. True, it doesn't preclude checking all conditions if only the last one is executed, or I'm wrong, which would be better for me.

What do you think?

Nah, it doesn't work that way. Firstly, there must be something after if(), at least just a semicolon (i.e. empty operator). Second, which one of the if's is your else operator intended to belong to? If it refers only to the last one (as you wrote it), then Action will be executed only if the D condition is true provided that A,B and C are false. It is always advisable to place curly braces to see the logic clearly.

 
FAQ:

Thank you! I'm avoiding the use of DLL and other pro-MCLogo stuff for now.

I'll take this opportunity to reply to Alexey (Meat) that all position openings are done on a new bar, though on M1, but everything else works on every tick. I also use a lot of necessary functions (if I check everything at start time, then the code will be really heavy). There's even one MathPow(), which I'll try to replace with the exponent suggested by Mathematician. As for the rest, all the necessary overshoots for modifications and closures. How to do without it?

 
Pay attention to monitoring and recalculating orders. this is what advisors usually do the most.
 
alsu:

No, it doesn't work that way. First, there must be something after if(), at least just a semicolon (i.e. an empty operator). Second, which one of the if's is your else operator meant to belong to? If it refers only to the last one (as you wrote it), then Action will be executed only if the D condition is true provided that A,B and C are false. It is always desirable to place curly braces to see the logic clearly.

Thank you! But I need only one Action();! But I don't know how! Can you give me a hint?

 
FAQ:
Pay attention to control and order recalculation. this is what advisors usually do the most.
But they are unavoidable, otherwise there will be errors!
 

In my programs, if there are a lot of ifs, I use this construction, putting conditions that will most often give false in the first place:

if (A>B)
{  if (C>=10)
   {  if (D<=5)
      {  if(E=1)
         Action:
      }
   }
}
And if it is necessary to check a lot of ifs, then it is like this
if (A>B || N<M)
{  if (C>=10 || P<100)
   {  if (D<=5 || R>1)
      {  if(E=1 || S!=0)
         Action:
      }
   }
}
Reason: