Please**, always **use the **CODE button (Alt-S)** when inserting code.

For now, your topic has been moved to the section: Expert Advisors and Automated Trading

Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893

**darkcanvas:**I have a couple of scripts that calculate the lot size depending on risk % and SL distance. Is there a way to somehow work out if I'm calculating lot size for a forex pair, or for an Index. I get the point from SymbolInfo ... which works for forex pairs. Then I put this line of code to get the "correct" point value for NAS100: I only trade Nas100, so it works for this index, but I think that there may be a better way to do it.

The easiest and best way to calculate the lot size, is to use the OrderCalcProfit function.

It will automatically adjust based on the asset class of the symbol, namely the SYMBOL_TRADE_CALC_MODE (see ENUM_SYMBOL_CALC_MODE for more details about the different asset class calculations being used).

Forum on trading, automated trading systems and testing trading strategies

SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE) sometimes zero

Fernando Carreiro, 2022.08.23 17:41

You can! These are the steps I take. I supply the function with a lot size equal to the “Max Lot Size” allowed for the symbol in question, then calculate the ratio needed to achieve the fractional risk that I wish to apply, to get the correct volume for the order. I then align that with the “Lot Step” and finally check it against both the maximum and minimum allowed lots for the symbol.

The reason I use the “maximum” lots instead of just “1.0” lots as a reference value is because there is no guarantee that the value of 1.0 is within the minimum and maximum values allowed. Given that using 1.0, or the maximum, gives equivalent results anyway (by using the ratio method), I choose to use the “max lots” as the reference point which also offers the most precision for the calculation.

Something like this ...

// This code will not compile. It is only a example reference if( OrderCalcProfit( eOrderType, _Symbol, dbLotsMax, dbPriceOpen, dbPriceStopLoss, dbProfit ) ) { dbOrderLots = fmin( fmax( round( dbRiskMax * dbLotsMax / ( -dbProfit * dbLotsStep ) ) * dbLotsStep, dbLotsMin ), dbLotsMax ); // the rest of the code ... };

- www.mql5.com

**Fernando Carreiro #:**

The easiest and best way to calculate the lot size, is to use the OrderCalcProfit function.

It will automatically adjust based on the asset class of the symbol, namely the SYMBOL_TRADE_CALC_MODE (see ENUM_SYMBOL_CALC_MODE for more details about the different asset class calculations being used).

Thanks Fernando,

I found your piece of code before in this forum and currently testing it in my code.

However, I also have a function that sets up a Break Even level... for that I have to know how to calculate the distance...

Say, to move SL to break even after 20 pips... is it 200 points for XAUUSD or 2000 points for NAS100...

I was hoping that there is a function that will work out if I multiply by 10 or 100.

If there isn't it's OK... my primitive solution still works. Even if only for the explicitly defined indices.

J

**darkcanvas #:**However, I also have a function that sets up a Break Even level... for that I have to know how to calculate the distance... Say, to move SL to break even after 20 pips... is it 200 points for XAUUSD or 2000 points for NAS100... I was hoping that there is a function that will work out if I multiply by 10 or 100. If there isn't it's OK... my primitive solution still works. Even if only for the explicitly defined indices. J

Don't think in "pips". Pips was mostly used in Forex only.

Each symbol is different so forget "pips"! Only work with "points" or in "ticks" (or in actual price quote difference).

NB! My example code is in actual price quote difference.

**Fernando Carreiro #:**

Don't think in "pips". Pips was mostly used in Forex only.

Each symbol is different so forget "pips"! Only work with "points" or in "ticks" (or in actual price quote difference).

NB! My example code is in actual price quote difference.

Cool,

Thank you very much for this. I think I understand the method of calculating lot size.

Now ... for the other problem.

Does mql5 have a method to work out if a symbol is an Index?

I want to replace the following IF statement with a function that does the same for ALL indicies.

if (Symbol()=="NDXUSD"|| Symbol()=="USTEC"|| Symbol()=="USTEC.a"|| Symbol()=="NAS100") {point = point*10;}

Something like:

`If(ThisIsAnIndex()) {point = point*10}`

For example

If I have an EA that looks for trades without a stop loss.

If it finds one, I want it to add a SL of 200 points for a forex pair, but 2000 points for an index.

J

**darkcanvas #:**Does mql5 have a method to work out if a symbol is an Index?

You are ignoring the information given to you ... *"the asset class of the symbol, namely the SYMBOL_TRADE_CALC_MODE (see ENUM_SYMBOL_CALC_MODE for more details about the different asset class calculations being used)"*

*"Don't think in pips "*... so, stop multiplying by 10.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets

You agree to website policy and terms of use

I have a couple of scripts that calculate the lot size depending on risk % and SL distance.

Is there a way to somehow work out if I'm calculating lot size for a forex pair, or for an Index.

I get the point from SymbolInfo ... which works for forex pairs.

Then I put this line of code to get the "correct" point value for NAS100:

I only trade Nas100, so it works for this index, but I think that there may be a better way to do it.