TradeHedgeDISPLAY_v2
Download scriptThis tool is designed to provide a real-time visual summary of your trading performance directly on your market chart. Its primary purpose is to calculate and display the collective profit or loss of a specific set of trades, allowing you to monitor your current financial standing at a glance without having to manually calculate figures from your trade history or open positions list.
How the Logic Works
1. Identification of Specific Trades The script does not simply add up every trade in your account. Instead, it acts as a filter. It looks for trades associated with a unique identification number (a "Magic Number"). This ensures that the profit displayed only reflects the trades managed by this specific strategy or automated system, ignoring any manual trades or other independent strategies you might have running simultaneously.
2. Real-Time Profit Calculation Every time the market moves or a new price tick occurs, the script scans through all your currently active orders. It identifies the ones that match the specific identification number mentioned above and sums up their individual profits and losses into a single total value.
3. Dynamic Visual Display Once the calculation is complete, the script updates the information on your screen:
- Automatic Refresh: It clears out the old data point and places a new one so that the numbers stay current with the live market.
- On-Screen Placement: The total profit figure is displayed as text on your chart, specifically positioned near the most recent price candle.
- Formatting: The result is shown in a clean, readable format (Times New Roman font) colored in white, making it easy to read against the background of the trading chart.
Summary for the User
Think of this script as a "Live Scoreboard." It constantly patrols your open trades, finds the ones belonging to your specific strategy, calculates the net profit or loss, and writes that number clearly on your screen so you can see exactly how much your current positions are worth in real-time.
//
// TradeHedge profit display
//
#property indicator_chart_window
datetime bartime;
int obj;
int start()
{
if(bartime!=Time[0] )
{
bartime=Time[0];
obj++;
}
int i;
double myProfit=0;
for(i = OrdersTotal(); i>=0; i--)
{
OrderSelect(i, SELECT_BY_POS);
if(OrderMagicNumber()==200809241653)
{
myProfit=myProfit+OrderProfit();
}
}
ObjectDelete("myp"+DoubleToStr(obj,0));
ObjectCreate("myp"+DoubleToStr(obj,0), OBJ_TEXT, 0, Time[0], High[0]+(5*Point));
ObjectSetText("myp"+DoubleToStr(obj,0),DoubleToStr(myProfit,2),10,"Times New Roman", White);
}
Comments