Tral

This automated script is designed to manage active trading positions by dynamically adjusting "Stop Loss" levels. Its primary goal is to protect your profits and mitigate risk automatically as the market moves in your favor, ensuring that a winning trade does not turn into a losing one due to sudden market fluctuations.

The logic operates based on three main parameters: a base Stop Loss, a Trailing distance, and a Safety Buffer. Here is how the system manages your trades:

Core Functionality

1. Safety Buffer Mechanism Before the script begins actively "trailing" your profit, it looks for a safety threshold. Once a trade moves in your favor by a specific amount (defined by the Safety Money setting), the script identifies the position as "safe." At this point, it ensures that a protection level is firmly in place, moving the initial stop loss to a position just below your entry price to prevent a total loss of the trade.

2. Dynamic Trailing Stop Once the safety threshold is met, the script begins its primary task: trailing the price.

  • For Buy Positions: As the market price climbs higher, the script constantly calculates a new stop loss level that stays at a fixed distance behind the current price. If the price moves up, the stop loss moves up with it. It will only move forward, never backward, effectively "locking in" profits as the trend continues.
  • For Sell Positions: The logic works in reverse. As the market price drops lower, the script follows the price down, keeping the stop loss at a consistent distance below the current market value.

3. Execution and Feedback The script scans all currently open positions on the specific chart you are viewing. Whenever it detects that the market has moved enough to justify a move in your protection level, it updates the order automatically. To provide real-time feedback, the script triggers an audio alert every time it successfully modifies a stop loss, notifying you that your profit is being secured.

Summary of Benefits

By using this script, you remove the need to manually monitor charts to adjust your exit points. It automates the "lock-in" process, ensuring that as long as a trade remains profitable and continues its trend, your risk is continuously minimized by moving your exit point forward in real-time.

Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategy
Miscellaneous
It plays sound alerts
8 Views
0 Downloads
0 Favorites
Tral
//+------------------------------------------------------------------+
//|                Trailing Stop   "ðàçíîêàëèáåðíûé"                 |
//+------------------------------------------------------------------+
extern int StopLoss  = 50; // 
extern int Trailing  = 50; //êîë-âî ïóíêòîâ äëÿ òðàëà
extern int SafeMoney = 20; //êîë-âî ïóíêòîâ äëÿ áåçóáûòêà

int init ()  { return(0); }
int deinit() { return(0); }

int start()
{
  double SLoss;

  for(int cnt=0; cnt<OrdersTotal(); cnt++)
  {
    OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if(OrderSymbol()==Symbol())
    {
      if(OrderType()==OP_BUY)
      {
        if(SafeMoney!=0 && Bid>OrderOpenPrice()+SafeMoney*Point && (OrderStopLoss()<=OrderOpenPrice() || OrderStopLoss()==0))
        { OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point,OrderTakeProfit(),0,CLR_NONE); PlaySound("expert.wav"); return(0); }

        if(Trailing!=0)
        {
 					SLoss=Bid-Trailing*Point;
 					if(SLoss>OrderOpenPrice() && SLoss>OrderStopLoss()+Point)
          { OrderModify(OrderTicket(),OrderOpenPrice(),SLoss,OrderTakeProfit(),0,CLR_NONE); PlaySound("expert.wav"); return(0); }
				}
			}

      if(OrderType()==OP_SELL)
      {
        if(SafeMoney!=0 && Ask<OrderOpenPrice()-SafeMoney*Point && (OrderStopLoss()>=OrderOpenPrice() || OrderStopLoss()==0))
        { OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point,OrderTakeProfit(),0,CLR_NONE); PlaySound("expert.wav"); return(0); }

        if(Trailing!=0)
        {
 					SLoss=Ask+Trailing*Point;
 					if(SLoss<OrderOpenPrice() && SLoss<OrderStopLoss()-Point)
          { OrderModify(OrderTicket(),OrderOpenPrice(),SLoss,OrderTakeProfit(),0,CLR_NONE); PlaySound("expert.wav"); return(0); }
        }
      }
    }
  }
  return(0);
}
//*******************************************************************************


Comments