Trade-Rectangle Visualizer is a utility class that makes automatic trading easy and seamless for online traders, by offering a general idea about how well their EA is doing, just by having a quick glance at the charts, without the need to read text-formatted trading logs, results, and reports.
Why did I start this project? As an online Fx & stocks trader, I often automatize my strategies - off-loading the hard work to trading bots. But when I want to monitor my bots and get a quick glance at how well they are performing, things become more complicated. There is no easy way to view the profitability of EA bots, other than spending a few minutes inside the EA reports, graphs, and results.
Why is this a problem? When it comes to automated trading, the main thing you want to know is how profitable your strategy / Expert Advisor (EA) are. How many recent wins and loses did it record. But this information is burried inside tester sub-windows (reports, results, graphs). If you have dozens of bots running simultanously, going into each of them is time-consuming, frustrating, and non-user friendly.
How does my script make your life easier? Instead of digging through countless tabs and sub-windows on dozens of charts, my script draws coloured rectangles and lines displaying profitable trades and loses directly on the graph. Just switch between your instrument charts to see the recents profits, loses, trading statistics.
- Introduction
- Table of Contents
- Project Description
- How to Install and Run the Project
- Configure the Properties and Functionality
- How to Use the Project
- Credits
- License
Step 1. Include the class file in your trading robot. The file-path (inside the "#include" preprocessor directive) might change depending on your folder structure or where you place the file:
#include <__SimonG\Helpers\TradeRectVisualizer.mqh>
Step 2. Declare a global or local variable of type TradeRectVisualizer:
TradeRectVisualizer * rectVisualizer;
Step 3. Initialize the TradeRectVisualizer object. The best place for this is inside the OnInit() function.
int OnInit(){
rectVisualizer = new TradeRectVisualizer();
rectVisualizer.setWhatToDraw (true, true);
//rectVisualizer.setTradeArrowProperties (clrDeepPink, clrDarkTurquoise, 3);
//rectVisualizer.setTradeRectProperties (clrPink, clrPaleTurquoise, true, true, 2);
//rectVisualizer.setTradeArrowProperties (clrDarkOrange, clrGreen, 3);
//rectVisualizer.setTradeRectProperties (clrPeachPuff, clrLightGreen, true, true, 2);
rectVisualizer.setTradeArrowProperties (clrRed, clrRoyalBlue, 3);
rectVisualizer.setTradeRectProperties (clrTomato, clrDeepSkyBlue, true, true, 2);
}
Step 4. Set-up a code sequence that uses the TradeRectVisualizer object immediatly after a trade closes, either in loss or profit:
static int currentOrderTicket = -1;
void check_condition_open_trade (){
// Check if there is an open trade, or if it was closed as a result of hitting Stop Loss
static bool hasDrawnArrRect = false;
if(OrderSelect(currentOrderTicket, SELECT_BY_TICKET) == true)
if(OrderCloseTime() > 0){
isThereAnOpenTrade = false;
if(doGraphTradesArrRect == true && hasDrawnArrRect == false){
rectVisualizer.vizualizeHalfHollowTradeRect (magicNumber, currentOrderTicket);
//rectVisualizer.vizualizeFullyColoredTradeRect (magicNumber, currentOrderTicket);
hasDrawnArrRect = true;
}
}
else isThereAnOpenTrade = true;
// Only check to open trade if no trade open yet
if(isThereAnOpenTrade == false){
conditionForBuying = validateOpenBuy ();
conditionForSelling = validateOpenSell ();
double volume = 100;
double stopLossPoints = 0.0020;
double takeProffitMultiply = 2.0;
int magicNumber = 18329;
// OPEN BUY
if( conditionForBuying == true ){
double orderStopLoss = Ask - stopLossPoints;
double orderTakeProfit = Ask + (stopLossPoints * takeProffitMultiply);
currentOrderTicket = OrderSend(Symbol(), OP_BUY, volume, Bid, 10, orderStopLoss, orderTakeProfit, "by me", magicNumber, clrTurquoise);
if(OrderSelect(currentOrderTicket, SELECT_BY_TICKET) == true){
isThereAnOpenTrade = true;
hasDrawnArrRect = false;
}
}
// OPEN SELL
else if( conditionForSelling == true ){
double orderStopLoss = Bid + stopLossPoints;
double orderTakeProfit = Bid - (stopLossPoints * takeProffitMultiply);
currentOrderTicket = OrderSend(Symbol(), OP_SELL, volume, Bid, 10, orderStopLoss, orderTakeProfit, "by me", magicNumber, clrCrimson);
if(OrderSelect(currentOrderTicket, SELECT_BY_TICKET) == true){
isThereAnOpenTrade = true;
hasDrawnArrRect = false;
}
}
}
}
Step 5. Memory clean-up, object deletion. This step is necesary for high-performing scripts, otherwise the left-over objects will continue to live in MT4/MT5 memory a long time, or until you close the software.
void OnDeinit (const int reason){
delete rectVisualizer;
}
The How to Install section offers a great example on how to use this utility class.
DEFAULT SCENARIO w/o SCRIPT | OPTIMIZED VISUALS with MY SCRIPT |
---|---|
Can barely see the profits/loses directly on the graph. |
Trading rectangle visualized, easier to see profits and loses. |
I can't credit anyone directly, but this section seems appropriate because I owe special thanks to so many course & content creators, chanels, youtubers.
- MQL4 Programming. Visit this link.
- ForexBoat Team. Check out Kiril's course on udemy. These guys create amazing content and I have learned so much from them!
Feel free to use this project for yourself. Or to edit it, use bits of it. Do not commercialize it! My Trade-Rectangle-Visualizer project is licensed under the GNU AGPLv3 license. Check out the licence link to better understand what you can and cannot do with this code.