BETTER_YZGraphOnLine_W
Download scriptThis script is designed to act as a visual history and real-time tracker for your trading activities on MetaTrader. It automatically processes both past completed trades and currently active positions, translating them into a clear visual map on your price chart.
Core Functionality
1. Visual Trade Mapping The script identifies every trade you have made (or are currently holding) and places specific visual markers on the chart. Instead of just seeing a list of numbers in your terminal, the script draws:
- Entry Markers: Arrows indicating exactly where a "Buy" or "Sell" position was opened.
- Exit Markers: Specific arrows identifying where a trade was closed. These change appearance based on whether the trade hit a specific target or ended otherwise.
- Price Lines: It draws trend lines connecting your entry price to your exit price, creating a "path" for each trade.
2. Dynamic Visual Feedback The script is intelligent enough to change the colors and styles of these visual elements based on the outcome of the trade:
- Profit vs. Loss: It detects the direction of the price movement. For example, if a "Buy" trade results in a lower closing price than the opening price, the script can adjust the color or line style to visually distinguish it as a losing trade.
- Status Indicators: It recognizes specific types of closures (like hitting a Stop Loss) and uses different arrow codes or colors to highlight those events instantly.
3. Performance Tracking The script includes an automated calculation for your trading performance:
- Pip Accumulator: It calculates the "Pips" (the unit of price movement) for each trade.
- On-Screen Display: It maintains a running total of these pips and displays the cumulative result directly on your chart in a readable text label. This allows you to see your total performance at a glance without manually doing the math.
4. Data Logging Beyond just drawing on the screen, the script performs a "housekeeping" task:
- It scans your trading history and creates a dedicated data file (
YZSIGNAL.DAT). - This file logs essential details for every trade—including ticket numbers, lot sizes, and exact timestamps for both opening and closing—providing you with a permanent, organized record of your activity.
Summary of User Experience
For a trader, this means that as soon as the script runs, your chart becomes a comprehensive visual diary. You can see where you entered, how far the price moved, exactly where you exited, whether those exits were successful or not, and your total pip performance, all while the system automatically saves this data to your computer for future reference.
//+------------------------------------------------------------------+
//| |
//| Copyright © 1999-2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.ru |
//+------------------------------------------------------------------+
//
// Ñêðèïò ñîçäàí ïî ìîòèâàì ñêðèïòà Èãðÿ Êèìà KimIV www.kimiv.ru
//
#property copyright "YURAZ YZH"
#property link "yzh@mail.ru"
#property show_inputs
//extern bool DeleteOldObjects = True; // Óäàëÿòü ñòàðûå îáúåêòû
extern string _P_Objects="---------- Ïàðàìåòðû îáúåêòîâ";
//extern int TypeObjects = 1; // Òèï îáúåêòîâ (0-ïðÿìîóã. 1-ëèíèÿ)
extern color clObjBuy =Aqua; // Öâåò ïðèáûëüíûõ ïîêóïîê
extern color clObjBuyLoss =Aqua; // Blue; // Öâåò óáûòî÷íûõ ïîêóïîê
extern color clObjSell =Salmon; // Öâåò ïðèáûëüíûõ ïðîäàæ
extern color clObjSellLoss =Salmon; // Red; // Öâåò óáûòî÷íûõ ïðîäàæ
extern string _P_Arrows="---------- Ïàðàìåòðû óêàçàòåëåé";
//extern bool ShowArrow = True; // Ïîêàçûâàòü óêàçàòåëè
extern int KodArrowBuy =2; // Êîä óêàçàòåëÿ ïîêóïêè
extern int OffSetArrowBuy =0; // -20; // Ñìåùåíèå óêàçàòåëÿ ïîêóïêè
extern color clArrowBuy =Blue; // Öâåò óêàçàòåëÿ ïîêóïêè
extern int KodArrowSell =1; // Êîä óêàçàòåëÿ ïðîäàæè
extern int OffSetArrowSell =0; // 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; // Öâåò ñóììû áàëàíñà
extern int KodArrowCloseBuy =3;
extern int KodArrowCloseSell=3;
static int ALLPIP=0;
//------- Ãëîáàëüíûå ïåðåìåííûå --------------------------------------
int frogBalance =0;
string frogNameObjLine="LDeal"; // Íàèìåíîâàíèÿ îáúåêòîâ ËÈÍÈß
string frogNameObjRect="RDeal"; // Íàèìåíîâàíèÿ îáúåêòîâ ÏÐßÌÎÓÃÎËÜÍÈÊ
//-----
string SIGNAL;
string name;
int arrow_code;
int iBar;
datetime datetime_object;
int len;
int fW ;
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
void start()
{
int iPos=0;
datetime dattimeOpen;
datetime dattimeClose;
double OpenPrice;
double ClosePrice;
fW=FileOpen ("YZSIGNAL.DAT",FILE_BIN|FILE_WRITE);
// SIGNAL = "B|"+TimeToStr( TimeCurrent() ,TIME_DATE|TIME_MINUTES|TIME_SECONDS)+"\n" ;
// FileWriteDouble( fW, StringLen(SIGNAL), 8 ); // çàïèøåì çàãîëîâîê
iPos=0;
while( true) // ïîñìîòðèì èñòîðèþ
{
if (OrderSelect( iPos , SELECT_BY_POS, MODE_HISTORY)==false )
break;
if(OrderType()==OP_BUY) // BUY
{
SIGNAL="B|"+OrderTicket()+"|"+OrderLots()+"|"+TimeToStr( OrderOpenTime() ,TIME_DATE|TIME_MINUTES|TIME_SECONDS)+"|"+TimeToStr( OrderCloseTime() ,TIME_DATE|TIME_MINUTES|TIME_SECONDS)+"|";
}
if(OrderType()==OP_SELL)// SELL
{
SIGNAL="S|"+OrderTicket()+"|"+OrderLots()+"|"+TimeToStr( OrderOpenTime() ,TIME_DATE|TIME_MINUTES|TIME_SECONDS)+"|"+TimeToStr( OrderCloseTime() ,TIME_DATE|TIME_MINUTES|TIME_SECONDS)+"|";
}
len=StringLen(SIGNAL);
FileWriteString( fW, SIGNAL, len );
if(OrderSymbol()==Symbol() )
{
// if ( StringSubstr ( OrderComment(), 0,3) == "[0]" )
SetPropArrow( OrderType(), OrderLots(), OrderTicket() , OrderOpenTime() ,OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit(), OrderCloseTime() ,OrderClosePrice(), OrderComment() );
}
iPos++;
}
iPos=0;
while( true) // îòêðûòûå îðäåðà òîæå ïîñòàâèì
{
if (OrderSelect( iPos , SELECT_BY_POS, MODE_TRADES)==false )
break;
if(OrderSymbol()==Symbol() )
{
// if ( StringSubstr ( OrderComment(), 0,3) == "[0]" )
SetPropArrow( OrderType(), OrderLots(), OrderTicket() , OrderOpenTime() ,OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit(), 0 ,0 ,OrderComment() );
}
iPos++;
}
FileClose(fW);
}
//+------------------------------------------------------------------+
//| Óñòàíîâêà ñâîéñòâ îáúåêòà ÓÊÀÇÀÒÅËÜ |
//| Ïàðàìåòðû: |
//| |
//| op - îïåðàöèÿ |
//| or - íîìåð îðäåðà (îáúåêòà) |
//| dtopen - äàòà, âðåìÿ îòêðûòèÿ |
//| price pp - öåíà îòêðûòèÿ |
//| dtclose - äàòà âðåìÿ çàêðûòèÿ |
//| priceclose - öåíà çàêðûòèÿ |
//+------------------------------------------------------------------+
void SetPropArrow( int op, double Lots, int or, datetime dtopen, double pOpen, double pSL,double pTP, datetime dtclose, double priceclose, string sComment)
{
string no="ADeal";
string oc="Close";
string osl="SL";
string otp="TP";
if (op==OP_BUY || op==OP_SELL )
{
if(op==OP_BUY )
{
no=OrderTicket()+"BUY"+no+" "+DoubleToStr((priceclose-pOpen)/Point,0)+" ";
}
if(op==OP_SELL )
{
no=OrderTicket()+"SEL"+no+" "+DoubleToStr ((pOpen-priceclose)/Point,0)+" ";
}
if(op==OP_BUY )
oc=OrderTicket()+"BUY"+oc+" "+DoubleToStr ((priceclose-pOpen)/Point,0)+" ";
if(op==OP_SELL )
oc=OrderTicket()+"SEL"+oc+" "+DoubleToStr ((pOpen-priceclose)/Point,0)+" ";
osl=OrderTicket()+osl+" "+DoubleToStr ((pSL)/Point,0);
otp=OrderTicket()+otp+" "+DoubleToStr ((pSL)/Point,0);
if (ObjectFind(osl) < 0)
{
if(( op==OP_BUY && pSL > pOpen && pSL==priceclose )
||
(op==OP_SELL && pSL < pOpen && pSL==priceclose )
)
{
ObjectCreate(osl, OBJ_ARROW, 0, 0,0);
ObjectSet(osl, OBJPROP_PRICE1 , pSL) ;
ObjectSet(osl, OBJPROP_COLOR , clArrowBuy);
ObjectSet(osl, OBJPROP_ARROWCODE, 34);
if(dtclose==0 )
ObjectSet(osl, OBJPROP_TIME1, dtopen );
else
ObjectSet(osl, OBJPROP_TIME1, dtclose );
}
}
if (ObjectFind(no+or) < 0)
{
ObjectCreate(no+or, OBJ_ARROW, 0, 0,0);
}
ObjectSet(no+or, OBJPROP_TIME1, dtopen);
if (priceclose!=0)
{
if (ObjectFind(oc+dtclose)<0)
ObjectCreate(oc+dtclose, OBJ_ARROW, 0, 0,0);
ObjectSet(oc+dtclose, OBJPROP_TIME1, dtclose);
int PIP;
if (op==OP_BUY)
PIP = (priceclose - pOpen ) / Point;
if (op==OP_SELL)
PIP= (pOpen - priceclose) / Point;
ALLPIP = ALLPIP + PIP;
if (ObjectFind("ALLPIP") < 0 )
{
ObjectCreate( "ALLPIP",OBJ_LABEL,0,0,0,0,0,0);
ObjectSet("ALLPIP", OBJPROP_XDISTANCE,100);
ObjectSet("ALLPIP", OBJPROP_YDISTANCE, 20 );
ObjectSet("ALLPIP", OBJPROP_CORNER, 1);
}
ObjectSetText("ALLPIP", DoubleToStr(ALLPIP,0) , 15 , "Arial", Aqua );
ObjectCreate( oc+dtclose+PIP,OBJ_TEXT,0,0,0,0,0,0);
ObjectSetText( oc+dtclose+PIP, DoubleToStr(PIP,0), 12 , "Times New Roman", DarkBlue) ;
ObjectSet(oc+dtclose+PIP, OBJPROP_TIME1, dtclose-5300);
ObjectSet(oc+dtclose+PIP,OBJPROP_COLOR, DarkBlue);
if (op==OP_BUY)
ObjectSet(oc+dtclose+PIP, OBJPROP_PRICE1 , priceclose+50*Point);
if (op==OP_SELL)
ObjectSet(oc+dtclose+PIP, OBJPROP_PRICE1 , priceclose-50*Point);
/*
ObjectCreate( oc+dtclose+Lots,OBJ_TEXT,0,0,0,0,0,0);
ObjectSetText( oc+dtclose+Lots, DoubleToStr(Lots,2), 9 , "Times New Roman", Red) ;
ObjectSet(oc+dtclose+Lots, OBJPROP_TIME1, dtclose-35000);
ObjectSet(oc+dtclose+Lots,OBJPROP_COLOR, Red);
if (op==OP_BUY)
ObjectSet(oc+dtclose+Lots, OBJPROP_PRICE1 , priceclose+50*Point);
if (op==OP_SELL)
ObjectSet(oc+dtclose+Lots, OBJPROP_PRICE1 , priceclose-50*Point);
*/
}
if (op==OP_BUY)
{
ObjectSet(no+or, OBJPROP_PRICE1 , pOpen+OffSetArrowBuy*Point);
ObjectSet(no+or, OBJPROP_COLOR , clArrowBuy);
ObjectSet(no+or, OBJPROP_ARROWCODE, KodArrowBuy);
if (priceclose!=0)
{
ObjectSet(oc+dtclose, OBJPROP_PRICE1 , priceclose);
ObjectSet(oc+dtclose, OBJPROP_COLOR , clArrowBuy);
ObjectSet(oc+dtclose, OBJPROP_ARROWCODE, KodArrowCloseBuy);
if(StringFind(sComment,"sl",0)!=-1 )
{
ObjectSet(oc+dtclose, OBJPROP_COLOR , Red );
ObjectSet(oc+dtclose, OBJPROP_ARROWCODE, 251 );
}
if(/*StringFind(sComment,"tp",0) != -1 ||*/ priceclose==pTP )
{
ObjectSet(oc+dtclose, OBJPROP_COLOR , DarkBlue);
ObjectSet(oc+dtclose, OBJPROP_ARROWCODE, 174 );
}
SetPropLines( op, Lots, or, dtopen , pOpen, dtclose, priceclose , 1, sComment);
}
else
{
ObjectSet(oc+Time[0], OBJPROP_PRICE1 , Bid);
ObjectSet(oc+Time[0], OBJPROP_COLOR , clArrowSell);
ObjectSet(oc+Time[0], OBJPROP_ARROWCODE, KodArrowCloseSell);
if(StringFind(sComment,"sl",0)!=-1 )
{
ObjectSet(oc+dtclose, OBJPROP_COLOR , Red );
ObjectSet(oc+dtclose, OBJPROP_ARROWCODE, 251 );
}
if(/* StringFind(sComment,"tp",0) != -1 || */ priceclose==pTP )
{
ObjectSet(oc+dtclose, OBJPROP_COLOR , DarkBlue);
ObjectSet(oc+dtclose, OBJPROP_ARROWCODE, 174 );
}
SetPropLines( op, Lots, or, dtopen , pOpen, Time[0], Bid, 0, sComment);
}
}
if (op==OP_SELL)
{
ObjectSet(no+or, OBJPROP_PRICE1 , pOpen+OffSetArrowSell*Point);
ObjectSet(no+or, OBJPROP_COLOR , clArrowSell);
ObjectSet(no+or, OBJPROP_ARROWCODE, KodArrowSell);
if (priceclose!=0)
{
ObjectSet(oc+dtclose, OBJPROP_PRICE1 , priceclose);
ObjectSet(oc+dtclose, OBJPROP_COLOR , clArrowSell);
ObjectSet(oc+dtclose, OBJPROP_ARROWCODE, KodArrowCloseSell);
if (/* StringFind(sComment,"tp",0) != -1 || */priceclose==pTP )
{
ObjectSet(oc+dtclose, OBJPROP_COLOR , DarkBlue);
ObjectSet(oc+dtclose, OBJPROP_ARROWCODE, 174 );
}
SetPropLines( op, Lots, or, dtopen , pOpen, dtclose, priceclose, 1, sComment);
}
else
{
ObjectSet(oc+Time[0], OBJPROP_PRICE1 , Ask);
ObjectSet(oc+Time[0], OBJPROP_COLOR , clArrowSell);
ObjectSet(oc+Time[0], OBJPROP_ARROWCODE, KodArrowCloseSell);
if(/* StringFind(sComment,"tp",0) != -1 || */ priceclose==pTP )
{
ObjectSet(oc+dtclose, OBJPROP_COLOR , DarkBlue);
ObjectSet(oc+dtclose, OBJPROP_ARROWCODE, 174 );
}
SetPropLines( op, Lots, or, dtopen , pOpen, Time[0], Ask, 0, sComment);
}
}
}
}
//+------------------------------------------------------------------+
//| Óñòàíîâêà ñâîéñòâ îáúåêòà ËÈÍÈß ÒÐÅÍÄÀ |
//| Ïàðàìåòðû: |
//| dt - äàòà, âðåìÿ |
//| op - îïåðàöèÿ |
//| or - íîìåð îðäåðà (îáúåêòà) |
//| pp - öåíà |
//+------------------------------------------------------------------+
void SetPropLines( int op, double Lots, int or, datetime dt, double pp, datetime pÂðåìÿÇàêðûòèÿ,double pÖåíàÇàêðûòèÿ,int FlOpen, string sComment)
{
color cl;
double p1, p2;
string no=frogNameObjLine;
if (op==OP_BUY)
no=OrderTicket()+no+" "+ DoubleToStr((pÖåíàÇàêðûòèÿ-pp)/Point,0)+" "+DoubleToStr(Lots,2)+" ";
if(op==OP_SELL )
no=OrderTicket()+no+" " + DoubleToStr((pp-pÖåíàÇàêðûòèÿ)/Point ,0)+" "+DoubleToStr(Lots,2)+" ";
if (op==OP_BUY || op==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);
ObjectSet(no+or, OBJPROP_TIME2 , pÂðåìÿÇàêðûòèÿ);
ObjectSet(no+or, OBJPROP_PRICE2, pÖåíàÇàêðûòèÿ);
}
if (op==OP_BUY)
ObjectSet(no+or, OBJPROP_COLOR, clObjBuy);
if (op==OP_SELL)
ObjectSet(no+or, OBJPROP_COLOR, clObjSell);
ObjectSet(no+or, OBJPROP_RAY , False);
if(FlOpen==0 )
{
ObjectSet( no+or, OBJPROP_STYLE, DRAW_LINE );
ObjectSet( no+or, OBJPROP_STYLE, STYLE_DOT );
// ObjectSet( no+or, OBJPROP_COLOR, );
}
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);
ObjectSet( no+or, OBJPROP_STYLE, DRAW_LINE );
ObjectSet( no+or, OBJPROP_STYLE, STYLE_DOT );
}
}
if (cl==clObjSell)
{
if (p1<p2)
{
ObjectSet(no+or, OBJPROP_COLOR, clObjSellLoss);
ObjectSet( no+or, OBJPROP_STYLE, DRAW_LINE );
ObjectSet( no+or, OBJPROP_STYLE, STYLE_DOT );
}
}
}
}
//+------------------------------------------------------------------+
Comments