Trying calculate trade result / OrderCalcProfit

 

Hi,

I am pretty new to programming MQL, although I have quite some experience in programming in general so maybe you can help me with this?

Trying to make the first steps with MQL in MT5, one obvious thing is to prepare and calculate a trade. So I come across this:

OrderCalcProfit(ORDER_TYPE_BUY,"Ger40Jun26", 1, 1000, 800, profit);

Stripped it down to the main thing. Once considering the contract size connected with the market, I would guess result could be around 5.000.

However, profit contains -2.000 when returns.

I checked some values that came across my mind:

double vmin = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
double vstep = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
int stopLevel = (int)SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL);
double point = SymbolInfoDouble(_Symbol, SYMBOL_POINT);
double tickSize = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
double tickValue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE);
int tradeCalcMode = SymbolInfoInteger(_Symbol, SYMBOL_TRADE_CALC_MODE);
double contract = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_CONTRACT_SIZE);
//double roundedSL = MathRound(desiredSL / tickSize) * tickSize;
Print("Symbol: ", _Symbol, " Min=", DoubleToString(vmin, 2), " Step=", DoubleToString(vstep, 2), " stopLevel=", stopLevel, " Point=", DoubleToString(point, 2),
   " TickSize=", DoubleToString(tickSize, 2), " TickValue=", DoubleToString(tickValue, 2), " tradeCalcMode=", IntegerToString(tradeCalcMode), " contract=", DoubleToString(contract, 2));

Result:

2026.05.19 15:28:31.311 Core 1  2026.01.20 00:00:00   Symbol: Ger40Jun26 Min=0.01 Step=0.01 stopLevel=10 Point=0.10 TickSize=0.50 TickValue=12.50 tradeCalcMode=4 contract=25.00

Just for chance trying this:

OrderCalcProfit(ORDER_TYPE_BUY,"Ger40", 1, 1000, 800, profit);

Contract size should be 1, so -200 could be appealing, but the result is -20.000. Here KI pushes me to believe there is a "EuroPerLot" Faktor which simply is 100 but can't be queried anywhere you just have to believe. Well, that's strange to me...

So I suppose there must be a rather simple (did I mention that I am quite new to this?) solution. Can you point me to it? BTW I used the search function but nothing that I found was of much help for this.

Thanks a lot,

Stephan Wöbbeking

 
Additional finding: When trying to open a trade (demo account) with minimum volume (0,25 Lot), I get the error "not enough money". Well, that's odd, in manual mode its no deal to open it, by code its impossible. So its not only the profit calculation but the trade itself. Following this, the profit calculation might be fine. But the factor of 100 as outlined above is still my problem. Still I don't know where it comes from. Any hints are welcome. Even when accompanied by "that was st*pid", I guess I can handle it.
 
Stephan Wöbbeking #:
Additional finding: When trying to open a trade (demo account) with minimum volume (0,25 Lot), I get the error "not enough money". Well, that's odd, in manual mode its no deal to open it, by code its impossible. So its not only the profit calculation but the trade itself. Following this, the profit calculation might be fine. But the factor of 100 as outlined above is still my problem. Still I don't know where it comes from. Any hints are welcome. Even when accompanied by "that was st*pid", I guess I can handle it.
To open a trade (manual or by code, it's the same), you need enough margin. What is the margin for the symbol you trade ? What is your free margin ?
 
Alain Verleyen #:
To open a trade (manual or by code, it's the same), you need enough margin. What is the margin for the symbol you trade ? What is your free margin ?

Hi, thanks for your answer as first!

Well, I know about the margin. I admit I haven't checked for it now, but I work in test mode with 10.000 EUR demo account and buying some Ger40future should be no problem. Also, the minimum amout of 0,25 then puzzles me, should be 0,01 afaik?

The main problem persists and is in connection what you say: Yes, you are right, I don't have enough margin, because the expected loss is 100 times what I plan for. And that's exactly my point, where is this factor of 100 coming from? Its not there in my real money account.

 
One more finding: Trying the same thing in "GOLD" market, works perfectly fine and as expected...