Show history
Download scriptThis script is designed to provide a visual history of your trading activity directly on your MetaTrader chart. It simplifies the process of reviewing past and current performance by automatically drawing markers and lines that represent your executed trades.
Core Functionality
The logic follows a systematic three-step process:
1. Workspace Cleanup Before doing anything else, the script clears out existing visual clutter. It removes all previous arrow markers and specifically identifies and deletes trend lines that represent closed positions. This ensures that every time you run the script, you are looking at a fresh, accurate representation of your data without overlapping old information.
2. Identifying Current and Pending Trades The script scans through all your currently active orders and pending requests (such as Buy Limits or Sell Stops). It performs the following actions:
- Filtering: It checks to ensure it only displays trades for the specific currency pair or asset you are currently viewing on the chart.
- Visual Mapping: For every valid trade found, it places an arrow at the exact price where the trade was opened.
- Categorization: It assigns distinct colors and styles based on the type of trade:
- Buy orders are marked with specific colors (like Aqua).
- Sell orders are marked with different colors (like Red).
- Pending orders (Limit or Stop) are highlighted in Yellow.
3. Reconstructing Trade History The script then dives into your historical trade data to recreate a "map" of completed transactions:
- Execution Points: It places an arrow at the opening price of every closed trade and another marker at the closing price.
- Visual Connections: To make it easy to see the "path" of a trade, the script draws a dotted line connecting the entry point to the exit point. This allows you to see at a glance how much profit or loss was made on a specific move.
- Consistent Styling: These historical lines maintain the same color coding as the live trades, allowing for easy visual recognition of your trading patterns over time.
Summary of User Experience
Instead of manually calculating where you entered and exited a trade, this script automates that visualization. When you run it, your chart becomes an organized diary: you can see exactly where your active "buy" or "sell" orders sit, and you can trace the lifecycle of every past trade via colored dotted lines and markers.
//+------------------------------------------------------------------+
//| Show history.mq4 |
//| Valmars |
//| valmars@bk.ru |
//+------------------------------------------------------------------+
#property copyright "Valmars"
#property link "valmars@bk.ru"
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
// Óäàëåíèå âñåõ ñòðåëîê ñäåëîê ñ ãðàôèêà
ObjectsDeleteAll(0,OBJ_ARROW);
// Óäàëåíèå âñåõ ëèíèé çàêðûòûõ ïîçèöèé ñ ãðàôèêà
for(int i = 0; i < ObjectsTotal(); i++)
{
if(ObjectType(ObjectName(i)) == OBJ_TREND)
if(!ObjectGet(ObjectName(i), OBJPROP_RAY))
ObjectDelete(ObjectName(i));
}
string name; // Èìÿ îáúåêòà-ñòðåëêè
int Arrow; // Êîä ñòðåëêè
double Color; // Öâåò ñòðåëêè
// Ïðîâåðêà äëÿ âñåõ îòêðûòûõ è îòëîæåííûõ îðäåðîâ
for(i = 0; i < OrdersTotal(); i++)
{
OrderSelect(i, SELECT_BY_POS);
// Ñèìâîëû îðäåðà è ãðàôèêà íå ñîâïàäàþò
if(OrderSymbol() != Symbol())
continue; // Ñëåäóþùèé îðäåð
switch(OrderType()) // Ïàðàìåòðû ñòðåëîê
{
case OP_BUY: Arrow = 1; Color = Aqua;
name = OrderTicket() + " buy " +
DoubleToStr(OrderLots(), 2) + " " +
OrderSymbol() + " at "+
DoubleToStr(OrderOpenPrice(),
MarketInfo(OrderSymbol(), MODE_DIGITS));
break;
case OP_SELL: Arrow = 2; Color = Red;
name = OrderTicket() + " sell " +
DoubleToStr(OrderLots(), 2) + " " +
OrderSymbol() + " at " +
DoubleToStr(OrderOpenPrice(),
MarketInfo(OrderSymbol(), MODE_DIGITS));
break;
case OP_BUYLIMIT: Arrow = 1; Color = Yellow;
name = OrderTicket() + " buylimit " +
DoubleToStr(OrderLots(), 2) + " " +
OrderSymbol() + " at " +
DoubleToStr(OrderOpenPrice(),
MarketInfo(OrderSymbol(), MODE_DIGITS));
break;
case OP_BUYSTOP: Arrow = 1; Color = Yellow;
name = OrderTicket() + " buystop " +
DoubleToStr(OrderLots(), 2) + " " +
OrderSymbol() + " at " +
DoubleToStr(OrderOpenPrice(),
MarketInfo(OrderSymbol(), MODE_DIGITS));
break;
case OP_SELLLIMIT: Arrow = 2; Color = Yellow;
name = OrderTicket() + " selllimit " +
DoubleToStr(OrderLots(), 2) + " " +
OrderSymbol() + " at " +
DoubleToStr(OrderOpenPrice(),
MarketInfo(OrderSymbol(), MODE_DIGITS));
break;
case OP_SELLSTOP: Arrow = 2; Color = Yellow;
name = OrderTicket() + " sellstop " +
DoubleToStr(OrderLots(), 2) + " " +
OrderSymbol() + " at " +
DoubleToStr(OrderOpenPrice(),
MarketInfo(OrderSymbol(), MODE_DIGITS));
break;
}
// Ñòðåëêà îòêðûòèÿ îðäåðà
ObjectCreate(name, OBJ_ARROW, 0, OrderOpenTime(), OrderOpenPrice());
ObjectSet(name, OBJPROP_ARROWCODE, Arrow);
ObjectSet(name, OBJPROP_COLOR, Color);
}
// Ïðîâåðêà äëÿ âñåõ çàêðûòûõ è óäàë¸ííûõ îðäåðîâ
for(i = 0; i < HistoryTotal(); i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);
// Ñèìâîëû îðäåðà è ãðàôèêà íå ñîâïàäàþò
if(OrderSymbol() != Symbol())
continue; // Ñëåäóþùèé îðäåð
switch(OrderType())
{
case OP_BUY: Arrow = 1; Color = Aqua;
name = OrderTicket() + " buy " +
DoubleToStr(OrderLots(), 2) + " " +
OrderSymbol() + " at " +
DoubleToStr(OrderOpenPrice(),
MarketInfo(OrderSymbol(), MODE_DIGITS));
break;
case OP_SELL: Arrow = 2; Color = Red;
name = OrderTicket() + " sell " +
DoubleToStr(OrderLots(), 2) + " " +
OrderSymbol() + " at " +
DoubleToStr(OrderOpenPrice(),
MarketInfo(OrderSymbol(), MODE_DIGITS));
break;
case OP_BUYLIMIT: Arrow = 1; Color = Yellow;
name = OrderTicket() + " buylimit " +
DoubleToStr(OrderLots(), 2) + " " +
OrderSymbol() + " at " +
DoubleToStr(OrderOpenPrice(),
MarketInfo(OrderSymbol(), MODE_DIGITS));
break;
case OP_BUYSTOP: Arrow = 1; Color = Yellow;
name = OrderTicket() + " buystop " +
DoubleToStr(OrderLots(), 2) + " " +
OrderSymbol() + " at " +
DoubleToStr(OrderOpenPrice(),
MarketInfo(OrderSymbol(), MODE_DIGITS));
break;
case OP_SELLLIMIT: Arrow = 2; Color = Yellow;
name = OrderTicket() + " selllimit " +
DoubleToStr(OrderLots(), 2) + " " +
OrderSymbol() + " at " +
DoubleToStr(OrderOpenPrice(),
MarketInfo(OrderSymbol(), MODE_DIGITS));
break;
case OP_SELLSTOP: Arrow = 2; Color = Yellow;
name = OrderTicket() + " sellstop " +
DoubleToStr(OrderLots(), 2) + " " +
OrderSymbol() + " at " +
DoubleToStr(OrderOpenPrice(),
MarketInfo(OrderSymbol(), MODE_DIGITS));
break;
}
// Ñòðåëêà îòêðûòèÿ îðäåðà
ObjectCreate(name, OBJ_ARROW, 0, OrderOpenTime(), OrderOpenPrice());
ObjectSet(name, OBJPROP_ARROWCODE, Arrow);
ObjectSet(name, OBJPROP_COLOR, Color);
switch(OrderType())
{
case OP_BUY: Arrow = 1; Color = Aqua;
name = OrderTicket() + " buy " +
DoubleToStr(OrderLots(), 2) + " " +
OrderSymbol() + " at " +
DoubleToStr(OrderOpenPrice(),
MarketInfo(OrderSymbol(), MODE_DIGITS));
break;
case OP_SELL: Arrow = 2; Color = Red;
name = OrderTicket() + " sell " +
DoubleToStr(OrderLots(), 2) + " " +
OrderSymbol() + " at " +
DoubleToStr(OrderOpenPrice(),
MarketInfo(OrderSymbol(), MODE_DIGITS));
break;
case OP_BUYLIMIT: Arrow = 1; Color = Yellow;
name = OrderTicket() + " buylimit " +
DoubleToStr(OrderLots(), 2) + " " +
OrderSymbol() + " at " +
DoubleToStr(OrderOpenPrice(),
MarketInfo(OrderSymbol(), MODE_DIGITS));
break;
case OP_BUYSTOP: Arrow = 1; Color = Yellow;
name = OrderTicket() + " buystop " +
DoubleToStr(OrderLots(), 2) + " " +
OrderSymbol() + " at " +
DoubleToStr(OrderOpenPrice(),
MarketInfo(OrderSymbol(), MODE_DIGITS));
break;
case OP_SELLLIMIT: Arrow = 2; Color = Yellow;
name = OrderTicket() + " selllimit " +
DoubleToStr(OrderLots(), 2) + " " +
OrderSymbol() + " at " +
DoubleToStr(OrderOpenPrice(),
MarketInfo(OrderSymbol(), MODE_DIGITS)); break;
case OP_SELLSTOP: Arrow = 2; Color = Yellow;
name = OrderTicket() + " sellstop " +
DoubleToStr(OrderLots(), 2) + " " +
OrderSymbol() + " at " +
DoubleToStr(OrderOpenPrice(),
MarketInfo(OrderSymbol(), MODE_DIGITS));
break;
}
// Ñòðåëêà çàêðûòèÿ îðäåðà
ObjectCreate(name, OBJ_ARROW, 0, OrderCloseTime(), OrderClosePrice());
ObjectSet(name, OBJPROP_ARROWCODE, 3);
ObjectSet(name, OBJPROP_COLOR, Color);
// Ïðîðèñîâêà ëèíèé çàêðûòûõ ïîçèöèé
name = OrderTicket() + DoubleToStr(OrderOpenPrice(), MarketInfo(OrderSymbol(),
MODE_DIGITS)) + "->" + DoubleToStr(OrderClosePrice(),
MarketInfo(OrderSymbol(), MODE_DIGITS));
ObjectCreate(name, OBJ_TREND, 0, OrderOpenTime(), OrderOpenPrice(),
OrderCloseTime(), OrderClosePrice());
ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
ObjectSet(name, OBJPROP_WIDTH, 1);
ObjectSet(name, OBJPROP_RAY, false);
ObjectSet(name, OBJPROP_COLOR, Color);
}
return(0);
}
//+------------------------------------------------------------------+
Comments