fromRepOnGraph
Download scriptThis script is designed to bridge the gap between raw trading data and visual analysis. Specifically, it takes the results from a "Strategy Tester" report—which is usually just a text-based file of numbers—and automatically draws those trades onto your trading chart as visual markers.
How It Works
When you run this script, it performs the following logic:
1. Data Extraction The script opens the standard HTML report file generated by the MetaTrader strategy tester. It scans through this file to find specific information for every trade executed during your test, including:
- The exact date and time of the trade.
- The type of operation (Buy or Sell).
- The unique ticket number (ID) of the trade.
- The prices at which the trades were opened and closed.
2. Visual Drawing Instead of you having to manually plot these points, the script automatically generates visual objects on your chart based on the data it finds:
- Shapes: It can draw either rectangles or lines (configurable by the user) to represent the "zone" of each trade.
- Smart Coloring: The script is intelligent enough to change colors based on the outcome. For example, it can distinguish between a profitable purchase and a losing one by shifting the color of the shape automatically.
- Arrows: It can place specific arrows at the entry points of your trades to clearly mark where the strategy initiated a position.
3. Performance Tracking & Labels Beyond just drawing shapes, the script calculates the financial results in real-time as it processes the report:
- Profit/Loss Calculation: For every trade, it calculates the difference between the entry and exit prices.
- Dynamic Text Labels: It places text on the chart next to each trade showing exactly how much profit or loss was made for that specific move.
- Running Balance: It tracks the cumulative progress of the trading session, displaying a running balance so you can see the account growth (or decline) step-by-step as you look at the chart chronologically.
Summary for the User
Essentially, this tool transforms a boring text report into a visual "map" of your trading strategy. It allows you to see exactly where your trades happened, how large they were, and whether they were successful, all plotted directly on the price history with clear colors and calculated profit figures.
//+------------------------------------------------------------------+
//| fromRepOnGraph.mq4 |
//| Êèì Èãîðü Â. aka KimIV |
//| http://www.kimiv.ru |
//| |
//| 17.02.2006 Ñêðèïò äëÿ ïåðåíîñà ñäåëîê èç îò÷¸òà íà ãðàôèê. |
//| Carrying the Deals from Report on Graph. |
//| Ñêðèïò âûïîëíÿåò ÷òåíèå ñäåëîê èç ôàéëà ñòàíäàðíîãî îò÷¸òà |
//| òåñòåðà è îòîáðàæàåò èõ â âèäå ðàçíîöâåòíûõ ïðÿìîóãîëüíèêîâ. |
//+------------------------------------------------------------------+
#property copyright "Êèì Èãîðü Â. aka KimIV"
#property link "http://www.kimiv.ru"
#property show_inputs
extern string FileName = "StrategyTester.htm";
extern bool DeleteOldObjects = True; // Óäàëÿòü ñòàðûå îáúåêòû
extern string _P_Objects = "---------- Ïàðàìåòðû îáúåêòîâ";
extern int TypeObjects = 1; // Òèï îáúåêòîâ (0-ïðÿìîóã. 1-ëèíèÿ)
extern color clObjBuy = Aqua; // Öâåò ïðèáûëüíûõ ïîêóïîê
extern color clObjBuyLoss = Blue; // Öâåò óáûòî÷íûõ ïîêóïîê
extern color clObjSell = Salmon; // Öâåò ïðèáûëüíûõ ïðîäàæ
extern color clObjSellLoss = Red; // Öâåò óáûòî÷íûõ ïðîäàæ
extern string _P_Arrows = "---------- Ïàðàìåòðû óêàçàòåëåé";
extern bool ShowArrow = True; // Ïîêàçûâàòü óêàçàòåëè
extern int KodArrowBuy = 241; // Êîä óêàçàòåëÿ ïîêóïêè
extern int OffSetArrowBuy = -20; // Ñìåùåíèå óêàçàòåëÿ ïîêóïêè
extern color clArrowBuy = Blue; // Öâåò óêàçàòåëÿ ïîêóïêè
extern int KodArrowSell = 242; // Êîä óêàçàòåëÿ ïðîäàæè
extern int OffSetArrowSell = 20; // Ñìåùåíèå óêàçàòåëÿ ïðîäàæè
extern color clArrowSell = Red; // Öâåò óêàçàòåëÿ ïðîäàæè
extern string _P_Text = "---------- Ïàðàìåòðû òåêñòà";
extern bool ShowTextBalance = True; // Ïîêàçûâàòü òåêñò áàëàíñà
extern int OffSetText = 100; // Ñìåùåíèå òåêñòà
extern int SizeText = 9; // Ðàçìåð òåêñòà
extern color clTextProfit = Green; // Öâåò ñóììû ïðèáûëè
extern color clTextLoss = Red; // Öâåò ñóììû óáûòêà
extern color clTextBalans = Green; // Öâåò ñóììû áàëàíñà
//------- Ãëîáàëüíûå ïåðåìåííûå --------------------------------------
int frogBalance = 0;
string frogNameObjLine = "LDeal"; // Íàèìåíîâàíèÿ îáúåêòîâ ËÈÍÈß
string frogNameObjRect = "RDeal"; // Íàèìåíîâàíèÿ îáúåêòîâ ÏÐßÌÎÓÃÎËÜÍÈÊ
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
void start()
{
datetime dt;
double pp;
int or, pos;
string op, str;
int fh=FileOpen(FileName, FILE_BIN|FILE_READ);
if (fh>0)
{
if (DeleteOldObjects) ObjectsDeleteAll();
while (!FileIsEnding(fh))
{
pos=StringFind(str, "<td class=msdate>");
if (pos>0)
{
str=str+GetStringFromFile(fh, 250-StringLen(str));
str=StringSubstr(str, pos+17);
dt =StrToTime(StringSubstr(str, 0, 16));
str=StringSubstr(str, 25);
pos=StringFind (str, "</td><td>");
op =StringSubstr(str, 0, pos);
str=StringSubstr(str, pos+9);
pos=StringFind (str, "</td><td>");
or =StrToInteger(StringSubstr(str, 0, pos));
str=StringSubstr(str, pos+9);
pos=StringFind (str, "</td><td>");
str=StringSubstr(str, pos+9);
pos=StringFind (str, "</td><td");
pp =StrToDouble (StringSubstr(str, 0, pos));
Comment("Ïîçèöèÿ: "+or);
switch (TypeObjects)
{
case 0: SetPropRectangle(dt, op, or, pp); break;
default: SetPropLines(dt, op, or, pp); break;
}
if (ShowArrow) SetPropArrow(dt, op, or, pp);
if (ShowTextBalance) SetPropText(dt, op, or, pp);
str=str+GetStringFromFile(fh, 250-StringLen(str));
} else {
str=StringSubstr(str, 125);
str=str+GetStringFromFile(fh, 125);
}
}
FileClose(fh);
} else Comment("Îøèáêà îòêðûòèÿ ôàéëà îò÷¸òà "+FileName);
}
//+------------------------------------------------------------------+
//| ×èòàåò ñòðîêîâûé áëîê èç ôàéëà |
//| Ïàðàìåòðû: |
//| fh - õýíäë ôàéëà |
//| ks - êîëè÷åñòâî ñèìâîëîâ |
//+------------------------------------------------------------------+
string GetStringFromFile(int& fh, int ks)
{
string str="", s;
while (StringLen(str)<ks && !FileIsEnding(fh))
{
s=FileReadString(fh, 1);
if (StringGetChar(s, 0)>31) str=str+s;
}
return(str);
}
//+------------------------------------------------------------------+
//| Óñòàíîâêà ñâîéñòâ îáúåêòà ÓÊÀÇÀÒÅËÜ |
//| Ïàðàìåòðû: |
//| dt - äàòà, âðåìÿ |
//| op - îïåðàöèÿ |
//| or - íîìåð îðäåðà (îáúåêòà) |
//| pp - öåíà |
//+------------------------------------------------------------------+
void SetPropArrow(datetime dt, string op, int or, double pp)
{
string no="ADeal";
if (op=="buy" || op=="sell")
{
if (ObjectFind(no+or)<0) ObjectCreate(no+or, OBJ_ARROW, 0, 0,0);
ObjectSet(no+or, OBJPROP_TIME1, dt);
if (op=="buy")
{
ObjectSet(no+or, OBJPROP_PRICE1 , pp+OffSetArrowBuy*Point);
ObjectSet(no+or, OBJPROP_COLOR , clArrowBuy);
ObjectSet(no+or, OBJPROP_ARROWCODE, KodArrowBuy);
}
if (op=="sell")
{
ObjectSet(no+or, OBJPROP_PRICE1 , pp+OffSetArrowSell*Point);
ObjectSet(no+or, OBJPROP_COLOR , clArrowSell);
ObjectSet(no+or, OBJPROP_ARROWCODE, KodArrowSell);
}
}
}
//+------------------------------------------------------------------+
//| Óñòàíîâêà ñâîéñòâ îáúåêòà ËÈÍÈß ÒÐÅÍÄÀ |
//| Ïàðàìåòðû: |
//| dt - äàòà, âðåìÿ |
//| op - îïåðàöèÿ |
//| or - íîìåð îðäåðà (îáúåêòà) |
//| pp - öåíà |
//+------------------------------------------------------------------+
void SetPropLines(datetime dt, string op, int or, double pp)
{
color cl;
double p1, p2;
string no=frogNameObjLine;
if (op=="buy" || op=="sell")
{
if (ObjectFind(no+or)<0) ObjectCreate(no+or, OBJ_TREND, 0, 0,0, 0,0);
ObjectSet(no+or, OBJPROP_TIME1 , dt);
ObjectSet(no+or, OBJPROP_PRICE1, pp);
} else {
ObjectSet(no+or, OBJPROP_TIME2 , dt);
ObjectSet(no+or, OBJPROP_PRICE2, pp);
}
if (op=="buy") ObjectSet(no+or, OBJPROP_COLOR, clObjBuy);
if (op=="sell") ObjectSet(no+or, OBJPROP_COLOR, clObjSell);
ObjectSet(no+or, OBJPROP_RAY , False);
p1=ObjectGet(no+or, OBJPROP_PRICE1);
p2=ObjectGet(no+or, OBJPROP_PRICE2);
cl=ObjectGet(no+or, OBJPROP_COLOR);
if (p1!=0 && p2!=0)
{
if (cl==clObjBuy)
{
if (p1>p2) ObjectSet(no+or, OBJPROP_COLOR, clObjBuyLoss);
}
if (cl==clObjSell)
{
if (p1<p2) ObjectSet(no+or, OBJPROP_COLOR, clObjSellLoss);
}
}
}
//+------------------------------------------------------------------+
//| Óñòàíîâêà ñâîéñòâ îáúåêòà ÏÐßÌÎÓÃÎËÜÍÈÊ |
//| Ïàðàìåòðû: |
//| dt - äàòà, âðåìÿ |
//| op - îïåðàöèÿ |
//| or - íîìåð îðäåðà (îáúåêòà) |
//| pp - öåíà |
//+------------------------------------------------------------------+
void SetPropRectangle(datetime dt, string op, int or, double pp)
{
color cl;
double p1, p2;
string no=frogNameObjRect;
if (op=="buy" || op=="sell")
{
if (ObjectFind(no+or)<0) ObjectCreate(no+or, OBJ_RECTANGLE, 0, 0,0, 0,0);
ObjectSet(no+or, OBJPROP_TIME1 , dt);
ObjectSet(no+or, OBJPROP_PRICE1, pp);
} else {
ObjectSet(no+or, OBJPROP_TIME2 , dt);
ObjectSet(no+or, OBJPROP_PRICE2, pp);
}
if (op=="buy") ObjectSet(no+or, OBJPROP_COLOR, clObjBuy);
if (op=="sell") ObjectSet(no+or, OBJPROP_COLOR, clObjSell);
ObjectSet(no+or, OBJPROP_BACK , True);
p1=ObjectGet(no+or, OBJPROP_PRICE1);
p2=ObjectGet(no+or, OBJPROP_PRICE2);
cl=ObjectGet(no+or, OBJPROP_COLOR);
if (p1!=0 && p2!=0)
{
if (cl==clObjBuy)
{
if (p1>p2) ObjectSet(no+or, OBJPROP_COLOR, clObjBuyLoss);
}
if (cl==clObjSell)
{
if (p1<p2) ObjectSet(no+or, OBJPROP_COLOR, clObjSellLoss);
}
}
}
//+------------------------------------------------------------------+
//| Óñòàíîâêà ñâîéñòâ îáúåêòîâ ÒÅÊÑÒ |
//| Ïàðàìåòðû: |
//| dt - äàòà, âðåìÿ |
//| op - îïåðàöèÿ |
//| or - íîìåð îðäåðà (îáúåêòà) |
//| pp - öåíà |
//+------------------------------------------------------------------+
void SetPropText(datetime dt, string op, int or, double pp)
{
color cl, clText;
double p1, p2, ss;
string no, no1="T1Deal", no2="T2Deal";
if (TypeObjects==0) no=frogNameObjRect; else no=frogNameObjLine;
p1=ObjectGet(no+or, OBJPROP_PRICE1);
p2=ObjectGet(no+or, OBJPROP_PRICE2);
cl=ObjectGet(no+or, OBJPROP_COLOR);
if (p1!=0 && p2!=0)
{
if (ObjectFind(no1+or)<0) ObjectCreate(no1+or, OBJ_TEXT, 0, 0,0);
if (ObjectFind(no2+or)<0) ObjectCreate(no2+or, OBJ_TEXT, 0, 0,0);
ObjectSet(no1+or, OBJPROP_TIME1 , dt);
ObjectSet(no2+or, OBJPROP_TIME1 , dt);
ObjectSet(no1+or, OBJPROP_PRICE1, pp+OffSetText*Point);
ObjectSet(no2+or, OBJPROP_PRICE1, pp-OffSetText*Point);
if (cl==clObjBuy || cl==clObjBuyLoss)
{
ss=(p2-p1)/Point;
frogBalance+=ss;
if (ss<0) clText=clTextLoss; else clText=clTextProfit;
ObjectSetText(no1+or, DoubleToStr(ss, 0), SizeText, "", clText);
ObjectSetText(no2+or, DoubleToStr(frogBalance, 0), SizeText, "", clTextBalans);
}
if (cl==clObjSell || cl==clObjSellLoss)
{
ss=(p1-p2)/Point;
frogBalance+=ss;
if (ss<0) clText=clTextLoss; else clText=clTextProfit;
ObjectSetText(no1+or, DoubleToStr(ss, 0), SizeText, "", clText);
ObjectSetText(no2+or, DoubleToStr(frogBalance, 0), SizeText, "", clTextBalans);
}
}
}
//+------------------------------------------------------------------+
Comments