Lot size - page 2

 

why do you divide the lot by the lotStep and then multiply by the lot step again?

Say the lotstep is 0.1 and your calculated lot size is 0.57

Divide 0.57 by 0.1 and you will get 5.7, mathfloor will return the integer 5

multiply the 5 by 0.1 and you get 0.5 which is a valid lot size whereas 0.57 is not

 
Keith Watford:

why do you divide the lot by the lotStep and then multiply by the lot step again?

Say the lotstep is 0.1 and your calculated lot size is 0.57

Divide 0.57 by 0.1 and you will get 5.7, mathfloor will return the integer 5

multiply the 5 by 0.1 and you get 0.5 which is a valid lot size whereas 0.57 is not

Thanks a lot


It seems that I do  not have to do it with the CDouble library.

Could you confirm?


double tp_lots = CDouble::RoundToLots(OrderLots() * 0.80);
 
Luciole:

Thanks a lot


It seems that I do  not have to do it with the CDouble library.

Could you confirm?


I am the developer of the CDouble library. It's open-source so you can dive into the code for confirmation, but just to save you a bit of time... 

double CDouble::RoundToLots(double number, string symbol = NULL, bool always_return_valid = true)
{
   symbol = symbol == NULL ? _Symbol : symbol;
   double min = SymbolInfoDouble(symbol, SYMBOL_VOLUME_MIN);
   double max = SymbolInfoDouble(symbol, SYMBOL_VOLUME_MAX);
   double lots = RoundToStepDown(number, SymbolInfoDouble(symbol, SYMBOL_VOLUME_STEP));
   if (always_return_valid && lots < min)
      return min;
   if (always_return_valid && lots > max)
      return max;
   return lots;
}
double CDouble::RoundToStepDown(double number, double step)
{
   return step * floor(number / step);
}
 
nicholi shen:

I am the developer of the CDouble library. It's open-source so you can dive into the code for confirmation, but just to save you a bit of time... 

Thanks a lot for your help.

Is is definitely more complex than I expected.


Just to be clear the code that you wrote just above, is the code I have to read to understand how it works?

and not the code I have to write in my own program?


Thanks and Sorry, I am a beginner in coding...

Luciole

 

Luciole: Thanks a lot for your help. Is is definitely more complex than I expected.

Just to be clear the code that you wrote just above, is the code I have to read to understand how it works?

and not the code I have to write in my own program?

Thanks and Sorry, I am a beginner in coding...

Yes, that is correct. That code which  @nicholi shen has shown you, is the functionality behind the CDouble method "RoundToLots".

It is always good to know how the "engine" works before you "drive a car"!

 
Fernando Carreiro:

Yes, that is correct. That code which  @nicholi shen has shown you, is the functionality behind the CDouble method "RoundToLots".

It is always good to know how the "engine" works before you "drive a car"!

Exactly ! and I think I got it !

but I am not really in coding (as you probably already know)

and I was not 100% sure of that.. hi hi !


Thanks a lot for your help :)

 

i wrote that in my program:

#include <Double.mqh>


it is written this error message:

can't open "C:\Users\Ludivine\AppData\Roaming\MetaQuotes\Terminal\76AE827A66F7801B9D79B1FD1D2103FD\MQL4\include\Double.mqh" include file TradingGM_FOREX_VENTE.mq4 12 11


Should I download the library somewhere?

 
Luciole:

i wrote that in my program:

#include <Double.mqh>


it is written this error message:

can't open "C:\Users\Ludivine\AppData\Roaming\MetaQuotes\Terminal\76AE827A66F7801B9D79B1FD1D2103FD\MQL4\include\Double.mqh" include file TradingGM_FOREX_VENTE.mq4 12 11


Should I download the library somewhere?

Yes you need to download this file and copy it to C:\Users\Ludivine\AppData\Roaming\MetaQuotes\Terminal\76AE827A66F7801B9D79B1FD1D2103FD\MQL4\include

 
nicholi shen:

Yes you need to download this file and copy it to C:\Users\Ludivine\AppData\Roaming\MetaQuotes\Terminal\76AE827A66F7801B9D79B1FD1D2103FD\MQL4\include

Thanks I did and it is almost working !!! thanks a lot !

I still have some problems when I try to close some part of the lots.


What I initially wrote was :

if (MarketInfo(Symbol(), MODE_BID) <= profit)
               {
                   if(OrderSelect (magic,SELECT_BY_TICKET) == true)
                     lot3 = CDouble::RoundToLots(OrderLots() * 0.8);
                     OrderClose (OrderTicket(), lot3, OrderClosePrice(), 10, Red);
                     return(0);
               }

But then, a warning message saying "return value of 'orderClose' should be checked

So I wrote that, as suggested here

 {
                   if(OrderSelect (magic,SELECT_BY_TICKET) == true)
                     lot3 = CDouble::RoundToLots(OrderLots() * 0.8);
                     OrderClose (OrderTicket(), lot3, OrderClosePrice(), 10, Red);
                     return(0);
               }

Now there is this error message  "'return' - 'void' function returns a value".

I am confused as I do not understand why should I wrote return 0.. or do anything else..

Any suggestions? :)



OrderClose - Trade Functions - MQL4 Reference
OrderClose - Trade Functions - MQL4 Reference
  • docs.mql4.com
OrderClose - Trade Functions - MQL4 Reference
 

Have picked up a few things here, will come back with questions.

Reason: