cm_orders_profit_info
Download scriptThis script is designed as a visual aid for traders using the MetaTrader 4 platform. Its primary purpose is to provide real-time, on-screen information regarding open trades specifically for the currency pair or asset currently being viewed on your chart.
Core Functionality
Instead of requiring you to constantly check the "Toolbox" or "Trade" tabs to monitor your positions, this script automatically scans your active orders and displays key information directly on the price chart.
How it Works
The logic follows a continuous cycle to ensure your information stays up to date:
- Automatic Scanning: The script constantly monitors your active trades. It identifies every open position and checks if it belongs to the specific symbol you are currently viewing.
- Dynamic Data Display: For every matching trade found, it creates a text label on your chart. This label displays two critical pieces of information:
- Magic Number: The unique identifier assigned to the trade (useful for distinguishing between different automated trading systems).
- Profit/Loss: The current financial standing of that specific trade.
- Real-Time Visual Cues: To help you make quick decisions, the script includes a visual color-coding system. If a trade is in a profit position, the text appears in green; if a trade is currently in a loss, the text automatically switches to red.
- Self-Cleaning Updates: The script is programmed to refresh these labels constantly. Every time the market moves (a "tick"), it clears out the old text positions and redraws them with the most recent profit figures. This ensures that the numbers you see on your screen are always current.
Summary for the User
Essentially, this tool acts as a "live dashboard" overlay. It takes the data hidden in your trade history and pulls it forward onto your main viewing area, allowing you to see exactly how much money each specific position is making or losing at a single glance, while using color cues to highlight your winners and losers instantly.
//+------------------------------------------------------------------+
//| cm_orders_profit_info.mq4 |
//| Copyright 2014, cmillion@narod.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, cmillion@narod.ru"
#property link "cmillion@narod.ru"
#property version "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
for(int j=0; j<OrdersTotal(); j++)
{
if(OrderSelect(j,SELECT_BY_POS))
{
if(Symbol()==OrderSymbol())
{
string name=IntegerToString(OrderTicket());
ObjectDelete(0,name);
TextCreate(0,name,0,Time[20],OrderOpenPrice(),StringConcatenate("Magic = ",OrderMagicNumber()," Profit = ",DoubleToStr(OrderProfit(),2)),"Arial",8,Color(OrderProfit()<0,clrRed,clrGreen));
}
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool TextCreate(const long chart_ID=0, // ID ãðàôèêà
const string name="Text", // èìÿ îáúåêòà
const int sub_window=0, // íîìåð ïîäîêíà
datetime time=0, // âðåìÿ òî÷êè ïðèâÿçêè
double price=0, // öåíà òî÷êè ïðèâÿçêè
const string text="Text", // ñàì òåêñò
const string font="Arial", // øðèôò
const int font_size=10, // ðàçìåð øðèôòà
const color clr=clrRed, // öâåò
const double angle=0.0, // íàêëîí òåêñòà
const ENUM_ANCHOR_POINT anchor=ANCHOR_LOWER, // ñïîñîá ïðèâÿçêè
const bool back=false, // íà çàäíåì ïëàíå
const bool selection=false, // âûäåëèòü äëÿ ïåðåìåùåíèé
const bool hidden=true, // ñêðûò â ñïèñêå îáúåêòîâ
const long z_order=0) // ïðèîðèòåò íà íàæàòèå ìûøüþ
{
ResetLastError();
if(!ObjectCreate(chart_ID,name,OBJ_TEXT,sub_window,time,price))
{
Print(__FUNCTION__,
": íå óäàëîñü ñîçäàòü îáúåêò \"Òåêñò\"! Êîä îøèáêè = ",GetLastError());
return(false);
}
ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
return(true);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
color Color(bool P,color a,color b)
{
if(P) return(a);
else return(b);
}
//------------------------------------------------------------------
Comments