Have a look at the following. It is not the same but the concept is similar.
To learn how to create and manage Graphical Objects, read the following: MQL5 Book: Creating application programs / Graphical objects
To learn how to create and manage Graphical Objects, read the following: MQL5 Book: Creating application programs / Graphical objects
thx buddy
what you want to do here is much more difficult than you think
- Need to create a deal function to get the price data of historical deals
- Need to create a function to parse numbers into a price format before and after the decimal
- Need to use the CCanvas library to create text bitmap with filled rectangle
Understanding how to even utilize the CCanvas library is at least 4 - 5 months of studying
what you want to do here is much more difficult than you think
- Need to create a deal function to get the price data of historical deals
- Need to create a function to parse numbers into a price format before and after the decimal
- Need to use the CCanvas library to create text bitmap with filled rectangle
Understanding how to even utilize the CCanvas library is at least 4 - 5 months of studying
Not necessarily. The OP's image shows just normal "rectangles" with some text. Both primitives of which are available as standard Graphical Objects, without the need for "canvas".
EDIT: Plus, in the example, they are locked to the both the price and time, so canvas would be not be ideal at all, and the standard Graphical Objects are much easier and simpler solution.
Not necessarily. The OP's image shows just normal "rectangles" with some text. Both primitives of which are available as standard Graphical Objects, without the need for "canvas".
EDIT: Plus, in the example, they are locked to the both the price and time, so canvas would be not be ideal at all, and the standard Graphical Objects are much easier and simpler solution.
Fair argument. I coded this both ways now just to try. I may as well post the code I have (MQL5)
#include <Canvas/Canvas.mqh> // Include the Canvas library CTrade obj_Trade; CCanvas canvas; // Canvas object for drawing void OnTick() { examineLastTrade(); } string FormatString(double value){ string str = DoubleToString(value, 8); // Find the position of the decimal point int dotPosition = StringFind(str, "."); if (dotPosition != -1){ // Check the part after the decimal point string fractionalPart = StringSubstr(str, dotPosition + 1); // If the fractional part has only one zero, keep it if (StringLen(fractionalPart) == 2 && StringSubstr(fractionalPart, 1, 1) == "0"){ str = StringSubstr(str, 0, dotPosition + 3); // Keep two decimal places } else{ // Remove trailing zeros while (StringLen(str) > 0 && StringSubstr(str, StringLen(str) - 1, 1) == "0"){ str = StringSubstr(str, 0, StringLen(str) - 1); // Remove trailing zero } // Remove the trailing dot if any if (StringSubstr(str, StringLen(str) - 1, 1) == "."){ str = StringSubstr(str, 0, StringLen(str) - 1); } } } return str; } void examineLastTrade(){ static datetime timeOfLastTrade = TimeCurrent(); for(int i = PositionsTotal() - 1; i >= 0; i--) { ulong posTicket = PositionGetTicket(i); if(posTicket > 0) { timeOfLastTrade = (datetime)PositionGetInteger(POSITION_TIME); // Position open time } } if (!PositionSelect(Symbol())){ HistorySelect(timeOfLastTrade, TimeCurrent()); for (int i = 0; i < HistoryDealsTotal(); i++){ ulong ticket = HistoryDealGetTicket(i); if (ticket > 0){ double dealProfit = HistoryDealGetDouble(ticket, DEAL_PROFIT); long dealTime = HistoryDealGetInteger(ticket, DEAL_TIME); int barIndex = iBarShift(_Symbol, _Period, dealTime); double pricePosition = iHigh(_Symbol, _Period, barIndex); datetime positionTime = iTime(_Symbol, _Period, barIndex); string price = "$" + FormatString(dealProfit); Profit_display(0, "deal_profit" + IntegerToString(ticket), price, pricePosition, 8, clrSilver, positionTime); DisplayProfitLabel(positionTime, pricePosition, price, ticket); } else{ Print("Failed to get ticket for index ", i); } } } } void DisplayProfitLabel(datetime time, double price, string priceLabel, ulong index){ int X = 0, Y = 0; uint TextColor = clrBlack; // Text color // Convert the time and price to chart pixel coordinates if (ChartTimePriceToXY(ChartID(), 0, time, price, X, Y)) { X -= 20; Y += 10; if (canvas.CreateBitmapLabel("canvasLabel" + IntegerToString(index), X, Y, 60, 20, COLOR_FORMAT_ARGB_NORMALIZE)) { canvas.Erase(ColorToARGB(clrOrange, 255)); //Fill rectangle canvas.TextOut(1, 1, priceLabel, TextColor); canvas.Update(false); } else { Print("Failed to create bitmap label at the calculated coordinates."); } } else { Print("Failed to convert time and price to chart pixel coordinates."); } } void Profit_display(int id, string name, string text, double distance, int fontSize, color fontColor, datetime time){ if (ObjectFind(0, name) < 0){ ObjectCreate(id, name, OBJ_TEXT, 0, time, distance); } ObjectSetInteger(id, name, OBJPROP_CORNER, 0); ObjectSetInteger(id, name, OBJPROP_FONTSIZE, fontSize); ObjectSetInteger(id, name, OBJPROP_COLOR, fontColor); ObjectSetString(id, name, OBJPROP_TEXT, text); }
I uploaded a working example on the codebase, although if you use a rectangle object, everything will go to shit when you zoom out because rectangle vertices are dependent on time. I tried to control it by using scaling values, but made trash of the code.
OBJ_RECTANGLE_LABEL is also not a solution. This object X value will always persist to the current bar time, and will not remain on a specific shift in time.
Next, there's an issue with canvas - similar to OBJ_RECTANGLE_LABEL...it will always update with time and will not remain on a specific shift in time even if you give a unique index name to each canvas object. If someone knows any solution...let us know.
I didn't bother checking OBJ_BITMAP from the standard library
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use


Hello, can somebody explain how to add this "Profit Lables" to show on a chart? how to code it into an EA or as a indicator?
thx.