1. ## Maximal lot size

ok to refine the whole thing:

each broker have set an AccountStopoutMode and an AccountStopoutLevel.

my broker (IBFX) uses AccountStopoutMode 0. that means "calculation of percentage ratio between margin and equity".

my ea does not many trades and if the ea is trading, i want to do this with the biggest possible lotSize between minimum and maximum lotSize given by my broker.

i have a fixed stopLoss and a fixed TakeProfit on my trades.

so now thats the point.

if i open a trade a need to know what the maximum lotSize could be without triggering a stopout.

i started now maybe 10 times to create a function to get this but with no success, so thats also the reason why i dont can post some code.

i found several functions for money management and also this here:

double calculateLotSize(int c)
{
double stopLoss = ((MarketInfo(currencies[c], MODE_STOPLEVEL) + MarketInfo(currencies[c], MODE_SPREAD))*3) * MarketInfo(currencies[c], MODE_POINT);
double takeProfit = ((MarketInfo(currencies[c], MODE_STOPLEVEL) + MarketInfo(currencies[c], MODE_SPREAD))*2) * MarketInfo(currencies[c], MODE_POINT);

double minLot = MarketInfo(currencies[c],MODE_MINLOT);
double maxLot = MarketInfo(currencies[c],MODE_MAXLOT);

double OneLotMargin = MarketInfo(currencies[c],MODE_MARGINREQUIRED);
double MarginAmount = AccountBalance()/5;
double lotMM = MarginAmount/OneLotMargin;
double LotStep = MarketInfo(currencies[c],MODE_LOTSTEP);
lotMM = NormalizeDouble(lotMM/LotStep,0)*LotStep;

if(lotMM < minLot) {
lotMM = minLot;
}
if(lotMM > maxLot) {
lotMM = maxLot;
}

return(lotMM);
}

but i dont think this will do it in any way.

the approach should more be like this:

free margin - stopModeLevel - max possible loss of my running trades = value of available margin

value of available margin => value of available margin for my new order

and then calculating what lotSize would be possible for this new order

i hope this would help to know what i want...

best regards,

mike