Is it possible to force Metatrader to store chart profile from mql?

 

Hi,

I have Expert advisor, that creates some label object in init().

I noticed that adding EA on chart causes MetaTrader4 to store chart profile on disk, but it happens before my object is created, so created object data is not stored in chart profile. I need to readd EA again, change profile or restart metatrader to get my chart profile updated.

Is there a way to force MetaTrader4 to store it again from my EA init() or start() functions?

Thanks,

Lukasz

 

I haven't found a way yet. The only way is to quit MT4 and restart it, a crash of MT4 will make you lose all newly added chart objects, a method to save the state of the chart while it is running does not exist to my knowledge (I could need this too).

But it is interesting to hear that adding an EA will trigger the saving of the chart, I did not know this! Does this happen when adding an indicator too? If this is the case then maybe here lies the key to automating it.

 
7bit:

I haven't found a way yet. The only way is to quit MT4 and restart it, a crash of MT4 will make you lose all newly added chart objects, a method to save the state of the chart while it is running does not exist to my knowledge (I could need this too).

But it is interesting to hear that adding an EA will trigger the saving of the chart, I did not know this! Does this happen when adding an indicator too? If this is the case then maybe here lies the key to automating it.


Only if an indicator creates new window. Calling an indicator from the EA code does not cause chart profile to be saved.
 
zork:

Only if an indicator creates new window. Calling an indicator from the EA code does not cause chart profile to be saved.
At least then it *might* be possible to use windows api (sendmessage and friends) to add an indicator and immediately remove it again. For my purpose this would already be enough, I could let my EA do this once every hour to save the chart with all the objects it has created (breakeven markers, trade markers, labels, etc).
 
7bit:
At least then it *might* be possible to use windows api (sendmessage and friends) to add an indicator and immediately remove it again. For my purpose this would already be enough, I could let my EA do this once every hour to save the chart with all the objects it has created (breakeven markers, trade markers, labels, etc).


I am also thinking about sending shutdown query event to metatrader ( WM_QUERYENDSESSION ). The questions are:

does metatrader saves its data upon receiving this event?

Can it cause some other side effects?

 
  1. shutdown query is an interesting idea.
  2. I have Expert advisor, that creates some label object in init().
    Why bother. On startup the EA will again create the objects so who cares whither it was written to disk?
 
zork:


I am also thinking about sending shutdown query event to metatrader ( WM_QUERYENDSESSION ). The questions are:

does metatrader saves its data upon receiving this event?

Can it cause some other side effects?

I haven't tried it but i'm quite sure it will.
 
WHRoeder:
  1. shutdown query is an interesting idea.
  2. I have Expert advisor, that creates some label object in init().
    Why bother. On startup the EA will again create the objects so who cares whither it was written to disk?

I need to find profile file of a chart where my EA is running from my own application.

My current way to do it is as follows:

1. EA creates an object with unique id and connects to my application providing this id.
2 .My
application scans all profiles and tries to find profile file with this unique object.

I need to add my EA to chart twice for this to work and my users find it a little bit strange.

Thanks for any hints,

 
 

Thx, but this is to intrusive. Better idea is to send F5 and ctrl+F5 to terminal, but this will cause flicker too. More advanced method is to create custom indicator in separate window. Adding this indicator and removing it will cause profile to be stored. Have you ever tried this from EA or external application?

 

This will save it.

It just forces to re-acknowledge the EA parameters.

void forceProfileSaveHack()
{
keybd_event(118, 0, 0, 0); //VK_F7
keybd_event(13, 0, 0, 0); //VK_RETURN
}

In my EA I trigger such save manually with the letter "S" (but you can call it from anywhere, maybe with a timer)

void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
   {
   if(id == CHARTEVENT_KEYDOWN && lparam == 83) // VK_S
      forceProfileHack();

   return;
   }  
Reason: