Position Size (again)

 

Hi All,


I know this has been asked and answered here before, but I'll be darned if I can find it!


I am looking for the algorithm for position sizing for a given stop loss when the account balance is different to the base currency of the trading pair e.g.


AccountCurrency: AUD
AccountSize: 1000
AccountLeverage: 100
RiskRatio: 0.5% (0.005)
StopLoss: 15 pips

Point: 0.0001
TradingPair: EURUSD
AUDUSD_Ask: 0.6415


So....

Risk = AccountSize * RiskRatio = 1000 * 0.005 = AUD$5


then Lots = ((Risk * AUDUSD_Ask) / StopLoss) / Leverage = ((5 * 0.6415) / 15) / 100 = 0.00214 Lots ??


Is this correct? It seems I always end up with really small marginal lots, so I figure I must have my logic wrong somewhere?



Thanks in advance for taking the time to answer this... my brain is in another place today!


P.S. Can someone please explain the rationale of MarketInfo( Symbol(), MODE_TICKVALUE )

 
double calcPositionSize(double amountToRisk, int pipRange, string currentSymbol, string myCurrency, double minimumLotSize, double maxLotSize)
{
   string baseCurrency = StringSubstr(currentSymbol,0,3);
   string quoteCurrency = StringSubstr(currentSymbol,3,3);
   double lotSize;
   
   double standardLotSize = MarketInfo(currentSymbol, MODE_LOTSIZE);
   double tickSize = MarketInfo(currentSymbol, MODE_POINT);
   double singlePipValue;
   
   if(quoteCurrency == myCurrency){
      singlePipValue = standardLotSize * tickSize;
   }
   
   if(baseCurrency == myCurrency){
      singlePipValue = standardLotSize * tickSize / MarketInfo(currentSymbol, MODE_ASK);
   }
   
   if(baseCurrency != myCurrency && quoteCurrency != myCurrency){
      singlePipValue = standardLotSize * tickSize * MarketInfo(baseCurrency + myCurrency, MODE_ASK) / MarketInfo(currentSymbol, MODE_ASK);
   }
   
   lotSize = NormalizeDouble( (amountToRisk * standardLotSize) / (pipRange * singlePipValue) / standardLotSize , 2);
   
   if(lotSize < minimumLotSize){
      return(minimumLotSize);
   }else if(lotSize > maxLotSize){
      return(maxLotSize);
   }else{
      return(lotSize);
   }
}
 

Thanks for the reply jmca,


I did a bit of playing around with your code to meet my requirements and (eventually) came up with this as my alternative solution:


double Lots(int TradeRisk, int StopLoss)
{
	double MinLot = MarketInfo(Symbol(), MODE_MINLOT);
	double MaxLot = MarketInfo(Symbol(), MODE_MAXLOT);
	double LotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
      double lots=0.0;
   
	lots = (AccountEquity() * TradeRisk / 100) / (StopLoss * MarketInfo(Symbol(),MODE_TICKVALUE));
	lots /= LotStep;
	lots = NormalizeDouble(lots, 0);
	lots *= LotStep;
		
	if(lots>MaxLot) lots=MaxLot;
	if(lots<MinLot) lots=0.0;
	
	return(lots);
}

 
wabbit:

Thanks for the reply jmca,


I did a bit of playing around with your code to meet my requirements and (eventually) came up with this as my alternative solution:


The code as u have it now will not calculate cross currencies correctly.

Reason: