trade history


trade history

This is a simple example to demonstrate the usage of plotNewOpenTrades() and plotNewClosedTrades() that can be found in common_functions.mqh. MT4 will not automatically plot manual trades or trades resulting from pending orders into the chart, it only plots them when an EA sends a market order.

However, we would like to see all trades in the chart and we don't want to drag them manually from the history into the chart, we would like this to happen automatically.

#property indicator_chart_window

#include <common_functions.mqh>

int start(){
   plotNewOpenTrades();
   plotNewClosedTrades();
}

The above code is a complete indicator that when put onto a chart will plot all trades (historic and currently open) into the chart and it will not interfere with the normal mechanism of MT4 plotting trades. You will not end up with duplicate objects in the chart when you already dragged a trade from the history or an EA is already plotting trades. Additionally the description of the closing arrows, visible as tooltip when hovering the mouse above them, will show the resulting profit of the trade denominated in the account currency and in pips.

You can use this code in your own EAs if they use pending orders to make all trades visible to the user.

Below you can download a compiled version of the above code, ready to put into the indicators folder and to be used as indicator on your charts.

https://sites.google.com/site/prof7bit/common_functions/trade_history