OrderHistory
Download scriptThis script is designed to enhance the visual clarity of your trading history by automatically mapping out past transactions directly on your price chart. Instead of manually scrolling through text-based logs, it converts your historical data into a visual roadmap, making it easier to see where trades opened, closed, and how they behaved relative to your intended targets.
Core Functionality
The script scans your account's trade history for the specific currency pair you are currently viewing. For every past trade found, it performs several automated actions:
- Data Extraction: It pulls essential details for each completed trade, including the opening and closing prices, the exact time of execution, the profit/loss results, and the set Stop Loss levels.
- Textual Labeling: It places a text label on the chart for each historical order. This label identifies the unique ticket number, the time the trade was opened, and the price at which it started.
- Visual Markers (Arrows): The script draws specific arrows to represent different stages of your trading activity:
- Entry Points: Shows where you first entered a Buy or Sell position.
- Take Profit Targets: Visually marks your intended profit goals based on the results of the trade.
- Stop Loss Levels: Highlights where your safety net (Stop Loss) was set during the trade.
- Exit Outcomes: It intelligently places different colored arrows at the closing price to indicate whether the trade hit your target, hit your stop loss, or was closed elsewhere.
Logic Flow for Trade Types
The script distinguishes between different types of market orders to ensure the markers are placed accurately:
- Buy Orders (including Buy Limits/Stops): These use blue markers to signify upward momentum. The logic identifies whether the price reached the profit goal (positive movement) or triggered a loss, placing corresponding arrows to show the "path" the price took.
- Sell Orders (including Sell Limits/Stops): These use red markers to signify downward momentum. The logic calculates the distance to the profit and stop-loss levels from the entry point to place the correct visual cues.
Key Features for the User
- Automated Cleanup: The script is designed to manage its own objects; if it processes a trade that already has a marker, it cleans up the old one before placing the updated information.
- Visual Feedback: By using different colors (Blue for Buy/Profit, Red for Sell/Profit, and Yellow for Stop Losses), it provides an instant "at-a-glance" summary of your trading performance history.
- Compatibility: It is specifically designed to work with the current chart's symbol, ensuring that your history for different currencies doesn't clutter the wrong charts.
//+------------------------------------------------------------------+
//| OrderHistory.mq4 |
//| Copyright © 2005, Arunas Pranckevicius(T-1000), Lithuania |
//| irc://irc.omnitel.net/forex |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Arunas Pranckevicius(T-1000), Lithuania"
#property link "irc://irc.omnitel.net/forex"
extern bool Arrows = 1;
#include <stdlib.mqh>
void SetArrow(datetime ArrowTime, double Price, double ArrowCode, color ArrowCollor)
{
if (!Arrows) return;
int err;
string ArrowName = TimeToStr(ArrowTime)+"_"+DoubleToStr(Price,4);
if (ObjectFind(ArrowName) != -1) ObjectDelete(ArrowName);
if(!ObjectCreate(ArrowName, OBJ_ARROW, 0, ArrowTime, Price))
{
err=GetLastError();
Print("error: can't create Arrow! code #",err," ",ErrorDescription(err));
return;
}
else
{
ObjectSet(ArrowName, OBJPROP_ARROWCODE, ArrowCode);
ObjectSet(ArrowName, OBJPROP_COLOR , ArrowCollor);
ObjectSet(ArrowName, OBJPROP_WIDTH , 1);
ObjectSetText(ArrowName,DoubleToStr(ArrowCode,1), 8, "Arial", ArrowCollor);
ObjectsRedraw();
}
}
void DelArrow(datetime ArrowTime, double Price)
{
if (!Arrows) return;
string ArrowName = TimeToStr(ArrowTime)+"_"+DoubleToStr(Price,4);
if (ObjectFind(ArrowName) != -1) ObjectDelete(ArrowName);
// if (Symbol() == "EURUSD") Print("DEBUG: Deleting "+ArrowName);
ObjectsRedraw();
}
void SetObject(string ObjName,int ObjType,datetime ObjTime1,double ObjPrice1,datetime ObjTime2=0,double ObjPrice2=0,color ObjColor=Red,int ObjSize=1,int ObjStyle=STYLE_SOLID,datetime ObjTime3=0,double ObjPrice3=0)
{
if (!Arrows || IsTesting()) return;
if (ObjectFind(ObjName) != -1) ObjectDelete(ObjName);
ObjectCreate(ObjName, ObjType, 0,ObjTime1 , ObjPrice1, ObjTime2, ObjPrice2, ObjTime3, ObjPrice3);
ObjectSet(ObjName,OBJPROP_COLOR,ObjColor);
ObjectSet(ObjName,OBJPROP_STYLE,ObjStyle);
ObjectSet(ObjName,OBJPROP_WIDTH,ObjSize);
}
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
//----
// retrieving info from trade history
int i,hstTotal=HistoryTotal();
int HistoryOrderType;
int HistoryOrderTicket;
int HistoryOrderCloseTime;
double HistoryOrderClosePrice;
int HistoryOrderOpenTime;
double HistoryOrderOpenPrice;
double HistoryOrderOpenProfit;
double HistoryOrderOpenStopLoss;
string OrderName;
for(i=0;i<hstTotal;i++)
{
//---- check selection result
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
{
Print("Access to history failed with error (",GetLastError(),")");
break;
}
HistoryOrderType = OrderType();
if (OrderSymbol() == Symbol())
{
HistoryOrderCloseTime=OrderCloseTime();
HistoryOrderClosePrice=OrderClosePrice();
HistoryOrderOpenTime=OrderOpenTime();
HistoryOrderOpenPrice=OrderOpenPrice();
HistoryOrderOpenProfit=OrderProfit();
HistoryOrderOpenStopLoss=OrderStopLoss();
HistoryOrderTicket=OrderTicket();
OrderName=DoubleToStr(HistoryOrderTicket,0)+" "+TimeToStr(HistoryOrderOpenTime)+" "+DoubleToStr(HistoryOrderOpenPrice,4);
if(!ObjectCreate(DoubleToStr(HistoryOrderTicket,0), OBJ_TEXT, 0, HistoryOrderOpenTime, (HistoryOrderOpenPrice+HistoryOrderOpenStopLoss)/2))
{
Print("error: can't create text_object! code #",GetLastError());
return(0);
}
ObjectSetText(DoubleToStr(HistoryOrderTicket,0),OrderName,10,"Times New Roman", Yellow);
if (HistoryOrderType == OP_BUY)
{
Print("Order ",OrderName,": BUY t/p ",HistoryOrderOpenProfit," s/l ",HistoryOrderOpenStopLoss);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice,233,Blue);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice + HistoryOrderOpenProfit * Point,177,Blue);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenStopLoss,251,Yellow);
if (HistoryOrderClosePrice >= HistoryOrderOpenProfit)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,252,Blue);
if (HistoryOrderClosePrice <= HistoryOrderOpenStopLoss)
{
if (HistoryOrderClosePrice <= HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,78,Yellow);
if (HistoryOrderClosePrice > HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,254,Blue);
}
}
if (HistoryOrderType == OP_BUYSTOP)
{
Print("Order ",OrderName,": BUYSTOP t/p ",HistoryOrderOpenProfit," s/l ",HistoryOrderOpenStopLoss);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice,228,Blue);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice + HistoryOrderOpenProfit * Point,177,Blue);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenStopLoss,251,Yellow);
if (HistoryOrderClosePrice >= HistoryOrderOpenProfit)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,252,Blue);
if (HistoryOrderClosePrice <= HistoryOrderOpenStopLoss)
{
if (HistoryOrderClosePrice <= HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,78,Yellow);
if (HistoryOrderClosePrice > HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,254,Blue);
}
}
if (HistoryOrderType == OP_BUYLIMIT)
{
Print("Order ",OrderName,": BUYLIMIT t/p ",HistoryOrderOpenProfit," s/l ",HistoryOrderOpenStopLoss);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice,200,Blue);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice + HistoryOrderOpenProfit * Point,177,Blue);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenStopLoss,251,Yellow);
if (HistoryOrderClosePrice >= HistoryOrderOpenProfit)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,252,Blue);
if (HistoryOrderClosePrice <= HistoryOrderOpenStopLoss)
{
if (HistoryOrderClosePrice <= HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,78,Yellow);
if (HistoryOrderClosePrice > HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,254,Blue);
}
}
if (HistoryOrderType == OP_SELL)
{
Print("Order ",OrderName,": SELL t/p ",HistoryOrderOpenProfit," s/l ",HistoryOrderOpenStopLoss);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice,234,Red);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice - HistoryOrderOpenProfit * Point,177,Red);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenStopLoss,251,Yellow);
if (HistoryOrderClosePrice <= HistoryOrderOpenProfit)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,252,Red);
if (HistoryOrderClosePrice >= HistoryOrderOpenStopLoss)
{
if (HistoryOrderClosePrice >= HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,78,Yellow);
if (HistoryOrderClosePrice < HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,254,Red);
}
}
if (HistoryOrderType == OP_SELLSTOP)
{
Print("Order ",OrderName,": SELLSTOP t/p ",HistoryOrderOpenProfit," s/l ",HistoryOrderOpenStopLoss);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice,230,Red);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice - HistoryOrderOpenProfit * Point,177,Red);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenStopLoss,251,Yellow);
if (HistoryOrderClosePrice <= HistoryOrderOpenProfit)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,252,Red);
if (HistoryOrderClosePrice >= HistoryOrderOpenStopLoss)
{
if (HistoryOrderClosePrice >= HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,78,Yellow);
if (HistoryOrderClosePrice < HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,254,Red);
}
}
if (HistoryOrderType == OP_SELLLIMIT)
{
Print("Order ",OrderName,": SELLIMIT t/p ",HistoryOrderOpenProfit," s/l ",HistoryOrderOpenStopLoss);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice,202,Red);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenPrice - HistoryOrderOpenProfit * Point,177,Red);
SetArrow(HistoryOrderOpenTime,HistoryOrderOpenStopLoss,251,Yellow);
if (HistoryOrderClosePrice <= HistoryOrderOpenProfit)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,252,Red);
if (HistoryOrderClosePrice >= HistoryOrderOpenStopLoss)
{
if (HistoryOrderClosePrice >= HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,78,Yellow);
if (HistoryOrderClosePrice < HistoryOrderOpenPrice)
SetArrow(HistoryOrderCloseTime,HistoryOrderClosePrice,254,Red);
}
}
}
{
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments