BETTER_YZGraphOnLine

Download script
Author: YURAZ YZH
BETTER_YZGraphOnLine

This script is designed to act as a visual auditing and reporting tool for trading history. It automatically scans your past and current trades to provide a detailed, graphical representation of your performance directly on the trading chart.

Here is a breakdown of how the logic works:

Data Collection & Logging

When you run the script, it begins by scanning your account history. It identifies every "Buy" and "Sell" trade you have executed. For each trade found, it extracts key information such as:

  • Unique Ticket Numbers
  • Trade Volume (Lots)
  • Exact Date and Time of opening and closing
  • Entry and Exit prices

The script then saves this data into a local file (YZSIGNAL.DAT). This ensures that the trading activity is logged systematically as the script processes the information.

Visual Mapping on Charts

Instead of just looking at a list of numbers, the script "draws" your trading history onto the chart using several visual elements:

  • Entry and Exit Markers: It places specific arrows (or symbols) on the chart to show exactly where you entered a trade and where it ended.
  • Dynamic Coloring: The script intelligently changes colors based on the outcome of the trade. For example, if a "Buy" trade resulted in a loss, it can adjust the visual style to distinguish it from a profitable one.
  • Trend Lines: It draws lines connecting your entry price to your exit price. These lines provide a clear visual path of how a specific trade moved over time.
  • Profit/Loss Indicators: For closed trades, the script calculates the distance between the entry and exit prices (in pips) and places a text label on the chart showing exactly how many pips were gained or lost for that specific position.

Real-Time & Historical Tracking

The script logic is split into two main phases:

  1. History Processing: It loops through all your closed trades to reconstruct your past performance visually.
  2. Active Trade Monitoring: It also scans currently open positions. For these, it places the entry markers and monitors the live prices to prepare the visual data for when the trade eventually closes.

Specialized Visual Cues

  • Stop Loss Tracking: The logic includes specific checks to identify if a trade was closed specifically by hitting a Stop Loss (SL) or Take Profit (TP) level, sometimes changing the arrow icons to notify you of these specific exit conditions.
  • On-Screen Totals: It maintains a running tally of pips gained or lost and displays this information as a live label on your screen, allowing for a quick summary of total performance at a glance.

Summary for the User: Essentially, this script transforms your "Account History" tab into a visual map. It replaces manual calculations with automatic drawings, showing you exactly where you traded, how far the price moved, and whether those moves resulted in profit or loss, all while keeping an organized log of the data in the background.

Price Data Components
Series array that contains open time of each bar
Miscellaneous
It writes information to file
16 Views
0 Downloads
0 Favorites
BETTER_YZGraphOnLine
//+------------------------------------------------------------------+
//|                                                                  |
//|                 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",  Yellow) ;
         ObjectSet(oc+dtclose+PIP, OBJPROP_TIME1, dtclose-5300);
         ObjectSet(oc+dtclose+PIP,OBJPROP_COLOR, Yellow);
         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    , Yellow);
               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    , Yellow);
               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    , Yellow);
               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    , Yellow);
               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