__________ StopLoss
Download scriptThis automated script is designed to manage your risk by dynamically adjusting the Stop Loss levels of your active trades. Its primary purpose is to ensure that your "safety net" (the Stop Loss) remains at a specific, predetermined distance from the current market price as the price fluctuates.
How it Works
The script constantly monitors your open positions on a specific currency pair. Instead of leaving your Stop Loss at a static price set when you first opened the trade, this tool recalculates where that stop should be based on real-time movement.
You can configure the behavior using two main settings:
- Distance: This defines how many "points" (the smallest price increment) away from the current market price the Stop Loss should stay.
- UpDown Toggle: This determines how aggressively the script reacts to price movements. It offers two modes of operation:
Mode 1: Continuous Tracking (Upside/Downside)
When enabled, the script actively moves your Stop Loss to maintain the exact distance you specified from the current price at all times. It effectively "trails" the market price, adjusting your risk level automatically as the price moves in either direction.
Mode 2: Directional Protection (Trend Specific)
When disabled, the script becomes more selective. It will only modify your Stop Loss if the price moves in a way that puts your current Stop Loss at risk of being hit prematurely by a temporary fluctuation or "rebound." In this mode, it acts as a safeguard to move the stop level only when necessary to protect your position from being closed by market noise.
Summary of Operation
Whenever the script detects an active trade on your chart, it performs the following logic:
- It identifies whether you are in a Buy or Sell position.
- It calculates a new price level based on the current Bid or Ask price plus/minus your chosen distance.
- It checks if the modification meets your "UpDown" criteria.
- If all conditions are met, it automatically updates the order in your trading platform to reflect the new protected price.
//+------------------------------------------------------------------+
//| _StopLossMove.mq4 |
//| "ÑÊÐÈÏÒÛ ÄËß ËÅÍÈÂÎÃÎ" |
//| Ñêðèïò ïåðåìåùàåò StopLoss íà Distance îò ðûíêà |
//| Bookkeeper, 2006, yuzefovich@gmail.com |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
//#property show_inputs
//+------------------------------------------------------------------+
extern int Distance=5; // Ðàññòîÿíèå îò ðûíêà |
extern bool UpDoun=true; //äëÿ òîëüêî "ïîäòàñêèâàíèÿ" ê ðûíêó =false |
//äëÿ è "ïîäòàñêèâàíèÿ" ê ðûíêó è "îòñêîêà" îò ðûíêà =true |
//+------------------------------------------------------------------+
void start()
{
double NewPrice;
int i,Total,Dist;
int Dgts=MarketInfo(Symbol(),MODE_DIGITS);
bool GoGo;
//+------------------------------- ÓÇÍÀÒÜ ÎÃÐÀÍÈ×ÅÍÈÅ ÑÂÎÅÃÎ ÄÖ -----+
// if(Distance<10) Dist=10;
// else
Dist=Distance;
//+------------------------------------------------------------------+
Total=OrdersTotal();
if(Total>0)
{
for(i=Total-1; i>=0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
{
if(OrderSymbol()==Symbol() && OrderType()==OP_SELL)
{
NewPrice=Ask+Dist*Point;
if(UpDoun==true) GoGo=true;
else
{
if(OrderStopLoss()>NewPrice) GoGo=true;
else GoGo=false;
}
if(GoGo==true) if(OrderModify(OrderTicket(),
OrderOpenPrice(),
NormalizeDouble(NewPrice,Dgts),
OrderTakeProfit(),
OrderExpiration(),
CLR_NONE)!=TRUE)
Print("LastError = ", GetLastError());
}
if(OrderSymbol()==Symbol() && OrderType()==OP_BUY)
{
NewPrice=Bid-Dist*Point;
if(UpDoun==true) GoGo=true;
else
{
if(OrderStopLoss()<NewPrice) GoGo=true;
else GoGo=false;
}
if(GoGo==true) if(OrderModify(OrderTicket(),
OrderOpenPrice(),
NormalizeDouble(NewPrice,Dgts),
OrderTakeProfit(),
OrderExpiration(),
CLR_NONE)!=TRUE)
Print("LastError = ", GetLastError());
}
}
}
}
}
//+------------------------------------------------------------------+
Comments