Download CloseIfProfitorLoss

Download The X Universal EA
Download EA Duplicator
Download The X Universal EA
Download EA Duplicator
Download CloseIfProfitorLoss
Download CloseIfProfitorLoss
11098 Downloads

 

 

 

CloseIfProfitorLoss (CLP)-Closing positions in MetaTrader when the total profit/loss is reached, with the profit trailing function.

Virtual stops can be enabled as a separate order, and calculations and closing can be done separately for BUY and SELL positions.

 

The Utility CloseIfProfitorLoss (CLP) is an advanced feature in MetaTrader that allows traders to automatically close their positions when the total profit or loss reaches a certain level.

Additionally, this feature comes with a profit trailing function, which enables traders to set virtual trailing stops and take profits.

Essentially, this means that the trader can set the system to automatically close their position at a specific level of profit or loss without having to monitor the trade constantly.

This feature can be a valuable tool for traders who want to manage their risk more effectively and optimize their trading strategies.

Main Documentation Settings FAQ 

Changelog Reviews Comments Extra

 

Changelog:

Version 24.426 2024.04.26

– CLP tab: with AutoCorrect_LevelCLP = false, you can work with negative trailing profit!
You can set trailing profit to be triggered from the minus zone.

Please set AutoCorrect_LevelCLP = false in the EA settings.

Example:
Loss = -100 USD
Profit = 10 USD
Trailing Profit = 100 USD
Price moves in my direction = +10 USD
New Loss = -90 USD
If the price moves against me, I will have lost 90 USD instead of the initial 100 USD.

Version 24.419 2024.04.20

– Optimization of the “Show Profit on History” function
– Added CLP tab settings to the Trade Pad external parameters.
Because MetaQuotes prohibits sending global variables to the VPS server from MQL (MetaQuotes), all buttons, checkboxes, edit fields, and controls on the Trade Pad panel no longer work on VPS from MQL (MetaQuotes).
You can customize the function of closing by total profit or loss from the external settings of the Utility:
Attention! If the VPS_CLP_Activation parameter is enabled (true), then All settings for this function will work from external variables!
Objects on the CLP tab – will be inactive!

e05vps=”================= VPS MQL5 CLP options ==================”;//———————————————————————————————————
VPS_CLP_Activation=false;//VPS_CLP_Activation –> CLP activation for VPS
VPS_CLP_AllSymbols=false;
VPS_CLP_CurrentSymbol=false;
VPS_CLP_SeparateBUYSELL=false;
VPS_CLP_SeparateDEALS=false;
e060=”===================================”;//———————————————————————————————————
VPS_CLP_Profit_Currency=false;
VPS_CLP_Profit_Currency_amount=0;
VPS_CLP_Profit_Pips=false;
VPS_CLP_Profit_Pips_amount=0;
VPS_CLP_Profit_Percent=false;
VPS_CLP_Profit_Percent_amount=0;
e061=”===================================”;//———————————————————————————————————
VPS_CLP_Trailing_Profit_Currency=false;
VPS_CLP_Trailing_Profit_Currency_amount=0;
VPS_CLP_Trailing_Profit_Pips=false;
VPS_CLP_Trailing_Profit_Pips_amount=0;
VPS_CLP_Trailing_Profit_Percent=false;
VPS_CLP_Trailing_Profit_Percent_amount=0;
e062=”===================================”;//———————————————————————————————————
VPS_CLP_Loss_Currency=false;
VPS_CLP_Loss_Currency_amount=0;
VPS_CLP_Loss_Pips=false;
VPS_CLP_Loss_Pips_amount=0;
VPS_CLP_Loss_Percent=false;
VPS_CLP_Loss_Percent_amount=0;

Version 24.124 2024.01.24

Compilation in the latest terminal build.
Long Ticket Number: Fixed CLP Trail Profit error when working with brokers with long ticket numbers.

Version 23.913 2023.09.18

——————————
-Last Build Compilation
-EAPADPRO v44

Version 22.111 2022.01.12

Update repeat

Version 22.110 2022.01.12

Исправлекна ошибка рисования объектов для новых версий терминала MT5

Version 21.956 2021.11.14

Code optimization and General improvements and bug fixes as reported by users.

Version 20.952 2020.10.22

– Added parameter to CLP (Closing on total profit and loss) settings:
— CPL_CloseAllCharts_per_CloseAllDeals = close charts / other charts before closing positions.
— This parameter allows us to solve the problem when our panel begins to close positions upon reaching the total profit or loss, and in the meantime, other experts simultaneously begin to open new positions.
— The CPL_CloseAllCharts_per_CloseAllDeals parameter closes only those charts on which other Expert Advisors are installed (except for VirtualTradePad) only for MT5.
— The CPL_CloseAllCharts_per_CloseAllDeals parameter closes All charts (When All Symbols is enabled) or only those with a chart symbol = VirtualTradePad symbol.
— The CPL_CloseAllCharts_per_CloseAllDeals parameter saves chart templates before closing them! The template can be downloaded later. Template name: VTP_Symbol_Period_Name of the expert (only for MT5).
Important:
— In MT5: Only those charts on which the Expert Advisor is installed are closed in MT5

Version 20.608 2020.06.08

Перекомпиляция 2485

Version 20.423 2020.04.23

-In the CLP_Alert CLP_Push Notification, the name of the currency pair with which the program works has been added.
-In the CLP_Alert CLP_Push Notification, the name of the currency pair, position type and lot of the closed position are added.

Version 20.206 2020.02.09

=================================================== =====================================
— Added opportunity to use Expert Adviser on Forex VPS for MetaTrader 4/5 from MetaQuotes
It works on any chart. Supports multiple chart at once!
Tabs work: CLP, TrailinStop, Signals!
Before changing the variables on your computer:
1. Enable AutoTrading to make the Expert Advisor active.
2. change the parameters,
3. After that, start the Migration!
=================================================== =====================================
– Added Risk Manager: Risk Manager Limiting losses / profits / Lots / Numbers
Block Limiting updated and supplemented!
This settings block allows users to limit Profit / loss / lots / number of deals/positions for a specified time.
A risk manager who monitors your trading and notifies you that the time limit has been exceeded with Current positions / today / week / month / all the time.

Settings:
CurrentOpenDeals – Take into account current open deals/positions;
ClosedDeals – Take into account closed deals / positions over time:
LimitFor – The time during which closed deals / positions in the history will be checked;
LimitForLosses – Loss limit at which the EA will sent a message, must be specified with -;
LimitForProfits – Profit limit at which the EA will sent a message;
LimitForLotsDeals – Limit of Lots of deals / positions, at which the adviser will sent a message;
LimitForCountDeals – Limit of the number of deals / positions at which the EA will sent a message;
NotificationMailSend – Send a message to the phone (PUSH) and mail if the limit is exceeded;

Version 20.129 2020.01.29

Исправлено завсиание при сворачивании

Version 20.127 2020.01.27

TesterHideIndicators

Version 20.125 2020.01.27

— Forced writing global variables to disk.
— Color of TrailingStop and CLP in the ON mode – is changed to green.
– The version for the MetaTrader 5 terminal now can use scrolling (on the mouse):
If you hover over the field for editing the parameter (lot, stop loss, take profit, distance, CLP), then when scrolling with scrolling, you can increase or decrease the value in this field!
Note: Only for MetaTrader 5!
Note: Scrolling of the chart is disabled if the cursor is on the area of our VIRTUALTRADEPAD panel and is enabled if the cursor is outside the VIRTUALTRADEPAD area.

Version 20.110 2020.01.10

Added CLP: New parameter Use_Commission_in_CLP – Use calculation of commission when closing positions.
true – take into account the commission in the calculations.
false – do not take into account the commission in the calculations.
Attention: The commission is calculated from an open deal and multiplied by 2 (When closing a deal a commission is also charged)
This is the standard way to calculate commission!
In MetaTrader 5, it is impossible to get the type of commission calculation from an adviser!
If you do not want the adviser to automatically calculate the commission, you can turn off this feature!
Attention! This function only affects the calculations on the CLP tab, all other tabs work in standard mode, taking into account commissions.

Version 19.992 2019.12.15

CLP – Обновлен расчет прибыли для CFD, Index

Version 19.991 2019.12.02

CLP: Fixed display of future levels (Show_Future_BE_TP_SL) for BUY positions.
CLP: The Show_Future_BE_TP_SL function has been added to show future profit / loss lines when closing is selected as a percentage of the current balance.
CLP: Added a new parameter to the “CLP options” section:
ClosebyFIFO = Closing positions according to FIFO rules;
When closing positions, the FIFO rule will be used (First opened, First closed).
The position will be closed in the order of their opening!
Attention: This rule is intended to be used only when working with all symbols and closing all positions at once.
Attention: This mode prohibits the use of functions: Separate Deals

Version 19.830 2019.08.31

Update for Separate Order

Version 19.824 2019.08.26

Fixed Virtual CLP error when the list of orders was not updated.

Version 19.701 2019.07.06

– A new parameter has been added to the function “Closing by total profit or loss”:
ClosingCurrentTicketOnly – Close only the current list of tickets.
This option will help to avoid problems when my program starts to close positions on the basis of total profit, and the user’s adviser starts to open new positions.
ClosingCurrentTicketOnly = true, Then the VirtualTradePad program, if the total profit conditions are met, will close the current list of positions. If new tickets are added to the list of positions, the VirtualTradePad program will ignore them.
ClosingCurrentTicketOnly = false, Then the VirtualTradePad program, if the total profit conditions are met, will close all positions, even if another adviser opens new positions.

Version 19.228 2019.02.26

Fixed a percentage value profit on the CLP tab when the user did not press Enter to save parameters.

Version 19.226 2019.02.26

Общие улучшения

Version 19.211 2019.02.11

Fixed the error of moving the graph when the panel is minimized!

Version 19.206 2019.02.06

– In the CLP block, when closing positions by profit in points, the profit in the deposit currency will be additionally checked.
Actual when closing positions with different volume of lots.
If the adviser can close positions by profit in points, but the profit in the deposit currency is less than 0, then the adviser will not close the position, but will wait for the positions to gain profit in the deposit currency> 0.
– Text labels with information about open positions are reduced, to save space.
– Cosmetic enhancements.

Version 19.201 2019.01.30

Global Update 2019
– Improved graphics part of the panel. Re-design of individual elements;
– Added the ability to resize the panel: GeneralSize!
– GeneralSize default = 12, Increasing the size of the panel.
– Last panel size with GeneralSize = 10!
– Text labels of open positions optimized. Fixed error when text labels were drawn on top of the VirtualTradePad panel;

Version 19.121 2019.01.21

Some graphical changes.

Version 19.114 2019.01.17

Global Update 2019:
– When using CLP_DeleteStopOrders = true and the CloseALL buttons, the choice of characters to close is taken into account (All symbols, only the current one);
– Added hints to external variables when setting up the program;
– Added language selection tips Language: Spanish, Portuguese (Brazil), German, Chinese, Japanese;
By default, the language of prompts will be determined automatically by the language of your terminal. You can also choose your language;
The translation was made using the GOOGLE Translator + MQL + Terminal site!
If you find an error in your language, please report it in messages. Thank!
– Parameter and function Sounds replaced by a more advanced function from our EAPADPRO
Added new parameters:
Notice_Open_Push = false;
Notice_Open_Sound = true;
Notice_Close_Push = false;
Notice_Close_Sound = true;
Notice_Modify_Push = false;
Notice_Modify_Sound = true;
Notice_Error_Push = false;
Notice_Error_Sound = true;
Notice_Open_NameSoundFromEa = “ok”;
Notice_Close_NameSoundFromEa = “alert2”;
Notice_Modify_NameSoundFromEa = “stops”;
Notice_Error_NameSoundFromEa = “timeout”;
You can enable / disable sound when opening, closing, modifying, error, as well as specify the name of the sound file (without .wav)
You can also enable notification to the phone (PUSH messages) when opening, closing, modifying, an error.
Additional information is displayed in the log.
– The ShowInfoPosition function has been updated; now the position information on the chart will not overlap our panel. Dynamic change of coordinates of information data on a chart.
– Font name changed to Roboto

Version 18.945 2018.10.18

The parameters of the number of attempts to close and open positions using one-click trading are added in external variables:
NumberTryClose – The number of attempts to close a position.
When receiving an error from the server, the adviser tries to open / close.
Required with frequent requotes.

CLP Activation (Close if Profit or Loss Activation) Changed!
ON OFF buttons are added to the panel for more understandable action!

Version 18.932 2018.10.01

– Added support for the work of the Expert Advisor and the CLP tab (Closing on Total Profit or Loss) on VPS hosting from MetaQuotes.

Version 18.515 2018.05.23

– Fixed the error with profit trailing and closure at a loss, which occurred when using the closing on all symbols.

– Added a variable for specifying the currency pair for the panel to work with: SymbolToTradeCustom
This allows working on offline charts (Tick charts, Renko charts, etc.).
Attention: Be careful when writing the name. The name should exactly match the name in the Market Watch!
EurUSD – incorrect!
EURUSD – correct!
If this parameter is not set, the EA works on the currency pair it is attached to.

– Added the ability for Magic Target to work on an offline (Tick, Renko…) chart.

– Added the indication of the feature operation to the CLP tab.
If the indication is red, the feature is disabled and does not work;
If the indication is green, the feature is enabled and working.

Version 18.309 2018.03.14

Fixed an error in the Close ALL button.

Version 18.227 2018.03.06

– Added support for font scaling in Windows (font size settings are not available);

– Added support for multiple magic numbers. Updated the MagicNumber parameter: the first number denotes the magic number for opening positions and management. It is also possible to set multiple magic numbers to be managed;
For example:
— MagicNumber=777 UseAllMagicFromAllAccount=true: the EA monitors all positions on the current symbol and on the entire account;
— MagicNumber=777 UseAllMagicFromAllAccount=false: the EA monitors positions with the magic number 777 on the current symbol and on the entire account;
— MagicNumber=777,888 UseAllMagicFromAllAccount=false: the EA monitors positions with the magic numbers 777 and 888 (opens positions with the magic number 777) on the current symbol and on the entire account;
— MagicNumber=777,888,999 UseAllMagicFromAllAccount=false: the EA monitors positions with the magic numbers 777, 888 and 999(opens positions with the magic number 777) on the current symbol and on the entire account;

– When a new object appears on the chart, the panel is refreshed to avoid overlapping of objects on the panel;

Version 17.979 2017.12.12

Cosmetic changes.

A new parameter has been added: CPL_AUTOOFF_AfterClose allows disabling the “Close if profit or loss” button after closing all positions.
The button is only disabled when ALL! positions are closed.
It takes into account the magic number specified in the EA, as well as the symbol for closing.
If closing only 1 currency is selected and the CPL_AUTOOFF_AfterClose parameter is enabled, the EA waits for all positions on the given currency pair to be closed, and can disable the button only after that!

BugFix: Fixed dragging of trade levels (Stop Loss, Take Profit) when hovering over the panel and back.

Version 17.970 2017.11.13

In the EA settings, changed the option for closing the terminal after all trades are closed.
Parameter CPL_CloseTerminalAfterClose – enable closing the terminal.
CPL_CloseTerminalAfterClose = true.
Terminal is closed only when ALL! positions are closed.
It takes into account the magic number specified in the EA, as well as the symbol for closing.
If closing only 1 currency is selected. If the CPL_CloseTerminalAfterClose parameter is enabled, the EA waits for all positions on the given currency pair to be closed, and cab close the terminal only after that!

