It is not correct to use the == condition for variables of type double. It is recommended to compare like this:
I can add to that, that although with some delay, we still wrote an article on this topic - Features of working with numbers of type double in MQL4. Everything mentioned there will still be relevant for any programming language when it comes to operations with real numbers (double and float in MQL5).
joo: Not enough op. memory. Check the size of the dynamic arrays, most likely an attempt to allocate more memory than is available.
No, that's not it. It's probably something with the servers. There's probably some work going on. A hole has appeared in the data. The connection to the server is often lost. The history is not being downloaded.
sergey1294: That's not the point of the question. If I understood it correctly, the operator return must always be placed at the end of the user function
I think the answer about == was essentially. There really should be a return(...) somewhere in a function of type double. Not necessarily at the end. Using == operator in if() return(); may cause false output if you have the LotStep type 0.1000000000000000001. In this case none of the returns will work and the function returns nothing. Although in your case the return probably does not like NormalizeDouble inside. In your version that works, fix the end to return(NormilizeDouble(lot,2)) and see if it works. I'm curious about it myself.
I think the answer about == was essentially. There really should be a return(...) somewhere in a function of type double. Not necessarily at the end. Using == operator in if() return(); may cause false output if you have the LotStep type 0.1000000000000000001. In this case none of the returns will work and the function returns nothing. Although in your case the return probably does not like NormalizeDouble inside. In your version that works, fix the end to return(NormilizeDouble(lot,2)) and see if it works. I'm curious about it myself.
There must be return(...) at the end, but it may never get there (if one of the If conditions works)...
The mistake is that you forgot about the margin currency in your calculations. Balance = 100 USD and margin requirement = 100 EUR (119 USD).
That's why the operation cannot be performed - everything is correct.
I want to get back to my question about correct margin calculation. As Renat noticed in my calculations, LotRqdMgn (margin required to buy 1 lot) does not take into account the price of the currency. I remember having seen this table
Identifier
Description
Formula
SYMBOL_CALC_MODE_FOREX
Forex mode - calculation of profit and margin for Forex
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
It is not correct to use the == condition for variables of type double. It is recommended to compare like this:
It is not correct to use the == condition for variables of type double. It is recommended to compare like this:
Quite reasonable, and most importantly a sensible approach. But it seems to me that at least the first line should have looked like this:
I get these messages in the log from time to time
2010.06.15 14:48:09 MemoryException 4915200 bytes not available
I don't know what to do ?
I get these messages in the log from time to time
2010.06.15 14:48:09 MemoryException 4915200 bytes not available
I don't know what to do ?
It is not correct to use the == condition for variables of type double. It is recommended to compare like this:
Not enough op. memory. Check the size of the dynamic arrays, most likely an attempt to allocate more memory than is available.
That's not the point of the question. If I understood it correctly, the operator return must always be placed at the end of the user function
I think the answer about == was essentially. There really should be a return(...) somewhere in a function of type double. Not necessarily at the end. Using == operator in if() return(); may cause false output if you have the LotStep type 0.1000000000000000001. In this case none of the returns will work and the function returns nothing. Although in your case the return probably does not like NormalizeDouble inside. In your version that works, fix the end to return(NormilizeDouble(lot,2)) and see if it works. I'm curious about it myself.
I think the answer about == was essentially. There really should be a return(...) somewhere in a function of type double. Not necessarily at the end. Using == operator in if() return(); may cause false output if you have the LotStep type 0.1000000000000000001. In this case none of the returns will work and the function returns nothing. Although in your case the return probably does not like NormalizeDouble inside. In your version that works, fix the end to return(NormilizeDouble(lot,2)) and see if it works. I'm curious about it myself.
There must be return(...) at the end, but it may not come to it (if one of the If conditions works)...
Renat:
The mistake is that you forgot about the margin currency in your calculations. Balance = 100 USD and margin requirement = 100 EUR (119 USD).
That's why the operation cannot be performed - everything is correct.
I want to get back to my question about correct margin calculation. As Renat noticed in my calculations, LotRqdMgn (margin required to buy 1 lot) does not take into account the price of the currency. I remember having seen this table
Identifier
Description
Formula
SYMBOL_CALC_MODE_FOREX
Forex mode - calculation of profit and margin for Forex
Margin: Lots*Contract_Size/Leverage
Profit: (close_price-open_price)*Contract_Size*Lots
SYMBOL_CALC_MODE_FUTURES
Futuresmode - calculation of margin and profit for futures
Margin: Lots *InitialMargin*Percentage/100
Profit: (close_price-open_price)*TickPrice/TickSize*Lots
SYMBOL_CALC_MODE_CFD
CFD mode - calculation of margin and profit for CFD
Margin: Lots *ContractSize*MarketPrice*Percentage/100
Profit: (close_price-open_price)*Contract_Size*Lots
SYMBOL_CALC_MODE_CFDINDEX
CFD index mode - calculation of margin and profit for CFD by indexes
Margin: (Lots*ContractSize*MarketPrice)*TickPrice/TickSize
Profit: (close_price-open_price)*Contract_Size*Lots
SYMBOL_CALC_MODE_CFDLEVERAGE
CFD Leverage mode - calculation of margin and profit for CFD at leverage trading
Margin: (Lots*ContractSize*MarketPrice*Percentage)/Leverage
Profit: (close_price-open_price)*Contract_Size*Lots
So it turns out that there is an error in the table: instead of Lots*Contract_Size/Leverage, it must be Price*Lots*Contract_Size/Leverage.