
09-17-2007, 07:13 PM
|
|
Senior Member
|
|
Join Date: Mar 2006
Location: La Verne,CA
Posts: 560
|
|
Thanks Nix,
This saves me some time.
Robert
Quote:
Originally Posted by nix
This modification of my previous AutoLot function should do the trick and takes the StopLoss value into consideration:
Code:
double AutoLots(int Risk, int StopLossInPips, double MIN_lots = 0.1, double MAX_lots = 5)
{
int Decimals = 0;
double LotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
double LotSize = MarketInfo(Symbol(), MODE_LOTSIZE);
double LotTickValue = MarketInfo(Symbol(), MODE_TICKVALUE);
if(LotStep == 0.01)
Decimals = 2;
if(LotStep == 0.1)
Decimals = 1;
double LotsToRisk = ((AccountFreeMargin()*Risk)/100)/StopLossInPips;
double Lots = StrToDouble(DoubleToStr(LotsToRisk/LotTickValue,Decimals));
if (Lots < MIN_lots)
Lots = MIN_lots;
if (Lots > MAX_lots)
Lots = MAX_lots;
return(Lots);
}
|
|