Added the Show_Future_BE_TP_SL parameter to CLP – show the lines of the future position closure by total profit or loss.
Attention: it works only on the current symbol and with the ‘SEPARATE Orders’ mode disabled.
The lines are displayed separately for Buy and Sell positions, or by a common line.
If a line is not shown, then the positions form a lock that cannot be closed by the total profit or loss.
Note: line and price data may be inaccurate for floating spread.
Remember! SELL is closed by ASK, while BUY is closed by BID

Profit trailing can now be enabled only after setting the parameters for closing by profit.

Added the profit trailing values on the CLP panel near the input box for the distance of Trailing Profit. The value appears when the trailing level is fixed by the EA and shows the fixed level for closure.

Added block of alerts for profit and loss in the deposit currency.
If you want to limit the losses on the current client magic number, you can do that in the new block.
For example: you need the EA to send you emails and display on-screen alerts when the total loss of open and closed trades within LimitFor becomes less than -100 USD:

Set the parameters to the following:
LimitFor=0;
LimitForLosses=-100;
LimitForProfits=0;

After receiving the daily loss of -100 USD in history for the given magic number, the EA displays an on-screen alert and sends an email.
Attention: this block does not close trades! It simply displays alerts!
At the next LimitFor, this parameter is reset to 0.

You can select LimitFor= DAY;WEEK;MONTH;ALLTIME;
You can also enable sending email and push notifications when reaching the limits of NotificationMailSend

To the CLP panel for closing by profit or loss, added a block of notifications when closing positions by profit or loss. 3 notification methods are available:
CPL_AlerT – alert message
CPL_Mail – email message
CPL_Push – push notification
How to set up mobile device or email to messages from the Expert Advisor:
https://www.metatrader4.com/en/trading-platform/help/setup/settings_notifications
https://www.metatrader4.com/en/trading-platform/help/setup/setup_email

the MagicOrderToClose parameter has been replaced by 2 parameters:
MagicNumber – unique magic number of positions to close.
UseAllMagicFromAllAccount:
true = apply the function of closing by total profit or loss to all magic numbers.
false = set the unique magic number for closing positions in the MagicNumber parameter.

Version 17.504 2017.05.11

– Fixed the error with the display of fractional numbers on the CLP panel: when entering fractional numbers in the fields Dollars, Percents and Profit trailing

Version 17.118 2017.01.24

Fixed operation with long tickets

Version 17.105 2017.01.13

-Added parameter Use_Lots_in_CLP_Points for working with the CLP tab – true – the EA will also consider the lot of those positions during calculation of profit points. This option can be useful in trading on a hedging account with different lots.

For example:
opened 2 SELL positions on EURUSD
SELL 0.01 with profit of 20 and 0.2 USD
SELL 0.02 with loss of -12 points -0.24 USD

-If Use_Lots_in_CLP_Points = false the EA will calculate the “net” points.
In this case, the Profit will be: -0.04 USD or 8 points.
As we can see, the position gained profit in points, but it is a loss in USD.

-If Use_Lots_in_CLP_Points = true the EA will calculate points with consideration of lots.
In this case, the profit will be: -0.04 USD or -4 points.
If calculation of profit is in points and the “Include lots in profit calculation” is enabled,
the EA will find the minimum lot of the provided positions and calculate the Points on that basis.
For example:
Minimum position 0.01, 1 “net” point = 1 point,
If a position is opened with a lot of 0.02, then 1 net point = 2 points with consideration of the lot.
If a position is opened with a lot of 0.05, then 1 net point = 5 points with consideration of the lot.

-Added checking of the input values for closing profit or loss:
If the specified profit is lower than the current – system generates a warning and disabled the closure mode.
If the specified loss is greater than the current – system generates a warning and disabled the closure mode.
If set to 0 and user attempts to enable closure – system generates an error.
-Added the AutoCorrect_LevelCLP parameter:
Only negative values can now be entered to the loss field. If user enters +10, the system automatically converts it to -10.
Only positive values can now be entered to the profit field. If user enters -10, the system automatically converts it to +10.

Only a positive value can be entered in the CLP_TralOptions, otherwise the EA generates an error.

