You should study the documentation. Just a glance and I realized there is a property called: OBJPROP_BMPFILE.
You can Also check this topic.
- docs.mql4.com
You should study the documentation. Just a glance and I realized there is a property called: OBJPROP_BMPFILE.
You can Also check this topic.
thank you for your reply, i have applied but now i can see the issue is:
Error opening directory: 5002
the files are there and i'm sure the permissions are ok and below my new script with full debugging:
void ShowOrderTypeImage() { string dataPath = TerminalInfoString(TERMINAL_DATA_PATH); string bullImagePath = dataPath + "\\MQL4\\Images\\bull.bmp"; Print("Image path: ", bullImagePath); // Check if the directory exists string imageDir = dataPath + "\\MQL4\\Images"; if (!DirectoryExists(imageDir)) { Print("Directory does not exist: ", imageDir); return; } // Check if the BMP file exists if (FileExistsCustom(bullImagePath)) { Print("BMP file exists: ", bullImagePath); } else { Print("BMP file does not exist: ", bullImagePath); PrintDirectoryListing(imageDir); return; } // Delete any existing image labels to avoid overlapping if (ObjectFind(0, "OrderTypeImage") != -1) { if (!ObjectDelete(0, "OrderTypeImage")) { Print("Error deleting existing OrderTypeImage: ", GetLastError()); } else { Print("Successfully deleted existing OrderTypeImage"); } } // Display the bull image in the middle of the chart if (!ObjectCreate(0, "OrderTypeImage", OBJ_BITMAP_LABEL, 0, 0, 0)) { Print("Error creating OrderTypeImage: ", GetLastError()); return; } else { Print("Successfully created OrderTypeImage"); } if (!ObjectSetString(0, "OrderTypeImage", OBJPROP_BMPFILE, bullImagePath)) { Print("Error setting BMP file for OrderTypeImage: ", GetLastError()); } else { Print("Successfully set BMP file for OrderTypeImage"); } // Get the chart width and height to position the image in the center long chartWidth = ChartGetInteger(0, CHART_WIDTH_IN_PIXELS); // Use long to avoid loss of data long chartHeight = ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS); // Use long to avoid loss of data Print("Chart width: ", chartWidth, ", Chart height: ", chartHeight); if (!ObjectSetInteger(0, "OrderTypeImage", OBJPROP_XDISTANCE, (int)(chartWidth / 2 - 150))) // Center horizontally { Print("Error setting X distance for OrderTypeImage: ", GetLastError()); } else { Print("Successfully set X distance for OrderTypeImage"); } if (!ObjectSetInteger(0, "OrderTypeImage", OBJPROP_YDISTANCE, (int)(chartHeight / 2 - 150))) // Center vertically { Print("Error setting Y distance for OrderTypeImage: ", GetLastError()); } else { Print("Successfully set Y distance for OrderTypeImage"); } if (!ObjectSetInteger(0, "OrderTypeImage", OBJPROP_XSIZE, 300)) // Adjust the width as needed { Print("Error setting X size for OrderTypeImage: ", GetLastError()); } else { Print("Successfully set X size for OrderTypeImage"); } if (!ObjectSetInteger(0, "OrderTypeImage", OBJPROP_YSIZE, 300)) // Adjust the height as needed { Print("Error setting Y size for OrderTypeImage: ", GetLastError()); } else { Print("Successfully set Y size for OrderTypeImage"); } if (!ObjectSetInteger(0, "OrderTypeImage", OBJPROP_HIDDEN, false)) { Print("Error setting hidden property for OrderTypeImage: ", GetLastError()); } else { Print("Successfully set hidden property for OrderTypeImage"); } if (!ObjectSetInteger(0, "OrderTypeImage", OBJPROP_SELECTABLE, true)) { Print("Error setting selectable property for OrderTypeImage: ", GetLastError()); } else { Print("Successfully set selectable property for OrderTypeImage"); } if (!ObjectSetInteger(0, "OrderTypeImage", OBJPROP_SELECTED, true)) { Print("Error setting selected property for OrderTypeImage: ", GetLastError()); } else { Print("Successfully set selected property for OrderTypeImage"); } } // Function to check if a file exists bool FileExistsCustom(string filename) { int handle = FileOpen(filename, FILE_READ | FILE_BIN); if (handle != INVALID_HANDLE) { FileClose(handle); return true; } else { Print("FileOpen error: ", GetLastError(), " for file: ", filename); } return false; } // Function to check if a directory exists bool DirectoryExists(string directoryPath) { string fileName; int handle = FileFindFirst(directoryPath + "\\*", fileName); if (handle != INVALID_HANDLE) { FileFindClose(handle); return true; } return false; } // Function to print directory listing void PrintDirectoryListing(string directoryPath) { Print("Listing files in directory: ", directoryPath); string fileName; int handle = FileFindFirst(directoryPath + "\\*.bmp", fileName); if (handle == INVALID_HANDLE) { Print("Error opening directory: ", GetLastError()); return; } do { Print("Found file: ", fileName); } while (FileFindNext(handle, fileName)); FileFindClose(handle); }
the files are there and i'm sure the permissions are ok and below my new script with full debugging:
string dataPath = TerminalInfoString(TERMINAL_DATA_PATH); string bullImagePath = dataPath + "\\MQL4\\Images\\bull.bmp";
The path you passed is garbage.
You can't read (or write) outside the sandbox with normal code.
File Write Problem (Error: 5002) - Expert Advisors and Automated Trading - MQL5 programming forum #1-2 (2020)
For security reasons, work with files is strictly controlled in the MQL5 language. Files with which file operations are conducted using MQL5 means, cannot be outside the file sandbox.
FileOpen - File Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Hello,
I'm tryng to show png image on the chart when i do run the EA, below the related script:
as you see in the attached screenshot, it is showing the object in the objects list, but not showing it in the chart actually.
please advise where is the wrong ?
https://www.mql5.com/en/code/45439
If you want to include png file in ex4, then unfortunately in Mql4 there is no such possibility as in mql5:
#resource "//Images//image.png" as uchar image[]
but there is a possibility:
- www.mql5.com
- 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,
I'm tryng to show png image on the chart when i do run the EA, below the related script:
as you see in the attached screenshot, it is showing the object in the objects list, but not showing it in the chart actually.
please advise where is the wrong ?