Schtirlitz_855
Download scriptThis script is a specialized visual diagnostic tool designed for MetaTrader 4 users who want to analyze their past trading history on a specific currency pair or asset. Rather than providing signals or automating trades, it acts as an "archivist" that draws a clear, visual map of your completed transactions directly onto your price chart.
Here is a breakdown of how the logic functions:
Automated History Mapping
When you run the script, it scans your account's entire trading history. It specifically looks for completed orders associated with the current chart's symbol. If it finds that no trades have been made on that specific asset, it will alert you immediately.
Visual Identification of Trades
For every valid trade found in your history, the script automatically identifies several key data points and places markers (arrows) on the chart:
- Entry Points: It places an arrow at the exact price and time where a "Buy" or "Sell" order was opened. The colors are distinct (typically Blue for buys and Red for sells) to help you see the direction of the trade at a glance.
- Exit Points: It marks where the trade was eventually closed with a separate arrow, allowing you to see the total duration the position remained open.
The "Trace" Feature
One of the core functionalities of this script is its ability to track the path of an order. If the tracing option is enabled, it doesn't just mark the start and end; it can create a visual trail between the opening and closing points. This helps in visualizing the "journey" of a trade across various price movements.
Profit and Loss Reporting
To make the history even more informative, the script can display specific performance labels at the closing point of each trade:
- Color-Coded Results: It automatically detects if a trade resulted in a profit or a loss. Profits are typically highlighted in Green, while losses appear in Deep Pink/Magenta.
- Dynamic Labels: It calculates and displays the exact profit/loss value of each closed trade next to its exit arrow.
Summary for the User
Essentially, this script transforms your raw trading history into a visual story on your chart. Instead of scrolling through text-heavy account logs, you can look at your chart and instantly see where you entered, where you exited, how long you held the position, and whether the trade was successful or not—all represented by color-coded markers and clear labels.
//+------------------------------------------------------------------+
//| Schtirlitz.mq4 |
//| Rosh |
//| http://forexsystems.ru/phpBB/ |
//+------------------------------------------------------------------+
#property copyright "Rosh"
#property link "http://forexsystems.ru/phpBB/"
#property show_inputs
extern int scht_ExpertMagicNumber=855;
extern bool scht_ShowProfitLabels=true;
extern bool scht_ShowTrace=true;
int scht_UpOpenArrow=1;
int scht_DownOpenArrow=2;
int scht_CloseArrow=3;
color scht_UpOpenColor=Blue;
color jd_DownOpenColor=Red;
color scht_CloseColor=White;
color scht_ProfitClose=Lime;
color scht_LossClose=DeepPink;
color scht_lastCloseColor;
int scht_TraceLabel=159;
int scht_CloseLabel=108;
int scht_traceCounter;
int scht_closeLabelShift=30;
//+------------------------------------------------------------------+
//| ïîñòàâèì ñòðåëêó |
//+------------------------------------------------------------------+
void SetArrow(datetime _time,double _price,string _Description ,int _arrowType, color _arrowColor)
{
bool res;
ObjectCreate(_Description,OBJ_ARROW,0,_time,_price);
ObjectSet(_Description,OBJPROP_ARROWCODE,_arrowType);
ObjectSet(_Description,OBJPROP_COLOR,_arrowColor);
// res=ObjectSetText(_Description,"Ïðîáà", 10, "Times New Roman", Green);
// if (!res) Print(GetLastError());
}
//+------------------------------------------------------------------+
//| ïðîòðåéñèì îðäåð |
//+------------------------------------------------------------------+
void scht_TraceOrder(int _orderTicket)
{
double priceCloseLabel;
string scht_openDescription;
string scht_closeDescription;
int scht_open_ArrowType;
int scht_orderType=OrderType();
color scht_orderColor;
if (scht_orderType==OP_BUY ||scht_orderType==OP_SELL)
{
double scht_openPrice=OrderOpenPrice();
double scht_closePrice=OrderClosePrice();
if (scht_orderType==OP_BUY) scht_open_ArrowType=scht_UpOpenArrow; else scht_open_ArrowType=scht_DownOpenArrow;
if (scht_orderType==OP_BUY) scht_orderColor=scht_UpOpenColor; else scht_orderColor=jd_DownOpenColor;
datetime scht_timeClose=OrderCloseTime();
datetime scht_timeOpen=OrderOpenTime();
if (scht_orderType==OP_BUY)
{
scht_openDescription="buy #"+_orderTicket;
}
else
{
scht_openDescription="sell #"+_orderTicket;
}
scht_closeDescription="close "+scht_openDescription;
SetArrow(scht_timeOpen,scht_openPrice,scht_openDescription,scht_open_ArrowType,scht_orderColor); // ñòðåëêà îòêðûòèÿ
SetArrow(scht_timeClose,scht_closePrice,scht_closeDescription,scht_CloseArrow,scht_CloseColor); // ñòðåëêà çàêðûòèÿ
if (scht_ShowTrace)
{
int scht_openShift=0;
int scht_closeShift=0;
while (Time[scht_openShift]>scht_timeOpen) scht_openShift++;
//scht_openShift--;
while (Time[scht_closeShift]>scht_timeClose) scht_closeShift++;
//scht_closeShift--;
if (scht_openShift-scht_closeShift>1)
{
for (int tr_shift=scht_openShift-1; tr_shift>scht_closeShift;tr_shift--)
{
SetArrow(Time[tr_shift],scht_openPrice,scht_openDescription+" "+scht_traceCounter,scht_TraceLabel,scht_orderColor);
scht_traceCounter++;
}
}
if (scht_ShowProfitLabels)
{
if (OrderProfit()>0) scht_lastCloseColor=scht_ProfitClose; else scht_lastCloseColor=scht_LossClose;
if (scht_orderType==OP_BUY) priceCloseLabel=High[scht_closeShift]+scht_closeLabelShift*Point ; else priceCloseLabel=Low[scht_closeShift]-scht_closeLabelShift*Point;
SetArrow(Time[scht_closeShift],priceCloseLabel,scht_openDescription+" "+DoubleToStr(OrderProfit(),2),scht_CloseLabel,scht_lastCloseColor);
}
}
}
}
//+------------------------------------------------------------------+
//| ïîäñ÷èòàåì êîëè÷åñòâî ñäåëîê ïî ñèìâîëó/èíñòðóìåíòó |
//+------------------------------------------------------------------+
int scht_SymbolTrades()
{
int scht_tradesOnSymbol=0;
int scht_allTrades=HistoryTotal();
int cnt;
for (cnt=0;cnt<HistoryTotal();cnt++)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY)==false)
{
Print("Îøèáêà ïðè äîñòóïå ê èñòîðè÷åñêîé áàçå (",GetLastError(),")");
break;
}
if ((OrderSymbol()==Symbol())&&(OrderType()==OP_BUY||OrderType()==OP_SELL)) scht_tradesOnSymbol++;
}
return(scht_tradesOnSymbol);
}
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
//----
if (scht_SymbolTrades()==0) Alert("Ïî ñèìâîëó ",Symbol()," ñäåëîê íå íàéäåíî");
else
{
for (int cnt=0;cnt<HistoryTotal();cnt++)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY)==false)
{
Print("Îøèáêà ïðè äîñòóïå ê èñòîðè÷åñêîé áàçå (",GetLastError(),")");
break;
}
if ((OrderSymbol()==Symbol())&&((OrderMagicNumber()==0)||((OrderMagicNumber()!=0)&&(OrderMagicNumber()==scht_ExpertMagicNumber))))
{
Print("Ticket=",OrderTicket());
scht_TraceOrder(OrderTicket());
}
}
Comment("Äàííûå ïîëó÷åíû óòèëèòîé Øòèðëèö :) ");
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments