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

 
alsu:
We can accelerate further, for example if we know that condition A is on average satisfied more often than C and C more often than B, then we should put them in that order: if(!a){if(!c)if{(!b) M=false;}}

You can speed things up even more by combining the probability of a condition happening with its computational complexity: for instance, taking as a criterion the product of the probability of happening by the value inverse of the computation time, the first conditions to be checked are those which are the most probable and have the lowest computational complexity, i.e. those which have the highest value of our given criterion.
 
TarasBY:

You can also optimise calculations in this way:

Or maybe you could try it this way:

    bool M = false;

    if (A) M = true; else if (B) M = true; else if (C) M = true; else if (D) M = true; else if (E) M = true;
    if (M == true) Action;

Thank you!

 
alsu:

You can speed things up even further by combining probability of a condition with its computational complexity: for example, taking as a criterion the product of probability of execution by a value inverse of computation time, first check those conditions which are most probable and have the lowest computational complexity, that is, those which have the highest value of our given criterion.

I put them in that order a long time ago. But even if more than one condition is fulfilled, the first one that comes up will be fulfilled.

And it doesn't matter, because then the final conditions are common for all variants.

 
alsu:

You can speed things up even more by combining probability of a condition with its computational complexity: for example, taking as criterion the product of probability of execution by the value inverse of computation time, first check those conditions which are most probable and have the lowest computational complexity, i.e. those which have the highest value of the criterion we set.
Alexey, once again I answer your suggestion to swap conditions depending on their influence on speed of actions. And here's what I found! The most complex calculations are not as slow as functions that check various necessary market data and open positions for each tick. I've already simplified these functions quite a bit on the advice of one of forum members, throwing out all unnecessary things in my case, which has almost doubled their speed. As for the choice to work on "every" tick, I was convinced earlier that only this mode brings me closer to real possible results. So, having implemented these functions after all the calculations, indicator checks and current price checks, the speed has doubled, which now makes 7 minutes of running in the tester during half a year and 14 minutes a year respectively. I cannot give up functions that perform the necessary checks, if the previous conditions allow. Now I will try to optimize the code by changing && to ) if (. I will be glad to know what other possibilities of code optimization there are. Thank you and everyone for your help!
 
borilunad:

None of the operators fit. Is there any other way without if(A || B || C || D || E) Action;?

I ask moderators not to send to general questioners thread due to importance of the question I'm thinking about and can't find a more rational solution! Thank you!


if(A || B || C || D || E) Action; I would do thisif((A + B + C + D + E) > 0) Action; ifAction needs at least 3 signals, write 2 instead of 0

the speed, I didn't measure it.

 
pako:


if(A || B || C || D || E) Action; I would do thisif((A + B + C + D + E) > 0) Action; ifAction needs at least 3 signals, write 2 instead of 0

speed, I did not measure


The speed would be tremendous. The solution is very original
 
If A,B,C,D are functions, you should count up in order of complexity, starting with the easiest and constantly checking for truth. This will work faster.
 
Vinin:

The acceleration will be tremendous. The solution is very original.
Just in! Thank you, Pako! Thank you, Victor! I'll have lunch now and give it a try!
 
FION:
If A,B,C,D are functions, you have to count by complexity, starting with the easiest one, and constantly check for truth. It will work faster that way.

Thank you for your participation! A, B, C ... not functions, but conditions containing functions and not containing functions, and furthermore mutually exclusive! And one condition is enough to jump to other conditions that already trigger action. If there were only functions, then there wouldn't be a problem:

double A = function1(); double B = function2(); double C = function3(); double D = function4(); double E = function5(); and then as Pako suggested:

if((A + B + C + D + E) > 0)

{other condition with mirrored direction to close Byes or Sells} action;BUT:

And I need A = condition1, B = condition2, C = condition3, D = condition4, E = condition5. Is it possible or not! Or is it impossible and that's it!

For example:

bool a = true;

//или
double a;

а = (isCloseLastPosByTake() == True && Profit > ProClo / clo - GetProfitCloseLastPosByTake() * clo);

I don't know what to try!

 
borilunad:

And I need A = condition1, B = condition2, C = condition3, D = condition4, E = condition5. Is it possible or not?! Or is it impossible and that's it!

bool a = true;

//или
double a;

а = (isCloseLastPosByTake() == True && Profit > ProClo / clo - GetProfitCloseLastPosByTake() * clo); <---   10,444 = 8,087 > 3,908 эт на каком языке? 

bool a = false;

if (isCloseLastPosByTake() == True && Profit > ProClo / (clo - GetProfitCloseLastPosByTake() * clo)) a = true;
Reason: