This script is designed to automate the adjustment of active trading orders based on a specific price point designated by the user. Its primary function is to "anchor" your open positions or pending orders to a custom level, ensuring that your risk parameters are aligned with a price you have manually identified on the chart.
How the Logic Works
The script operates by scanning all of your active trades and pending orders in real-time. For every position you have open on your current trading instrument, it performs the following logic:
For Active Market Positions:
- Buy Orders: If you currently hold a "Buy" position, the script checks if the price you selected is lower than the current market price. If it is, it automatically moves your entry level (or reference point) to that specific value.
- Sell Orders: If you currently hold a "Sell" position, the script checks if the price you selected is higher than the current market price. If it is, it adjusts the order to that specific value.
For Pending Orders (Limit and Stop Orders): The script also monitors orders that have not yet been triggered:
- Buy Limits/Stops: It looks for Buy orders where your chosen price is lower than the original price you set. If it finds one, it moves the order down to your chosen price.
- Sell Limits/Stops: It looks for Sell orders where your chosen price is higher than the original price you set. If it finds one, it moves the order up to your chosen price.
User Experience Summary
In simple terms, this tool allows you to "drop" a price onto your chart and have the script automatically go through your entire portfolio to realign those trades. It ensures that your orders are consistently positioned relative to your chosen price point without requiring you to manually modify every single trade one by one. It essentially acts as a bulk-adjustment tool for your trade entries based on a single user-defined price level.
#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<Bid)
OrderModify(OrderTicket(),OrderOpenPrice(),value, OrderTakeProfit(),OrderExpiration(),White);
if(OrderType()==OP_SELL)
if(value>Ask)
OrderModify(OrderTicket(),OrderOpenPrice(),value, OrderTakeProfit(),OrderExpiration(),White);
if((OrderType()==OP_BUYSTOP) || (OrderType()==OP_BUYLIMIT))
if(value<OrderOpenPrice())
OrderModify(OrderTicket(),OrderOpenPrice(),value, OrderTakeProfit(),OrderExpiration(),White);
if((OrderType()==OP_SELLSTOP) || (OrderType()==OP_SELLLIMIT))
if(value>OrderOpenPrice())
OrderModify(OrderTicket(),OrderOpenPrice(),value, OrderTakeProfit(),OrderExpiration(),White);
}
return(0);
}
//+------------------------------------------------------------------+
Comments