Is there any differecent between 2 code?

 

I wonder there is a difference between below code.

because I want to make backtest speed faster.

if (a>0) Print ("OK");


if(a!=0)Print ("OK");

If you know some other ideas to make backtest faster even in everytick mode with icustom.

Please tell me.


Thank you.

 

Hi,

it depends on the possible value of var a - if it is negative, the second statement will print "OK" the first one not.

But I doubt that there will be measurable differences in the backtest with these two instructions.

Best regards

 
In fact there is a difference in speed. But it is so marginal, you won't notice it.

Unequal comparison will stop as soon as 2 bits differ. While grater or any other comparison will need to use the full length of the values.

Therefore, it is faster to do an unequal comparison vs any other. But it is very marginal, even if performed trillions of times. Almost not measurable.
 
Cromo: If you know some other ideas to make backtest faster even in everytick mode with icustom.
  1. EAs : Don't do per tick that you can do per bar, or on open.
    If you are waiting for a level, don't reevaluate, wait until price reaches it (or a new bar starts, and you recalculate.)
    If you are waiting for an order to close, only look when OrdersTotal (or MT5 equivalent) has changed.
              How to get backtesting faster ? - MT4 - MQL4 programming forum 2017.08.07

  2. Indicators: Code it properly so it only recomputes bar zero (after the initial run.)
              How to do your lookbacks correctly. 2016.05.11
    Or, reduce Tools → Options (control+O) → Charts → Max bars in chart to something reasonable (like 1K.)

 
William Roeder:
  1. EAs : Don't do per tick that you can do per bar, or on open.
    If you are waiting for a level, don't reevaluate, wait until price reaches it (or a new bar starts, and you recalculate.)
    If you are waiting for an order to close, only look when OrdersTotal (or MT5 equivalent) has changed.
              How to get backtesting faster ? - MT4 - MQL4 programming forum 2017.08.07

  2. Indicators: Code it properly so it only recomputes bar zero (after the initial run.)
              How to do your lookbacks correctly. 2016.05.11
    Or, reduce Tools → Options (control+O) → Charts → Max bars in chart to something reasonable (like 1K.)

Hi,WIlliam

Thank you for your comments.

By the way, if I need to do backtest in everytick mode, like an order is places during current bar is forming,

the reason why backtest speed is so slow is due to using icustom with some indicator file?

 
Werner Klehr:

Hi,

it depends on the possible value of var a - if it is negative, the second statement will print "OK" the first one not.

But I doubt that there will be measurable differences in the backtest with these two instructions.

Best regards

Thank you. Maybe I don't need to think about both code is not so different.

 
Dominik Egert:
In fact there is a difference in speed. But it is so marginal, you won't notice it.

Unequal comparison will stop as soon as 2 bits differ. While grater or any other comparison will need to use the full length of the values.

Therefore, it is faster to do an unequal comparison vs any other. But it is very marginal, even if performed trillions of times. Almost not measurable.

I got it. Thank you.

I use icustom but everytick mode gives me so much stress... Speed is so slow.

 
Cromo: the reason why backtest speed is so slow is due to using icustom with some indicator file?

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the file.

Cromo: I use icustom but everytick mode gives me so much stress... Speed is so slow.
So stop calling it. See #3.1 and #3.2
 
Cromo:

I wonder there is a difference between below code.

because I want to make backtest speed faster.


It is valid to mention, that the compiler does code optimizations, example:

If you code something like:  

int a = 0; int b = 1; if(a != b) Print("lalala");

During compilation, the optimization will know that this comparison will always be true, so it substitutes de above code to:

Print("lalala");


The "if", will never exist during execution.

Just the Print command, since the comparison was useless, the the compiler rewrite it during optimization phase. 

The optimization phase, makes thousands of adjusts like the above example, and much more complex ones, specially for loop and while situations. 

So you don't have to worry about micro-optimizations or situations like this, while writing the code. 


It is much more important, to follow what William Roeder proposed. 

Reason: