modify_take_profits_DragDrop
Download scriptThis script is designed to automate the management of active trades and pending orders on your MetaTrader platform by dynamically adjusting their "Take Profit" levels based on a specific price point you choose.
Instead of requiring you to manually calculate and update prices as the market moves, this tool monitors your open positions in real-time. Here is how the logic flows:
Core Functionality
The script operates by identifying every active trade or pending order currently associated with the specific currency pair you are viewing. It then compares the current market price against a target value—specifically, the price at the location where you dropped or clicked on the chart.
How it Handles Different Trade Types
The logic automatically detects what kind of trade is open and applies the appropriate rule to ensure your exit point is set correctly:
- For Buy Positions: If the current market price is lower than your designated target value, the script automatically updates your "Take Profit" to that target.
- For Sell Positions: If the current market price is higher than your designated target value, the script adjusts your "Take Profit" to that target.
- For Pending Orders (Buy/Sell Limits and Stops): The script checks if your target value is positioned correctly relative to your entry price. It ensures that your "Take Profit" is moved to the target value only if it makes logical sense for that specific type of order.
Key Benefits
- Automation: It removes the need to manually click and modify multiple orders one by one.
- Precision: By using the current market digits, it ensures that the price levels are set accurately according to the broker's requirements.
- Dynamic Updates: The script constantly refreshes the latest market data to ensure that your trade modifications happen as quickly as possible based on the live price action.
In short, this tool acts as an automated "Take Profit" setter that synchronizes your trading goals with the visual points you select on your trading screen.
#property copyright "what?"
#property link "who cares!"
//+------------------------------------------------------------------+
//| couldn't recall a fancy comment here |
//+------------------------------------------------------------------+
int start()
{
//----
int digits = MarketInfo(Symbol(),MODE_DIGITS);
double value = NormalizeDouble(WindowPriceOnDropped(),digits);
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
continue;
if(OrderSymbol()!=Symbol())
continue;
RefreshRates();
if(OrderType()==OP_BUY)
if(value>Ask)
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(), value,OrderExpiration(),White);
if(OrderType()==OP_SELL)
if(value<Bid)
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(), value,OrderExpiration(),White);
if((OrderType()==OP_BUYSTOP) || (OrderType()==OP_BUYLIMIT))
if(value>OrderOpenPrice())
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(), value,OrderExpiration(),White);
if((OrderType()==OP_SELLSTOP) || (OrderType()==OP_SELLLIMIT))
if(value<OrderOpenPrice())
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(), value,OrderExpiration(),White);
}
return(0);
}
//+------------------------------------------------------------------+
Comments