Download MetaTrader 5
To add comments, please log in or register
Having troubles understanding the code? Articles can help you!
mikegreen
236
mikegreen 2016.05.22 21:58 
// Determine what a pip is.
   pips=Point; //.00001 or .0001. .001 .01.
   if(Digits==3 || Digits==5)

      pips*=10;

 

I get an invalid lot size error if I enter say 1.63 lot however if I enter 1.6 lot then I do not get an error message.

Please note that I am spread betting on fx is there a fix for my Pip sizing above or might the problem lie somewhere else in my EA?

Hope someone can suggest a fix thanks?? 

Keith Watford
Moderator
7862
Keith Watford 2016.05.22 23:04  
mickeyferrari:
// Determine what a pip is.
   pips=Point; //.00001 or .0001. .001 .01.
   if(Digits==3 || Digits==5)

      pips*=10;

 

I get an invalid lot size error if I enter say 1.63 lot however if I enter 1.6 lot then I do not get an error message.

Please note that I am spread betting on fx is there a fix for my Pip sizing above or might the problem lie somewhere else in my EA?

Hope someone can suggest a fix thanks?? 

What does your code have to do with lot size?

Maybe the symbol's lot step is 0.1, so anything smaller will be rejected.

Fernando Carreiro
1428
Fernando Carreiro 2016.05.23 01:23  

As GumRai has pointed out, the volume or lots has nothing to do with pips or points (unless it is part of some unknown formula that you have not shown).

What is important, also pointed out by GumRai, is that your volume abide by the Broker's conditions of Minimum, Maximum and Step Size:

dblMarketLotMin  = MarketInfo( _Symbol, MODE_MINLOT  ); // Minimum Lots   allowed by Broker
dblMarketLotMax  = MarketInfo( _Symbol, MODE_MAXLOT  ); // Maximum Lots   allowed by Broker
dblMarketLotStep = MarketInfo( _Symbol, MODE_LOTSTEP ); // Lots Step Size allowed by Broker

// dblLotsCalculated = calculated volume based on risk, margin or other formula
// dblLotsNormalised = normalised volume based on broker's minimum, maximum and step size

dblLotsNormalised = fmin( fmax( round( dblLotsCalculated / dblMarketLotStep ) * dblMarketLotStep, dblMarketLotMin ), dblMarketLotMax );
whroeder1
13590
whroeder1 2016.05.23 16:12  
Last line of my standard post
Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
Fernando Carreiro
1428
Fernando Carreiro 2016.05.23 16:26  
WHRoeder:
Last line of my standard post - Lot size must also be adjusted to a multiple of LotStep. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
@WHRoeder, it may be advisable for you to update/revise your "NormalizeLots()" code at that post, because it is currently incomplete and does not check against the maximum number of lots ("MODE_MAXLOT").
/
To add comments, please log in or register