What is the difference - int, double?

 

Hi, just wondering what the difference is if you use;

extern int

or

extern double

Thanks

 

Anything that needs to be specified as a fractional value (Lots 0.01 etc.) requires you to use Double, whole numbers (Pips 30 etc.) are fine as Integers

 

Thank you. Does it really matter though if I use either?

 
matrixebiz:
Thank you. Does it really matter though if I use either?

yes it matters

if you have a value thats an integer (a number without a decimal place) such as 1,4, 66, 176 etc then you should really use an integer. Examples might be full lot sizes, or the size of a stop or target in pips.

if your variable is representing a real rumber (one with a decimal point) such as 1.2756 or 2.0109 then you need to use a double. If you use an integer in this case, all of the data after the decimal point will be lost. So you need to use doubles for fractional lots, or exchange rates, stop levels, target levels, indicator values etc

 

Lets put it simple - if you, by accident, make int lots, you will only use whole lots which will kill 10k deposit in most cases

On the other hand, if you make every variable double, you'll eat more resources of the PC and ultimately eat all the resources!

Choose if you need fractions when you are making a new variable.

 
Shinigami:
... if you make every variable double, you'll eat more resources of the PC and ultimately eat all the resources!

Its not even always possible: many variables must be integer, for example indexes of arrays.

 
Michel:
Its not even always possible: many variables must be integer, for example indexes of arrays.

Some have to be but if you have 2000 doubles in one EA where half could be integer, you'll take up much more resources with 50 EAs running in 2 MT4s than you could

 
Shinigami:
Some have to be but if you have 2000 doubles in one EA where half could be integer, you'll take up much more resources with 50 EAs running in 2 MT4s than you could

Yes, that's true.

 

Its always good to know what you want and what you will need to use to get the fastest result. Its also good to attach things like current time that you are going to check for being true more than once in a row to some variable.

Example

datetime timer=TimeCurrent();

if(timer==start)

dosomething;

if(timer==end)

dosomethingelse;

ect. Its always good to know what you want.

 
Shinigami:
Its always good to know what you want and what you will need to use to get the fastest result. Its also good to attach things like current time that you are going to check for being true more than once in a row to some variable.

Example

datetime timer=TimeCurrent();

if(timer==start)

dosomething;

if(timer==end)

dosomethingelse;

ect. Its always good to know what you want.

Good points, but there are times when I'd rather trade off a bit of speed for readability.

 
zupcon:
Good points, but there are times when I'd rather trade off a bit of speed for readability.

Just add comments to know what does every function does