Put Image on Chart - page 2

 

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.

There are two directories (with subdirectories) in which working files can be located:

  • terminal_data_folder\MQL5\FILES\ (in the terminal menu select to view "File" - "Open the data directory");
  • the common folder for all the terminals installed on a computer - usually located in the directory C:\Documents and Settings\All Users\Application Data\MetaQuotes\Terminal\Common\Files.

There is a program method to obtain names of these catalogs using the TerminalInfoString() function, using the ENUM_TERMINAL_INFO_STRING enumeration:

//--- Folder that stores the terminal data
   string terminal_data_path=TerminalInfoString(TERMINAL_DATA_PATH);
//--- Common folder for all client terminals
   string common_data_path=TerminalInfoString(TERMINAL_COMMONDATA_PATH);

 
//+------------------------------------------------------------------+
//|                                          Check_TerminalPaths.mq5 |
//|                        Copyright 2009, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   Print("TERMINAL_PATH = ",TerminalInfoString(TERMINAL_PATH));
   Print("TERMINAL_DATA_PATH = ",TerminalInfoString(TERMINAL_DATA_PATH));
   Print("TERMINAL_COMMONDATA_PATH = ",TerminalInfoString(TERMINAL_COMMONDATA_PATH));
  }
 

This is what i get:

pfad

tree
 

Maybe it's time to use your imagination ?

string filename=TerminalInfoString(TERMINAL_DATA_PATH)+"\\Images\\dollar.bmp";
 

Use CCanvas class and it will work. I dont understand why you use this native functions which blow up the code instead of using the classes. Its three lines of code to display your bitmap, not 300.

I ve uploaded a modified version of CCanvas longer time ago. With this you can also compile your image as resource and display it. 

And by the way, buffers like these are only displayed after a chart-update. 

 

It's actually the way around, displaying a bitmap take one line in native code but 300 in CCanvas include files included.

So nice try but nope.

And i had told the OP that he could use resources some posts ago but he didn't pick up on it.

 
wokl:

same... I created another new mini example:


 int OnInit() {
 
  ObjectCreate(0, "test", OBJ_BITMAP,0, TimeCurrent(), 1.047);
  ObjectSetString(0,"test",OBJPROP_BMPFILE,0,"..\\Images\euro.bmp");
  Print("Last Error:", GetLastError());
  return(0);
 
 }
 
 void OnTick() {
 
 }
 
here I also tried differente pathes. The object is placed by TimeCurrent and Price as can be seen in the screenshot:




changing the function to:

 int OnInit() {

 
  string file="\\Images\\dollar.bmp";
 
  ObjectCreate(0, "test", OBJ_BITMAP,0, TimeCurrent(), 1.047);
  ObjectSetString(0,"test",OBJPROP_BMPFILE,0,file);
  Print("Last Error:", GetLastError());
  return(0);
 
 }
 
 void OnTick() {
 
 }
 

has no effect either. Might be a bug? cannot see what's wrong..

   ObjectCreate(0,"test",OBJ_BITMAP_LABEL,0,0,0);

   ObjectSetString(0,"test",OBJPROP_BMPFILE,0,"\\Images\\euro.bmp");

   ObjectSetInteger(0,"test",OBJPROP_XDISTANCE,265);

   ObjectSetInteger(0,"test",OBJPROP_YDISTANCE,175);

   ObjectSetInteger(0,"test",OBJPROP_CORNER,0);

   ObjectSetInteger(0,"test",OBJPROP_BACK,true);

 

Use the </> code button to insert your code.


 

Have the same problem. The script compiles, resource is accepted, you just can't see anything on chart.

Then i tried with another bitmap, same location and i get error "unsupported image type".

What's the secret here ?

 

I could solve it by playing around with width and height parameter:

      ObjectSetInteger(chart_ID,obj_name,OBJPROP_XSIZE,width);
      ObjectSetInteger(chart_ID,obj_name,OBJPROP_YSIZE,height);

In my case i used a slightly lower width and height as the imagsize given in windows paint and then the bitmap shown on chart.