breakevenmaster

Download script
Author: Copyright � 2016, Il Anokhin
breakevenmaster

This tool is designed to automate and secure your trading positions by managing "Break-Even" levels automatically. Its primary purpose is to protect your capital by ensuring that once a trade moves into a profitable state, the risk is minimized by shifting the stop-loss point to the original entry price.

Core Functionality

The script continuously monitors your open trades in real-time. When a trade reaches a specific profit threshold (defined by you in pips), the tool automatically adjusts the stop-loss order. By doing this, it ensures that if the market reverses suddenly, the trade will close at your entry point—effectively "breaking even" and preventing a winning trade from turning into a losing one.

Key Features & Customization

To give you full control over how this automation behaves, the script includes several filtering options:

  • Profit Threshold (Break-Even Pips): You can define exactly how far the price needs to move in your favor before the safety mechanism activates.
  • Specific Order Filtering: The tool allows you to choose whether it should manage all open trades or only specific ones. You can set these filters using:
    • Magic Numbers: If you use an automated trading robot (EA), you can tell this script to only manage trades created by a specific robot ID.
    • Order Comments: You can tag specific trades with unique text comments, allowing the tool to ignore everything else and focus only on your selected positions.
  • Smart Detection: The script is programmed to recognize both "Buy" and "Sell" orders independently, adjusting the logic based on whether the price needs to move up or down to reach your target. It also intelligently checks if a stop-loss is already set to avoid unnecessary modifications.

How it Works in Practice

  1. Monitoring: The script scans every tick of the market price.
  2. Verification: It checks if a trade meets your specific criteria (e.g., correct symbol, correct comment, and positive profit).
  3. Action: Once the price exceeds your defined pip target, the script instantly moves the stop-loss to the entry price.
  4. Safety: If the trade is already at or beyond the break-even point, it remains in place, leaving your remaining potential profits untouched.
Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategy
12 Views
0 Downloads
0 Favorites
breakevenmaster
//+------------------------------------------------------------------+
//|                                                  BreakEvenMaster |
//|                                       Copyright 2016, Il Anokhin |
//|                           http://www.mql5.com/en/users/ilanokhin |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, Il Anokhin"
#property link "http://www.mql5.com/en/users/ilanokhin"
#property description ""
#property strict
//-------------------------------------------------------------------------
// Inputs
//-------------------------------------------------------------------------
input int BE = 20;                  //Break-Even Stop (pips)
input bool UC = false;              //Use Certain Order Comment
input string Comm = "";             //Certain Order Comment
input bool UM = false;              //Use Certain Order Magic Number
input int Magic = 12345;            //Certain Order Magic Number
//-------------------------------------------------------------------------
// Variables
//-------------------------------------------------------------------------
int i;
double pip;
bool w;
//-------------------------------------------------------------------------
// 1. Main function
//-------------------------------------------------------------------------
void OnTick(void)
  {
   Comment("Copyright © 2016, Il Anokhin\n"+TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS));

//--- 1.1. Define pip -----------------------------------------------------
   if(Digits==4 || Digits<=2) pip=Point;
   if(Digits==5 || Digits==3) pip=Point*10;

//--- 1.2. Break-Even -----------------------------------------------------
   for(i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
        {
         if(OrderSymbol()==Symbol() && BE>0 && OrderProfit()>0)
           {
            if(UC==true && OrderComment()==Comm && UM==true && OrderMagicNumber()==Magic && OrderType()==OP_BUY && OrderOpenPrice()+BE*pip<=Bid && OrderStopLoss()<OrderOpenPrice()) w=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0);
            if(UC==true && OrderComment()==Comm && UM==true && OrderMagicNumber()==Magic && OrderType()==OP_SELL && OrderOpenPrice()-BE*pip>=Ask && (OrderStopLoss()>OrderOpenPrice() || OrderStopLoss()==0)) w=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0);
            if(UC==true && OrderComment()==Comm && UM==false && OrderType()==OP_BUY && OrderOpenPrice()+BE*pip<=Bid && OrderStopLoss()<OrderOpenPrice()) w=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0);
            if(UC==true && OrderComment()==Comm && UM==false && OrderType()==OP_SELL && OrderOpenPrice()-BE*pip>=Ask && (OrderStopLoss()>OrderOpenPrice() || OrderStopLoss()==0)) w=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0);
            if(UC==false && UM==true && OrderMagicNumber()==Magic && OrderType()==OP_BUY && OrderOpenPrice()+BE*pip<=Bid && OrderStopLoss()<OrderOpenPrice()) w=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0);
            if(UC==false && UM==true && OrderMagicNumber()==Magic && OrderType()==OP_SELL && OrderOpenPrice()-BE*pip>=Ask && (OrderStopLoss()>OrderOpenPrice() || OrderStopLoss()==0)) w=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0);
            if(UC==false && UM==false && OrderType()==OP_BUY && OrderOpenPrice()+BE*pip<=Bid && OrderStopLoss()<OrderOpenPrice()) w=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0);
            if(UC==false && UM==false && OrderType()==OP_SELL && OrderOpenPrice()-BE*pip>=Ask && (OrderStopLoss()>OrderOpenPrice() || OrderStopLoss()==0)) w=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0);
           }
        }
     }

//--- 1.3. End of main function -------------------------------------------
   return;
  }
//-------------------------------------------------------------------------

Comments