AutostopCyriac
Download scriptThis automated tool is designed to manage your trading risk by automatically calculating and applying "Take Profit" (your target for profit) and "Stop Loss" (your limit to prevent excessive losses) levels on your open trades. It ensures that every position you enter follows a consistent, pre-defined exit strategy without requiring manual intervention for each individual trade.
How the Logic Works
The script functions as an automated watchdog that constantly scans your trading account. Here is the step-by-step logic it follows:
1. Automated Calculation Instead of you having to manually calculate price points, the tool takes the base numbers you provide (the target profit and maximum loss) and adjusts them automatically based on the specific rules of the currency pair you are trading. It recognizes different price formats (such as 4-digit or 5-digit brokers) to ensure that the exit levels are placed accurately.
2. Continuous Monitoring The tool continuously scans your active trades. It looks specifically for any "Buy" or "Sell" positions that currently do not have a Take Profit or Stop Loss assigned to them. This makes it ideal for traders who open multiple positions quickly and want to ensure none are left unprotected.
3. Intelligent Trade Modification For every open trade identified without safety limits, the tool performs the following actions:
- For Buy Orders: It calculates a price point below your entry (the Stop Loss) and a price point above your entry (the Take Profit).
- For Sell Orders: It calculates a price point above your entry (the Stop Loss) and a price point below your entry (the Take Profit).
- Execution: Once calculated, the tool instantly updates the trade to include these precise exit points.
4. Error Handling and Stability The script includes a built-in "safety net" to handle common trading environment issues. If the market is moving too fast for the order to be placed correctly, it will alert you and attempt to retry. It also provides specific notifications if the trading platform is busy or if there are restrictions on your account, ensuring that you remain informed of any technical hiccups in real-time.
Key Benefits for the User
- Consistency: Ensures that every trade follows your exact risk management rules.
- Speed: Instantly protects new trades the moment they are opened.
- Automation: Removes the need to manually calculate pips or price levels for every single currency pair, reducing the risk of human error during high-pressure trading moments.
//+------------------------------------------------------------------+
//| AutoStop.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright "panthaigle"
#property link ""
extern string AboutAutostop="Automatically sets take profit and stop loss calcul with inital cost on all trades multisymbol";
extern bool MonitorTakeProfit=true;
extern bool MonitorStopLoss=true;
extern double TakeProfit=15;
extern double StopLoss=20;
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int digits=MarketInfo("EURUSD",MODE_DIGITS);
if(digits==5){int StopMultd=10;} else{StopMultd=1;}
double TP=NormalizeDouble(TakeProfit*StopMultd,Digits);
double SL=NormalizeDouble(StopLoss*StopMultd,Digits);
double slb=0;
double sls=0;
double tpb=0;
double tps=0;
//----
//-------------------------------------------------------------------+
//Check open orders
//-------------------------------------------------------------------+
if(OrdersTotal()>0){
for(int i=1; i<=OrdersTotal(); i++) // Cycle searching in orders
{
if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
{
TP=NormalizeDouble(TakeProfit*StopMultd,Digits);
SL=NormalizeDouble(StopLoss*StopMultd,Digits);
if((OrderType()==OP_BUY)&&((OrderTakeProfit()==0)))
{
slb=NormalizeDouble(OrderOpenPrice()-SL*Point,Digits);
tpb=NormalizeDouble(OrderOpenPrice()+TP*Point,Digits);
OrderModify(OrderTicket(),0,slb,tpb,0,CLR_NONE);
}
if((OrderType()==OP_SELL)&&(OrderTakeProfit()==0))
{
sls=NormalizeDouble(OrderOpenPrice()+SL*Point,Digits);
tps=NormalizeDouble(OrderOpenPrice()-TP*Point,Digits);
OrderModify(OrderTicket(),0,sls,tps,0,CLR_NONE);
}
}
}
}
//----
int Error=GetLastError();
if(Error==130){Alert("Wrong stops. Retrying."); RefreshRates();}
if(Error==133){Alert("Trading prohibited.");}
if(Error==2){Alert("Common error.");}
if(Error==146){Alert("Trading subsystem is busy. Retrying."); Sleep(500); RefreshRates();}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments