qShowTrades

Author: Copyright � 2011, Thomas Quester
qShowTrades

This script is designed to provide a visual history of your trading activity directly on your MetaTrader 4 charts. Instead of having to scroll through complex menus or historical logs to see how your past trades performed, this tool automatically draws the trajectory of completed transactions as visual lines on your screen.

Core Functionality

The script monitors your account's trade history. Whenever it detects that a new trade has been finalized (closed), it triggers an update to the chart. It specifically identifies closed "Buy" and "Sell" orders for the specific currency pair or asset you are currently viewing.

How the Visuals Work

For every completed trade identified in your history, the script creates a trend line that connects two key points:

  • The Starting Point: Where the trade was opened (the entry price).
  • The Ending Point: Where the trade was closed (the exit price).

To make the data easy to interpret at a glance, the script applies specific styling based on the outcome of each trade:

  • Profitability Color Coding: If a trade resulted in a profit, the line is drawn in Green. If it resulted in a loss, the line is drawn in Red.
  • Trade Type Distinction: The script distinguishes between "Buy" and "Sell" orders. For example, "Sell" trades may be displayed with a dashed line style to differentiate them from standard "Buy" entries.
  • Labels: Each line is labeled with the type of trade and its entry price, ensuring you can identify specific moves quickly.

Smart Filtering Features

To ensure the chart remains clean and relevant, the script includes two important logic layers:

  1. Asset Specificity: The script only draws lines for the current symbol you are viewing. This prevents your chart from becoming cluttered with trades from other currency pairs or assets.
  2. Demo Mode Protection: There is a built-in safety check that can prevent the script from running on historical data prior to a specific date (set by default to early 2012). This ensures that the tool focuses on your relevant modern trading activity rather than outdated historical logs.

Summary for the User

Essentially, this tool acts as a "visual diary" of your trading performance. It transforms raw numbers from your history into a clear, color-coded map of your successes and mistakes, allowing you to see the "shape" of your trading history directly on your active charts.

Orders Execution
Checks for the total of closed orders
9 Views
0 Downloads
0 Favorites
qShowTrades
//+------------------------------------------------------------------+
//|                                                   ShowTrades.mq4 |
//|                                 Copyright © 2011, Thomas Quester |
//|                                                 www.mt4expert.de |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Thomas Quester"
#property link      "www.mt4expert.de"
#property indicator_chart_window


//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+

bool   gTimeDemo=true;
int    gDemoDate=1;
int    gDemoMonth=1;
int    gDemoYear=2012;
int    gOldCnt=0;
int init()
{
   gOldCnt = 0;
}

int start()

  {
//----
   int cnt;
   int i,typ;
    if (gTimeDemo)
    {
        int t,m,y;
        t = TimeDay(Time[0]);
        m = TimeMonth(Time[0]);
        y = TimeYear(Time[0]);
        if (y >= gDemoYear &&
            m >= gDemoMonth &&
            t >= gDemoDate)
               return(0);
    }

   cnt = OrdersHistoryTotal();
   if (cnt != gOldCnt)
   {
      gOldCnt = cnt;
      Print("ShowTraces start");
      
      string name;
      datetime ostart, oend;
      double   open, close;
   
      Print("cnt = "+cnt);
      for (i=0;i<15000;i++)
      {
    
          ObjectDelete("trades_"+i);
      }
   
      for (i=0;i<cnt;i++)
      { 
          Print("Order 1 = "+OrderSymbol());
          if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) == false) break;
          if (OrderSymbol() == Symbol())
          {
             typ = OrderType();
             if (typ == OP_BUY || typ == OP_SELL)
             {
               ostart = OrderOpenTime();
               oend   = OrderCloseTime();
               open   = OrderOpenPrice();
               close  = OrderClosePrice();
               Print("o=",ostart," ",open," ",oend," ",close);
               ObjectCreate("trades_"+i,OBJ_TREND,0,ostart,open,oend,close);
               ObjectSet("trades_"+i,OBJPROP_RAY,false);
               if (OrderProfit() > 0)
                   ObjectSet("trades_"+i,OBJPROP_COLOR,Green);
               else
                   ObjectSet("trades_"+i,OBJPROP_COLOR,Red);
           
               name="";   
          
               switch(typ)
               {
                  case OP_BUY: name = "buy"; break;
                  case OP_SELL: name = "sell"; break;
                  case OP_BUYSTOP: name = "buystop"; break;
                  case OP_SELLSTOP: name = "sellstop"; break;
               }
               name = name + " " + open;
               ObjectSetText("trades_"+i,name, 10, "Times New Roman", Green);
               if (typ == OP_SELL)       
                  ObjectSet("trades_"+i,OBJPROP_STYLE,STYLE_DASH);
               ObjectSet("trades_"+i,OBJPROP_WIDTH,2);
             }
          }
      }
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments