-->

Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

Metatrader 5 Libraries | nProfit and Loss Positions | MQL5 Community Release

RobotFX curates the best open-source MetaTrader code to inspire your trading automation.


Profit_and_Loss_Positions - Position Profit/Loss Calculator

Purpose

Plug-in file for calculating the total profit or loss of trading positions with filtering by type and Magic Number.

Main function

Profit_Position(string p_l, string type_pl, long magicNumber)

Calculates the total profit or loss of positions.

Parameters:

  • p_l - calculation type: "Profit" ( profit) or "Loss" ( loss)

  • type_pl - type of positions: "All" , "Buy" , "Sell" , "Sell"

  • magicNumber - filter by magic number (0 = all)

Returns: total profit/loss in deposit currency

Examples of use

// Profit sum of all items
double profitAll = Profit_Position("Profit", "All", 0);

// The amount of loss of BUY positions of the Expert Advisor with magik 123
double lossBuy = Profit_Position("Loss", "Buy", 123);

// The amount of profit of SELL positions
double profitSell = Profit_Position("Profit", "Sell", 0);

Practical application

For traders:

  • Monitoring current results

  • Analyse the effectiveness of strategies

  • Riskcontrol

For developers:

  • Riskmanagement in experts

  • Creating trade reports

  • Implementing closing conditions

Features

  • Works only in MetaTrader 5

  • Supports Magic Number filtering

  • Returns amount in deposit currency

  • Efficient position override

How to connect

#include <Profit_and_Loss_Positions.mqh>

// Use in expert code
double currentProfit = Profit_Position("Profit", "All", 123456);

Smooth out market noise with the Heiken Ashi Expert Advisor for MT4 and MT5. Reliable trend-following automation. Details here.

Level up your trading with professional RobotFX expert advisors and indicators. Visit www.robotfx.org for proven MT4/MT5 tools.

68505

Best MetaTrader Indicators + Profitable Expert Advisors