-Added the SEPARATE Orders option to the CLP panel for separate calculation and deletion of each position.
“Virtual Stop Loss and Take Profit” mode.
For example, if you set closure by loss to $ -5 and closure by profit to 100 points, each trade will be closed separately by a loss of $ -5 or by profit of 100 points.

-Added the Separate BUYSELL option to the CLP panel, which allows to calculate a close positions by the net profit or loss separately for BUY and for SELL.

Version 16.930 2016.10.03

Updated the algorithm for working on hedging accounts
Fixed the error in the TrailingProfit edit box

Version 16.128 2016.02.01

Added the function to save the settings during the terminal reboot, the change in settings inside the panel, when closing the panel on the chart and attaching the panel to the chart.
All variables and data changes made in the panel are now saved when the terminal is restarted.
If you turn off the terminal and turn it on again – all the parameters will be re-loaded from the global variables.

Added the TrailingProfit function to the CLP tab:
Trailing Stop at Closing.
A new function for trailing profits has been implemented on user demand. In this case, the profit is fixed with some correction. As soon as the profit reaches the specified value, the Expert Advisor saves the current profit level and starts trailing the profit.

For example:
If you made settings for closing at the profit of 10 dollars:
Profit $ – positive closing.
Profit $ – value of positive closing.
TrailingProfit- distance from Profit $, which, when reached, triggers trailing of profit.
If Profit $ is set to 10 and TrailingProfit is set to 5 the Trailing Stop will be set at 5 dollars. The Trailing Stop will come into play when the Expert Advisor passes the 10 dollar line and start moving following the profit. The Journal will show entries about the current profit status.
When the total profit falls below the last fixed level, TrailingProfit, the Expert Advisor will perform forced closing of all position.

The function works for all closure types: Every symbol, Current symbol, Separate BUY and SELL direction, Each order separately.

Version 15.923 2015.09.24

Fill policy parameter has been added to the external parameters:
TypeFilling=FillOrKill

FillOrKill
This fill policy means that an order can be executed only with the specified volume. If the required volume for a given financial instrument is currently unavailable in the market, the order will not be executed. The required volume can be filled using several offers currently available in the market.

ImmediateOrCancel
This means that a trade will be executed with the maximum volume available in the market within the value indicated in the order. In case entire order volume is not available in the market at the moment, a partial fulfillment is possible, but any portion that cannot be filled immediately is canceled.

Return
This fill policy is used for market, Limit and Stop Limit orders and only in the Market Execution and Exchange Execution modes. In case of partial filling a market or Limit order with remaining volume is not canceled but processed further.
When a Stop Limit order triggers, a relevant Limit order will be placed with the Return fill policy.

Version 15.116 2015.01.16

In case of incorrect settings, the Close button will be disabled and an error will be returned to the user.

Version 15.112 2015.01.13

Added check of input data before the start of algorithm operation. Protection against incorrect settings.
For example, if you specify the loss of more than the current one – the system will not allow you to perform the algorithm. Since the positions must be closed immediately.
For example: You have indicated close loss at 2 dollars. Currently loss is -3 dollar. This means that you obviously specified closing level below the current one. And the system will immediately close the position.
In this version, the system returns an error and asks you to enter another value.

If your сurrent loss is -5 dollars, you can set the loss value only -5.1 or below.

If you have a current profit of $10 and you want to set it to $5 – the system will return an error. You can set the value for locking the profit only above the current profit. For example, $11.

Version: 24.918

This post is also available in: English Українська Portuguese Español Deutsch Chinese Русский Français Italiano Türkçe 日本語 한국어

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.


     

    Risk Warning:


    Past trading performance does not guarantee future results.

    Trading foreign exchange on margin carries a high degree of risk and may not be suitable for all investors.

    Be aware that using trading robots involves substantial risk, and you could lose more than your initial investment.

    Please proceed with caution, assess your financial situation carefully, and consider seeking advice from a qualified professional.

    Disclaimer

    This website uses cookies to improve your experience. By using this website you agree to our Data Protection Policy and Disclaimer.
    Read More