Exp-Rami-Stop

Download script
Author: Copyright � 2006, LeonSi.
Exp-Rami-Stop

This script is an automated trading assistant designed to manage your open positions by dynamically adjusting "Stop Loss" levels. Its primary goal is to protect your capital as a trade moves in your favor by automatically moving your safety nets closer to the current market price based on specific milestones.

Core Logic Overview

The tool operates as a multi-stage trailing system. Instead of using a single, static rule for all trades, it identifies four distinct "zones" of profit. As the price moves further away from your entry point in a favorable direction, the script switches between different protection levels to lock in gains progressively.

How It Works for Buy Positions

When you have an open "Buy" trade (expecting the price to go up), the script monitors how much profit has been accumulated:

  • Stage 4 (Immediate Protection): Once the price moves just slightly past your entry, the script sets a tight safety net.
  • Stages 3, 2, and 1: As the price continues to climb, the script checks if you have reached specific profit milestones (defined by the "STLos" settings). Every time you hit a new milestone, it automatically moves your Stop Loss higher to a new designated distance (defined by the "Trailing" settings).
  • The Goal: This ensures that if the market suddenly reverses, you exit with the maximum amount of profit gained up to that specific milestone.

How It Works for Sell Positions

The logic mirrors the "Buy" behavior but is inverted for "Sell" trades (expecting the price to go down):

  • It monitors the downward movement of the price.
  • As you reach each respective profit milestone, the script moves your Stop Loss downward to "lock in" the gains.

Key Features

  • Automatic Monitoring: The script constantly scans all open trades on the current symbol. You do not need to manually move any orders; it detects the price movement and updates the positions for you.
  • Dynamic Protection: By using four different levels, the tool provides a sophisticated "staircase" of protection. It becomes more aggressive in locking in profits as your trade becomes more successful.
  • Visual Feedback: When the script modifies a position to a new level, it displays a notification on your chart screen (e.g., "1 Stop Changed"), allowing you to see exactly when your protection has been updated.

In summary, this tool acts like an automated security guard for your trades, constantly moving your "exit door" closer to the current price as you gain ground, ensuring that a winning trade doesn't turn into a loss if the market suddenly shifts.

Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategy
15 Views
0 Downloads
0 Favorites
Exp-Rami-Stop
//+------------------------------------------------------------------+
//|                                                Exp-4StepStop.mq4 |
//|                                        Copyright © 2006, LeonSi. |
//|                                      http://www.expert-mt4.nm.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, LeonSi."
#property link      "http://www.expert-mt4.nm.ru"

//---- input parameters
extern int       Trailing1=50;
extern int       STLos1=20;
extern int       Trailing2=40;
extern int       STLos2=40;
extern int       Trailing3=30;
extern int       STLos3=60;
extern int       Trailing4=10;
extern int       STLos4=90;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//---- 
int cnt;
//---- Go for Change StopLoss
if(OrdersTotal()>0)
   {
   Comment(" ");
   for(cnt=0; cnt<=OrdersTotal(); cnt++)
      {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
//---- StopLoss for Buy
      if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && OrderStopLoss()>0)
         {
         if(OrderOpenPrice()+(STLos4*Point)<Bid && OrderStopLoss()<Bid-(Trailing4*Point))
            {
            Comment("4 Stop Changed ",OrderSymbol(),OrderType()," Number Ticket=",OrderTicket());
            OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(Trailing4*Point),OrderTakeProfit(),0,Blue);
            return(0);
            }
//---- STLos1
         if(OrderOpenPrice()+(STLos3*Point)<Bid && OrderStopLoss()<Bid-(Trailing3*Point))
            {
            Comment("3 Stop Changed ",OrderSymbol(),OrderType()," Number Ticket=",OrderTicket());
            OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(Trailing3*Point),OrderTakeProfit(),0,Blue);
            return(0);
            }
//---- STLos2
         if(OrderOpenPrice()+(STLos2*Point)<Bid && OrderStopLoss()<Bid-(Trailing2*Point))
            {
            Comment("2 Stop Changed ",OrderSymbol(),OrderType()," Number Ticket=",OrderTicket());
            OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(Trailing2*Point),OrderTakeProfit(),0,Blue);
            return(0);
            }
//---- STLos3
         if(OrderOpenPrice()+(STLos1*Point)<Bid && OrderStopLoss()<Bid-(Trailing1*Point))
            {
            Comment("1 Stop Changed ",OrderSymbol(),OrderType()," Number Ticket=",OrderTicket());
            OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(Trailing1*Point),OrderTakeProfit(),0,Blue);
            return(0);
            }
         }
//---- StopLoss for Sell
      if(OrderSymbol()==Symbol() && OrderType()==OP_SELL && OrderStopLoss()>0)
         {
         if(OrderOpenPrice()-(STLos4*Point)>Ask && OrderStopLoss()>Ask+(Trailing4*Point))
            {
            Comment("4 Stop Changed ",OrderSymbol(),OrderType()," Number Ticket=",OrderTicket());
            OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(Trailing4*Point),OrderTakeProfit(),0,Green);
            return(0);
            }
//---- STLos1
         if(OrderOpenPrice()-(STLos3*Point)>Ask && OrderStopLoss()>Ask+(Trailing3*Point))
            {
            Comment("3 Stop Changed ",OrderSymbol(),OrderType()," Number Ticket=",OrderTicket());
            OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(Trailing3*Point),OrderTakeProfit(),0,Green);
            return(0);
            }
//---- STLos2
         if(OrderOpenPrice()-(STLos2*Point)>Ask && OrderStopLoss()>Ask+(Trailing2*Point))
            {
            Comment("2 Stop Changed ",OrderSymbol(),OrderType()," Number Ticket=",OrderTicket());
            OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(Trailing2*Point),OrderTakeProfit(),0,Green);
            return(0);
            }
//---- STLos3
         if(OrderOpenPrice()-(STLos1*Point)>Ask && OrderStopLoss()>Ask+(Trailing1*Point))
            {
            Comment("1 Stop Changed ",OrderSymbol(),OrderType()," Number Ticket=",OrderTicket());
            OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(Trailing1*Point),OrderTakeProfit(),0,Green);
            return(0);
            }
         }
      }
   }
//+------------------------------------------------------------------+
   return(0);
  }

Comments