MQL5 OrderCalcProfit()
Works out the profit or loss, in the account's currency, of a trade opened at one price and closed at another, on the account and market as they stand.
Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.
This is an MQL5 function, not an HTTP endpoint. It has no method, no path and no address to send a request to: it runs inside the MetaTrader 5 terminal, in a program written in MQL5.
This is arithmetic on prices you supply. It predicts nothing.
Signature
The form of the call on the vendor's page, with the vendor's comments taken out.
bool OrderCalcProfit( ENUM_ORDER_TYPE action, string symbol, double volume, double price_open, double price_close, double& profit )
Arguments
| Name | Type | Description |
|---|---|---|
| actionrequired | ENUM_ORDER_TYPE | The order type. The page allows two values of ENUM_ORDER_TYPE here: ORDER_TYPE_BUY or ORDER_TYPE_SELL. |
| symbolrequired | string | The symbol's name. |
| volumerequired | double | The volume of the trade. |
| price_openrequired | double | The opening price. |
| price_closerequired | double | The closing price. |
| profitrequired | double& | The variable that receives the calculated figure when the function succeeds. |
Return value
- Type
- bool
- What comes back
- True on success, false otherwise, and false for an order type that is not allowed. On failure the page points to GetLastError() for the reason.
Sample
Written by this site from the signature and arguments recorded on this page. It has not been run against a terminal, a server or an account, and the values in it are placeholders. It holds no credential and needs none: the program runs inside a terminal that is already logged in to an account. Nothing is entered on this site.
void OnStart()
{
double profit=0.0;
if(OrderCalcProfit(ORDER_TYPE_BUY,_Symbol,0.1,1.1000,1.1050,profit))
PrintFormat("result: %.2f",profit);
else
PrintFormat("OrderCalcProfit error %d",GetLastError());
}