Need explanation for code

 

Im very new to this programming,

I have opened a sample program & understood some of the things.

but still I need more explanation..

the code is:

double	LotStep = MarketInfo( Symbol(), MODE_LOTSTEP );
LOT=MathFloor(	LOT / LotStep )*LotStep;
if (LOT>MarketInfo(Symbol(),MODE_MAXLOT)) LOT = MarketInfo(Symbol(),MODE_MAXLOT);
if (LOT<MINLOT)                           LOT = MINLOT;

Could you please any explain me clearly,

why it is?

what is logic?

keyword(predefined words)?

what is happening in this code?

Thanks,

Venkat.

 

V

double LotStep = MarketInfo( Symbol(), MODE_LOTSTEP ); // Gets the value of the minimum size increment between lots, eg 0.1 so 0.1, 0.2 etc
//=========================
LOT=MathFloor( LOT / LotStep )*LotStep; // Logic to try & ensure the submitted LOT size is valid - this is not 100% safe on all brokers
//=========================
if (LOT>MarketInfo(Symbol(),MODE_MAXLOT)) LOT = MarketInfo(Symbol(),MODE_MAXLOT); // Reduces LOT size to maximum allowed (if is over that limit)
if (LOT<MINLOT)                           LOT = MINLOT;                           // Increases LOT size to the minimum allowed if is below

Good Luck

-BB-

 

It's altering the lot size based on the current size of the lot. When your captial increases you want to increase the size of the lot on each trade so you make more profit. Lots have an allowed range like from 0.01 to 500 hence the limit checking.

"Keyword " is a predefined name used in the compiler language like"if" or "double" that you can't use as a variable.

You can find an explanation of each term using the MT4 editor search.

 
BarrowBoy Thanks!
 
this is not 100% safe on all brokers
Please explain why.
 
WHRoeder wrote >>
Please explain why.

Some brokers as Alpari have min lot - 0.1, and lot step 0.01 after 0.1 lot. You can open 0.11 or 0.12 lot but not 0.01 or 0.05.

 
Roger wrote >>

Some brokers as Alpari have min lot - 0.1, and lot step 0.01 after 0.1 lot. You can open 0.11 or 0.12 lot but not 0.01 or 0.05.

Hi Roger

Are you refering to Alpari US? Alpari UK have an option called a micro account. With this account the minimum lot is 0.01, also part of this account is max lot of 2

whocares

Reason: