Can I draw from buffer to BMP on chart directly? [SOLVED]

 

Hi. first thanks for all, and excuse for my English, I do better than I can :D


I develop my own EA and I want to put some bmp images to chart.

I don't have any problem to create an bmpObject and load bmp file from MQL4/Files folder, but this only work on realtime mode, if I try on test mode, the main folder change to test/Files folder, this is a problem for me beacuse the images that I want to load on chart I generated programmatically on the fly, from buffer to write to an file and them read from file and load to bmp object.

I repeat that I don't have any problem with this on realtime, but I want to see same as realtime on tester and by the sandbox capsule files I don't do to same way.


My question are, there are any way to draw my buffer image directly on the chart and not write buffer to file and them read file to bmpObject create?

There is another way to do same better than I do?

Thanks very much.

 
indio99:

I don't have any problem to create an bmpObject and load bmp file from MQL4/Files folder, 

Save the bmp in MQL4/Images folder, and load it from there.


Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I have moved your topic to the MQL4 and Metatrader 4 section.

 
Keith Watford #:

Save the bmp in MQL4/Images folder, and load it from there.


Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I have moved your topic to the MQL4 and Metatrader 4 section.


Hi , thanks for your reply.


You are right, excuse me for don't write my post on correct section.


I try to save file in MQL4/Images folder, but the limitation from sandbox capsule don't write out of tester folder when run on tester strategy


Here are a portion of my code and any of different path don't work for me when run on tester. When run on live mode work correctly but temporaryImage save on MQL4/Files folder, don't save on Images folder, why?


//imageFileName = "C:\\Program Files\\Darwinex MT4\\MQL4\\Images\\temporaryImage.bmp";
//imageFileName = "C:\\Program Files\\Darwinex MT4\\tester\\Images\\temporaryImage.bmp";
//imageFileName = TerminalInfoString(TERMINAL_DATA_PATH) + "\\MQL4\\Images\\temporaryImage.bmp"
imageFileName = "temporaryImage.bmp";


filehandle = FileOpen(imageFileName, FILE_READ|FILE_WRITE|FILE_BIN);
if (filehandle == INVALID_HANDLE) {
    Print("Operation FileOpen failed, error ", GetLastError());
    return(-1);
}

FileWriteArray(filehandle, fileHeader);
FileWriteArray(filehandle, infoHeader);


FileWriteArray(filehandle, imageBmp);
FileWriteArray(filehandle, padding);

FileClose(filehandle);


Print("FileOpen and Write OK");
return (0);


If I put any image on MQL4/Images folder, yes it is load from tester, but don't save programatically on this folder from tester.


I too try with TERMINAL_COMMONDATA_PATH but the result as the same, from tester don't save here and OBJPROP_BMPFILE only read from MQL4 folder


Any other solution or idea ???


Thanks a lot.

 
//imageFileName = TerminalInfoString(TERMINAL_DATA_PATH) + "\\MQL4\\Images\\temporaryImage.bmp"
imageFileName = "temporaryImage.bmp";


filehandle = FileOpen(imageFileName, FILE_READ|FILE_WRITE|FILE_BIN);

You tried to add a path. You can only read and write in the sandbox («DataFolder»\MQL4\Files).

File Write Problem (Error: 5002) - Expert Advisors and Automated Trading - MQL5 programming forum #1-2 (2020)
and FolderDelete using TERMINAL_DATA_PATH - General - MQL5 programming forum (2017)

 
William Roeder #:

You tried to add a path. You can only read and write in the sandbox («DataFolder»\MQL4\Files).

File Write Problem (Error: 5002) - Expert Advisors and Automated Trading - MQL5 programming forum #1-2 (2020)
and FolderDelete using TERMINAL_DATA_PATH - General - MQL5 programming forum (2017)



Hi, thanks.


I understand the sandbox and I know that I don't write on same folder from live mode and tester mode.

for this reason the others path are commented on code and the last asignation to imageFileName is "temporaryImage.bmp" with out any path.


I have two questions at this moment.


1º if I can't write and read on same folder I can't do my purpose from this way, right? I can solve if I can load BMP object from buffer instead from file, it is not posible, right?


//--- create a bitmap
if(!ObjectCreate(chart_ID,name,OBJ_BITMAP,sub_window,time,price)) {
Print(__FUNCTION__,
": failed to create a bitmap in the chart window! Error code = ",GetLastError());
return(false);
}

if(!ObjectSetString(chart_ID,name, OBJPROP_BMPFILE,  "temporaryImage.bmp")) {  <<< HERE >>>
Print(__FUNCTION__,
": failed to load the image! Error code = ",GetLastError());
return(false);
}


I know that this is not right but, there are some like this

//--- create a bitmap
if(!ObjectCreate(chart_ID,name,OBJ_BITMAP,sub_window,time,price)) {
Print(__FUNCTION__,
": failed to create a bitmap in the chart window! Error code = ",GetLastError());
return(false);
}

if(!ObjectSetString(chart_ID,name, OBJPROP_BMPFROMBUFFER, bufferBMP)) { <<< HERE >>>
Print(__FUNCTION__,
": failed to load the image! Error code = ",GetLastError());
return(false);
}


Any Idea ???



2º if the first question is not posible, I quest The title of this post. Can I draw from buffer to chart directly?

for example drawing a buffer of pixels directly on chart?


Thanks a lot

 
indio99 #:



Hi, thanks.


I understand the sandbox and I know that I don't write on same folder from live mode and tester mode.

for this reason the others path are commented on code and the last asignation to imageFileName is "temporaryImage.bmp" with out any path.


I have two questions at this moment.


1º if I can't write and read on same folder I can't do my purpose from this way, right? I can solve if I can load BMP object from buffer instead from file, it is not posible, right?



I know that this is not right but, there are some like this


Any Idea ???



2º if the first question is not posible, I quest The title of this post. Can I draw from buffer to chart directly?

for example drawing a buffer of pixels directly on chart?


Thanks a lot

Hello . 

If your original process is :

  1. construct pixels
  2. save to file
  3. load file

Then yes 

you can skip 2 in the tester (and live , unless you need to cache)

But , if you have a one time constructor of bmps you will have to always call it on the tests and use the resource without saving it.

But i think there is a \\Files\\ in the tester sandbox where you can place files temporarily and load from there (i might be wrong)?

 
Lorentzos Roussos #:

Hello . 

If your original process is :

  1. construct pixels
  2. save to file
  3. load file

Then yes 

you can skip 2 in the tester (and live , unless you need to cache)

But , if you have a one time constructor of bmps you will have to always call it on the tests and use the resource without saving it.

But i think there is a \\Files\\ in the tester sandbox where you can place files temporarily and load from there (i might be wrong)?


Hi.

My process is as you say correctly:

    1. Construct pixels to buffer array

    2. Save buffer array to file

    3. Draw bmp Object from file previously saved

I don't interested in cache of files created, file is overwrited eatch new occurrence with new generated bmp image.

Yes, I need to call BMP constructor one time for each image generated. All bmp are independent one from another.

How can I skip step 2 in the testing mode ? and on live mode too if is possible?

Can you give me an explanation of process or some example?

Thank you very much.

 
indio99 #:


Hi.

My process is as you say correctly:

    1. Construct pixels to buffer array

    2. Save buffer array to file

    3. Draw bmp Object from file previously saved

I don't interested in cache of files created, file is overwrited eatch new occurrence with new generated bmp image.

Yes, I need to call BMP constructor one time for each image generated. All bmp are independent one from another.

How can I skip step 2 in the testing mode ? and on live mode too if is possible?

Can you give me an explanation of process or some example?

Thank you very much.

Yes , with pleasure . 

int OnInit()
  {
//---
  uint pixels[];
  //just filling up the pixels here 
  //and resizing 100x100 for show
    ArrayResize(pixels,10000,0);
    ArrayFill(pixels,0,ArraySize(pixels),ColorToARGB(clrDeepPink,255));
  //then create a resource directly 
    ResourceFree("::MyResource");
    bool created=ResourceCreate("MyResource",pixels,100,100,0,0,100,COLOR_FORMAT_ARGB_NORMALIZE);
    if(created){
    Print("Resource created");
    //add resource name to a list of resources you are to release after the program exits 
      //unless its done automatically and i don't know that
        //create a bitmap object with the resource directly 
          ObjectCreate(ChartID(),"myObject",OBJ_BITMAP_LABEL,0,0,0);
          ObjectSetInteger(ChartID(),"myObject",OBJPROP_XSIZE,100);
          ObjectSetInteger(ChartID(),"myObject",OBJPROP_YSIZE,100);
          ObjectSetInteger(ChartID(),"myObject",OBJPROP_XDISTANCE,10);
          ObjectSetInteger(ChartID(),"myObject",OBJPROP_YDISTANCE,10);
          //and set the resource as the bitmap 
            ObjectSetString(ChartID(),"myObject",OBJPROP_BMPFILE,"::MyResource");
    }else{
    Print("Cannot create resource");
    }
//---
   return(INIT_SUCCEEDED);
  }

The yellow parts are most important the pixel stuff you are probably already doing 

 
Lorentzos Roussos #:

Yes , with pleasure . 

The yellow parts are most important the pixel stuff you are probably already doing 



WOOOWWWW !!!

This yellow lines are that I needed.


Now it work perfectly for my with out write/read files, and it sure are much more efficiently.


Thanks, thanks, thanks.

 
indio99 #:



WOOOWWWW !!!

This yellow lines are that I needed.


Now it work perfectly for my with out write/read files, and it sure are much more efficiently.


Thanks, thanks, thanks.

awesome