Visualize tradehistory ?

 

Hi, does anyone have an indicator or EA that can read the tradehistory and visualize it on the chart, like the B/S symbols we get when backtesting ?

 

I'd like this indicator/script/EA as well.

 
DayTrader:

Hi, does anyone have an indicator or EA that can read the tradehistory and visualize it on the chart, like the B/S symbols we get when backtesting ?

There's probably already something in the codebase to do this, and you could add endless refinements to such a thing, but the following script will draw markers for all the closed trades in the history for the chart symbol on which you run the script:

#property show_inputs

extern string  s_Display = "=== Display===";
extern bool    ShowPriceLabelsInsteadOfArrows = false;

extern string  s_Colours = "=== Colours ===";
extern color   Colour_LongWinner = Blue;
extern color   Colour_ShortWinner = Blue;
extern color   Colour_LongLoser = Red;
extern color   Colour_ShortLoser = Red;


int start()
{
   // Look for all historic orders for the current chart symbol 
   for (int i = 0; i < OrdersHistoryTotal(); i++) {
      if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
         if (OrderSymbol() == Symbol()) {
            DrawSelectedOrder();
         }
      }
   }

   return(0);
}


bool DrawSelectedOrder()
{
   // Ignore cancelled pending orders 
   if (OrderType() != OP_BUY && OrderType() != OP_SELL) return (false);

   // Build an order description
   string strDescription = "Ticket #" + OrderTicket() + ": result " + AccountCurrency() + " " + DoubleToStr(OrderProfit() + OrderCommission() + OrderSwap(), 2);

   // Get colour to use
   int lColour;
   if (OrderProfit() + OrderSwap() + OrderCommission() >= 0) {
      if (OrderType() == OP_BUY) {
         lColour = Colour_LongWinner;
      } else {
         lColour = Colour_ShortWinner;
      }
   } else {
      if (OrderType() == OP_BUY) {
         lColour = Colour_LongLoser;
      } else {
         lColour = Colour_ShortLoser;
      }
   }

   // Create two arrows/price-labels and a dotted line connecting them 
   string strObjOpen = "TMOpen" + OrderTicket();
   if (ObjectFind(strObjOpen) >= 0) ObjectDelete(strObjOpen);
   ObjectCreate(strObjOpen, OBJ_ARROW, 0, OrderOpenTime(), OrderOpenPrice());
   if (ShowPriceLabelsInsteadOfArrows) {
      ObjectSet(strObjOpen, OBJPROP_ARROWCODE, SYMBOL_LEFTPRICE);
   } else {
      ObjectSet(strObjOpen, OBJPROP_ARROWCODE, 1);    // Standard backtesting right-facing arrow
   }
   ObjectSet(strObjOpen, OBJPROP_COLOR, lColour);
   ObjectSetText(strObjClose, strDescription, 10);
   
   string strObjClose = "TMClose" + OrderTicket();
   if (ObjectFind(strObjClose) >= 0) ObjectDelete(strObjClose);
   ObjectCreate(strObjClose, OBJ_ARROW, 0, OrderCloseTime(), OrderClosePrice());
   if (ShowPriceLabelsInsteadOfArrows) {
      ObjectSet(strObjClose, OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
   } else {
      ObjectSet(strObjClose, OBJPROP_ARROWCODE, 3);   // Standard backtesting left-facing arrow
   }
   ObjectSet(strObjClose, OBJPROP_COLOR, lColour);
   ObjectSetText(strObjClose, strDescription, 10);
   
   string strObjLine = "TMLine" + OrderTicket();
   if (ObjectFind(strObjLine) >= 0) ObjectDelete(strObjLine);
   ObjectCreate(strObjLine, OBJ_TREND, 0, OrderOpenTime(), OrderOpenPrice(), OrderCloseTime(), OrderClosePrice());
   ObjectSet(strObjLine, OBJPROP_RAY, false);
   ObjectSet(strObjLine, OBJPROP_COLOR, lColour);
   ObjectSet(strObjLine, OBJPROP_STYLE, STYLE_DOT);
   ObjectSetText(strObjLine, strDescription, 10);
   
   return (true);
}
Reason: