How can I find the lot size for a trade for a given Symbol, desired profit and stop loss / take profit value?

 

Hi,

I have the following situation:

Given Symbol, the desired profit (let's say 20 USD) and :

double spread  = MarketInfo(Symbol(), MODE_SPREAD);

double stopLoss = Bid - 30; //30 pips

double takeProfit =Bid +spread +30; //30 pips

How can I calculate the lot size for a potentially buy or sell order so the profit / loss to be  = desired amount (20 USD)

Do I need to use a huge switch (for any Symbol) or maybe there is a better solution instead ?

Many thanks,

 

At once correct.

double stopLoss = Bid - 30 * _Point; //30 pips

double takeProfit =Bid + (spread + 30) * _Point; //30 pips

You can try it like this

double newLot = 20 / (spread + 30) / SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_VALUE);