Exp SafetyLock PRO
SAFETYLOCK allows traders to avoid strong market reversals by setting an opposite order for an already opened position.
If a trader or an EA opens a position, SAFETYLOCK opens an opposite pending order for it. If the position becomes loss-making, the pending order is activated creating a lock.
The EA allows you to close the initial position, work with a trailing stop, or multiply the lot.
You can also modify the pending order Open price following the position price.
Parameters basic (Full description of the parameters in our blog)
- MilliSecondsTimerForMonitoring - the duration of algorithm execution, in milliseconds (default is 1000 = 1 second).
- SymbolMonitoring - SymbolMonitoring = ALL_SYMBOL = monitoring all symbols and all trades on the account. If you launch the Expert Advisor on any currency pair chart, it will monitor all currency pairs.
- Type_Monitoring - the type of trades for the EA to monitor, BUY SELL or ALL.
- Magic_Monitoring - the magic number of positions for the EA to monitor, you can specify multiple values separated by commas.
- Comment_Monitoring - this option filters trades for opening a locking position based on the Comment_Monitoring.
- Min_Lot_Monitoring - the minimum lot for the EA to monitor, the parameter is disabled if set to 0.
- Max_Lot_Monitoring - the maximum lot for the EA to monitor, the parameter is disabled if set to 0.
- SafetyPosMonitoring - enable monitoring of positions opened by the SafetyLock Expert Advisor.
- StopLosse - stop loss for SafetyLock pending orders.
- TakeProfite - take profit for SafetyLock pending orders.
- MNLOT - lot multiplier for pending orders.
- StopOrderDeltaifUSEe - the distance for SafetyLock pending orders.
- NumberofStopOrder - the number of SafetyLock pending orders per position.
- DistancefromStopOrders - the step of the order grid in points if you use NumberofStopOrder.
- ModifyOrdPend - enable pending order price modification based on the price movement. If enabled, pending orders will follow the price.
- ModifyOrdPend_STEP - order price modification step in pips.
- ReopenClosedSafetyOrders - reopen SafetyLock pending orders that were closed by a stop loss, if the locked position is still open.
- Close_One_if_Safety_Closed_In_Profit - close the original position if the SafetyLock position was closed with profit covering the current loss of the original position.
- Close_One_if_Safety_More_profitable - close the original position if the profitable SafetyLock position covers the current loss of the original position.
- CloseOneifStopsActive - close the position if the SafetyLock pending order triggers. Once a pending order triggers and turns into a position, the main position will be closed if this option is enabled.
- CloseSafetyPositionsifclosed - close SafetyLock activated positions after closing the main position.
- Remove_TAKEPROFIT_ofOriginalifStopsActive - delete the take profit of the original position upon the activation of the SafetyLock pending order.
- Remove_STOPLOSS_ofOriginalifStopsActive - delete the stop loss of the original position upon the activation of the SafetyLock pending order.
- Added a new block of work:
TPWCM EXTRA SETS Actions when the Source position is closed
TPWCM_Use = false; // TPWCM_Use -> Use this block
TPWCM_StopLossWhenCloseSource = 0; // TPWCM_StopLossWhenCloseSource -> Setup StopLoss after close Source
TPWCM_TakeProfitWhenCloseSource = 0; // TPWCM_TakeProfitWhenCloseSource -> Setup TakeProfit after close Source
TPWCM_TakeProfitOnlyToProfitZone = true; // TPWCM_TakeProfitOnlyToProfitZone -> Takeprofit only in Profit
TPWCM_TrailingStopUSE = false; // TPWCM_TrailingStopUSE -> Use TrailingStop after close Source
TPWCM_TrailingStop = 0; // TPWCM_TrailingStop -> Distance of TrailingStop
TPWCM_TrailingStep = 1; // TPWCM_TrailingStep -> Step of TrailingStop
TPWCM_BreakEven = false; // TPWCM_BreakEven -> Setup Breakeven after close Source
TPWCM_LevelWLoss = 0; // TPWCM_LevelWLoss -> Distance from OpenPrice to profitable SL
TPWCM_LevelProfit = 0; // TPWCM_LevelProfit -> Number of points gained by pos to use BE
- Added new filter block:
LockOnlyLossPosPoint = 0; // LockOnlyLossPosPoint -> Min loss for open Pending Order
LockOnlyProfPosPoint = 0; // LockOnlyProfPosPoint -> Min profit for open Pending Order
================================================== ================================================== =========================
TPWCM EXTRA SETS Stops when Source Close Pos
When the block is turned on: If the source is closed, then the SAFETYLOCK position will not be closed.
Instead, a trailing stop or breakeven is activated.
Those. instead of closing a SAFETYLOCK position, you have the opportunity to enable a trailing stop and follow the position further.
Trailing stop settings are separate in this case. And it turns on only when this position source is closed.
Attention: Pending orders that are not activated will be deleted!
The TPWCM block works after the initial position is closed, but the SAFETYLOCK position will not be closed and a stop loss / take profit / trailing stop will be set on it
parameter for setting the take-profit for SAFETYLOCK positions that remain after the source is closed;
After closing the source position, it is possible, without closing the SAFETYLOCK position, to set a take profit for it from the closing price of the source;
When enabled, true - the advisor sets take profit, after closing the source - only in the profitable zone.
If, after closing the source position, the SAFETYLOCK position is at a loss, then the take profit will not be set until it is in profit;
If disabled, false - the advisor will place a take profit in any case, even in a losing zone.
TPWCM_TakeProfitOnlyToProfitZone = true means that the take profit will be set only when the SAFETYLOCK position is in profit.
TakeProfit (when installed) will be in profit.
If the SAFETYLOCK position is at a loss of -30 points and you set take profit = 10 points, then when you close the source position, the take profit will be set at the level of -20 points (loss).
This function sets the take profit only when the take profit level is in profit.
the parameter for setting the stop loss for SAFETYLOCK positions that remain after the source is closed;
Enable trailing stop \ Breakeven on SAFETYLOCK positions after closing trades in the source;
difference between TrailingStopUSE and TPWCM_TrailingStopUSE
TrailingStopUSE is always used. that is, it works constantly.
If you enable it TrailingStopUSE = true, then SAFETYLOCK positions will always be with a trailing stop.
If TPWCM_TrailingStopUSE = true, then trailing stop is enabled only when the original position is closed.
Only then will the SAFETYLOCK position include a trailing stop.
Trailing stop works only in the profitable zone.
This means that the trailing stop starts working only when the position already has a profit in TPWCM_TrailingStop points.
Trailing stop distance;
Trailing stop step;
Enable breakeven on SAFETYLOCK positions after closing trades in the source
Set stop loss at the open price + - TPWCM_LevelWLoss points;
Set the breakeven when the position is in profit TPWCM_LevelProfit points;
Locking only those positions for which the current loss is less than the specified loss in points (indicated with a minus),
0 - disabled.
Locking only those positions for which the current profit is greater than the set profit in points,
0 - disabled.
Change when using Max_Lot_Monitoring / Min_Lot_Monitoring and SafetyPosMonitoring.
Advisor takes into account Max_Lot_Monitoring / Min_Lot_Monitoring in its positions, opened by SAFETYLOCK.
- Added DynamicStopOrderDelta = dynamic distance parameter:
Allows you to set a different distance of pending order, depending on the lot of the protected position.
With DynamicStopOrderDelta >0: The Higher the lot, the closer the pending order distance!
With DynamicStopOrderDelta <0: The higher the lot, the further the pending order distance!
DynamicStopOrderDelta is set to a position with a volume of 1 lot.
With DynamicStopOrderDelta = 100:
If the lot (volume) of your position is 1 lot, then the StopOrderDeltaifUSEe distance will be = 100 points;
If the lot (volume) of your position is 0.1 lot, then the StopOrderDeltaifUSEe distance will be = 1000 points;
If the lot (volume) of your position will be 0.01 lot, then the StopOrderDeltaifUSEe distance will be = 10,000 points;
With DynamicStopOrderDelta = -100:
If the lot (volume) of your position is 1 lot, then the StopOrderDeltaifUSEe distance will be = 100 points;
If the lot (volume) of your position is 0.1 lot, then the StopOrderDeltaifUSEe distance will be = 10 points;
If the lot (volume) of your position is 0.01 lot, then the StopOrderDeltaifUSEe distance will be = 1 point;
- Additional languages added to the panel: Spanish, Portuguese (Brazil), German, Chinese, Japanese;
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!
- Increase the speed of the panel;
- Added a control unit and control the speed of the quotes and the speed of testing.
- Added block output table open deals and positions.
Added hints to external variables
Added variable ModifyOrdPend_onlytoOpenPrice -
true - the ability to modify a pending order only up to the opening price of the position (old version)
false - continue to modify the opening price of pending orders by price movement.
When using NumberofStopOrder> 1, the profit of SafetyLock positions is calculated from the amount of the profit of all positions according to the ticket of the main position.
The function Close_One_if_Safety_More_profitable is imenen.
Now the closing of the main position and SAFETYLOCK positions occurs only when the amount of profit of these positions is greater or equal to Close_One_if_Safety_More_profitable_Dollars (With NumberofStopOrder> 1)
To get the results of previous versions, set Close_One_if_Safety_More_profitable_Dollars = 0.
The function Close_One_if_Safety_Closed_In_Profit is changed.
Now the closing of the main position occurs only when the amount of profit of the closed positions SAFETYLOCK and the main position is greater than or equal to Close_One_if_Safety_Closed_In_Profit_Dollars.
All orders and positions of SAFETYLOCK are closed.
If both Close_One_if_Safety_More_profitable and Close_One_if_Safety_Closed_In_Profit functions are enabled,
then the total profit is calculated from the closed positions SAFETYLOCK and positions SAFETYLOCK, which are still open. (Actual for NumberofStopOrder> 1)
The profit amount of SAFETYLOCK must be greater than or equal to Close_One_if_Safety_More_profitable_Dollars + Close_One_if_Safety_Closed_In_Profit_Dollars., Than the main position.
Added function Close_One_if_Safety_Closed
If the position SAFETYLOCK was closed for any reason (manual close, takeprofit, trailing stop), then the main position will also be closed.
The variable StopOrderDeltaifReopen is added to the ReopenClosedSafetyOrders block
StopOrderDeltaifReopens - The distance to set the pending order SAFETYLOCK after reopening the order.
If StopOrderDeltaifReopens = 0, then the distance = StopOrderDeltaifUSEe (old version)
The price for setting a pending order will be calculated from the current price.
- If the SPECIFID_Symbol_Monitoring parameter is not set and SymbolMonitoring = SPECIFID_SYMBOLs, then the EA monitors the currency pair it is attached to.
- Changed the conditions for closing Safety positions, if they are more profitable.
Close_One_if_Safety_Closed_In_Profit - close the original position if the SafetyLock position was closed with profit covering the current loss of the original position;
Close_One_if_Safety_Closed_In_Profit_Dollars - profit in USD to cover the original position;
Close_One_if_Safety_More_profitable - close the original position if the profitable SafetyLock position covers the current loss of the original position;
Close_One_if_Safety_More_profitable_Dollars - profit in USD to cover the original position;
Fixed an error than caused repeated modification of stop loss/take profit of the original position.
Updated the timer function. In case the timer does not start, the EA operates based on ticks.
SPECIFID_Symbol_Monitoring - added the ability to create a comma-separated list of symbols to be monitored.
For example, Close_One_if_Safety_Closed_In_Profit=true MNLOT=2.
As soon as the LOCK triggers and the Safety position closes by take profit, the original position will be closed.
- Added the Close_One_if_Safety_More_profitable parameter, which closes the original position, if the Safety position is more profitable, covering the current loss of the original position.
For example, Close_One_if_Safety_More_profitable=true MNLOT=2.
As soon as the LOCK triggers and the Safety position is more profitable, both the Safety and the original positions will be closed.
- Added the ModifyOrdPend_STEP pending - trailing step for pending orders when the ModifyOrdPend function is enabled
- Added the MilliSecondsTimerForMonitoring parameter - the number of milliseconds of the algorithm execution (by default, 1000 = 1 second)
- The Magic_Monitoring parameter has been updated. It is now possible to specify a list of magic numbers (separated by a comma) to be monitored.
Magic_Monitoring= -1 means that all magic numbers will be monitored
Magic_Monitoring= 0 means that manual trades will be monitored
Magic_Monitoring= 555,777 means that magic numbers 555 and 777 will be monitored
- Added monitoring filtering by the Comment_Monitoring comment. This option filters deal for placing locks for positions with the comment matching Comment_Monitoring
Comment_Monitoring="" - monitors all trades, regardless of the comment
Comment_Monitoring="VirtualTRadePad" - monitors all trades with the VirtualTRadePad comment, even if the comments contain VirtualTRadePad-1 or VirtualTRadePadEXTRA or TickVirtualTRadePadEXTRA
- Added a breakeven function
MovingInWLUSE - transfer the position to breakeven;
LevelWLoss - transfer the stop loss to +LevelWLoss points;
LevelProfit - when the trade gains LevelProfit points of profit;
- Fixed the error with placing pending orders on their positions when the SafetyPosMonitoring is enabled and more than 1 position in different directions are present in the market.
- Fixed the error with Magic_Monitoring, when setting a Magic_Monitoring value other than "-1"
The EA made this error in such functions as: CloseOneifStopsActive, Remove_TAKEPROFIT_ofOriginalifStopsActive, Remove_STOPLOSS_ofOriginalifStopsActive
- Fixed the error with modification of Take Profit when using the ModifyOrdPend parameter
- Added two options:
Remove_TAKEPROFIT_ofOriginalifStopsActive - remove the take profit of the original position, if the SafetyLock pending order was triggered;
Remove_STOPLOSS_ofOriginalifStopsActive - remove the stop loss of the original position, if the SafetyLock pending order was triggered;
It allows to "hard" lock two positions by removing the stop loss and take profit. It creates a "safe lock", which will not be unlocked if the original position was closed by its stop loss or take profit.
Details on the panel in our blog: https://www.mql5.com/en/blogs/post/687140
Min_Lot_Monitoring - minimum lot for the EA to monitor, if 0 - parameter is disabled;
Max_Lot_Monitoring - maximum lot for the EA to monitor, if 0 - parameter is disabled;
For example, you need to use the current SafetyLock EA for protecting positions which accumulated a large lot, such as after using martingale. The lot for which an opposite stop order should be placed = 0.16, at the same time the EA must not touch the positions less than 0.16. To do that, set the parameter to: Min_Lot_Monitoring =0.16;
For example, you need to lock all positions with lot sizes from 0.1 to 0.25, to do that, set the parameters to:
Min_Lot_Monitoring = 0.1;
Max_Lot_Monitoring = 0.25;
Added the SetMinStops variable:
In case of AutoSetMinLevel, the stop levels are reduced to the minimum possible levels, allowed on the server;
In case of ManualSet, user receives a message that the stop levels in the EA are less than the minimum allowed ones, and the EA stops operation.
Added the CloseSafetyPositionsifclosed variable:
Close SAFETY positions that have been activated, if the main position was closed.
ReopenClosedSafetyOrders - reopen the 'Safety' pending orders, if they were closed by a stop order, while the protected position is still open.
NumberofStopOrder - the number of pending orders placed for a position.
DistancefromStopOrders - the distance between the 'Safety' orders
CloseOneifStopsActive - Close the position if the 'Safety' pending orders was triggered
SymbolMonitoring = ALL_SYMBOL = Monitor all symbols, all trades on the account. If you placed the EA on 1 chart of any currency pair, then it will monitor every currency pair on the account;
SymbolMonitoring = ONLY_CURRENT_SYMBOL = Monitor only the current symbol. The EA will monitor and maintain only trades on the symbol the EA is set on;
SymbolMonitoring = SPECIFID_SYMBOL = Monitor only the trades on the symbol specified in SPECIFID_Symbol_Monitor. For example, EURUSD - then the EA will only maintain the trades on the EURUSD symbol;