I know my entry price and my Stop Loss price. I want to when stop loss will be hit then i always loose for example 10USD.

I followed discussion here (link bellow) but it didnt worked for me. Orders sizes always too small

https://www.quantconnect.com/forum/discussion/7442/calculating-lot-size-for-a-forex-order-based-on-portfolio-value-and-leverage/p1

 

I managed to make code to work almost like i want but results are just approximate. Also i am sure i overcomplicated things.

How calculate order size based on SL price and wanted amount to loose?

private decimal GetNewMinOrderQuantityForex(int desiredAmountToLose, decimal entryPrice, decimal stopOrTpPrice, decimal minPriceVariation, decimal margin, decimal leverage)
{
if (entryPrice == 0) return 0;

var maxOrderSize = margin * leverage / entryPrice;

if (minPriceVariation == 0 || entryPrice == 0 || minPriceVariation == 0) return 0;
const int multiplier = 10;
var pipsDiffSl = (entryPrice - stopOrTpPrice) / minPriceVariation / multiplier;

var pipPrice = minPriceVariation / entryPrice * maxOrderSize * multiplier;
var slValueInMoney = pipsDiffSl * pipPrice;

//const int desiredAmoutnToLose = 10;
var newPipValue = desiredAmountToLose * pipPrice / slValueInMoney;
var newMinimalOrderSize = (newPipValue * entryPrice) / (minPriceVariation * multiplier);
newMinimalOrderSize = Math.Round(newMinimalOrderSize, 0);

return newMinimalOrderSize;
}