MetaTrader 4 MT4 Libraries Hidden StopLoss and TakeProfit System – library MetaTrader 4

Hidden StopLoss and TakeProfit System – library MetaTrader 4

The attached files represent a class system that can be used to simulate a hidden Stop Loss and Take Profit system, however in addition to this, it also creates a live Stop Loss and Take Profit on the trade just in case the connection between the client and broker server goes down. There are also 4 example EAs. A basic description of how the system works is as follows:

  1. A class object is created with the trade characteristics that are required.
  2. A set of functions that are very similar to the OrderSend, OrderModify and OrderClose functions have been provided in the class for opening the trade.
  3. The class records the hidden Stop Loss and hidden Take Profit.
  4. When a trade is opened, a real Stop Loss and Take Profit is added onto the trade that is bigger than the hidden Stop Loss or Take Profit.
    • Buy: Minimum Stop Loss 1 = hidden Stop Loss – Live Spread.
    • Buy: Minimum Stop Loss 2 = Current Spot – {Freeze Level/Stop Level Adjustment} – Live Spread.
    • Buy: Actual Live Stop Loss is Min (Stop Loss 1, Stop Loss 2).
    • Sell: Minimum Stop Loss 1 = hidden Stop Loss + Live Spread.
    • Sell: Minimum Stop Loss 2 = Current Spot + {Freeze Level/Stop Level Adjustment} + Live Spread.
    • Sell: Actual Live Stop Loss is Max (Stop Loss 1, Stop Loss 2).
  5. The idea was to choose a level for Live Spread that will be large enough to cover any changes in the spread for Stop Loss hunting, but also any changes in the Stop Level and Freeze Level that may occur.
  6. I would suggest recording the spread, Stop Level and Freeze Level over a week and recording the difference between the minimum and maximum of these values. The Live Spread should be set so that it is greater than these differences.
Alternative:   Authenticate into an MT4 account from MQL4 (tested in build 880) - library MetaTrader 4

To get the system to work please use the following procedure:

  1. Add GlobalChartFunctions, C_Trade, C_Trade_TrailingStop Loss, C_Trade_SteppedStop Loss, C_Trade_Pending into the include directory.
  2. Add C_Trade_BasicExample_1, C_Trade_TrailingStop Loss_2, C_Trade_SteppedStop Loss_3, C_Trade_Pending_4 into the Experts directory.
  3. If you want to move the files to a different location, you may need to adjust the include files.
  4. Compile the EA’s and test them.

This system has only had some basic testing. It has not been tested in a live environment or incorporated into practical trading system yet, so please take great care and beware that bugs may exist.

I consider this a work in progress that I hope to improve upon later, when I have more time available.

📈 ROBOTFX MetaTrader Expert Advisors and Indicators to maximize profits and minimize the risks