How to tell EA that it is on its last round of optimization?

 

I need to trigger a specific function at the end of the final round of optimization, from the EA's deinit() function.

What is the best way to do this? Do I have to calculate it out by making start, step, and stop globally available variables? Or is there an easier way?

 

There's something that you're not telling us, otherwise what's wrong with something like

int deinit() 
{
  DoMyFinalCalculations();
  DoSaveMyGlobals();
}

Note that you have no more than 2.5 seconds to do whatever you need in deinit()

 
I need this to be launched after the last round of optimization. The deinit() function is called once per round... I need my function it to be called only on after all rounds of optimization are complete.
 

AFAIK the EA treats each optimization cycle as a self-contained run and so you are asking the EA to do something for which it was never intended.

And in true pioneering spirit, there is a workaround ...

My suggestion would be to do the call in deinit() as I said earlier, and as the EA gets cycled for each optimization, treat each one as 'the last one', deleting earlier results, and only keep the results of the final one.

Like I tell my kids ... "Life isn't fair"

 

That is pretty much what I do now.

At each run a global variable "Run #" is incremented. If Run# >= FinalRun# then it creates a MessageBox with the info that I need and sets Run#=1 again.

This means that I have to manually set FinalRun# each time.

I want to either use the windows API through a .dll file to get the "start," step," and "stop" internal variables or figure out their location in the RAM and access them that way. I would appreciate some tips about either of these methods.

 

Never say "never."

I figured it out on my own.

#import "user32.dll"
#include <WinUser32.mqh>

int GetWindow (int hWnd, int uCmd);
int GetWindowTextA (int hWnd, string lpString, int nMaxCount);
int GetWindowTextLengthA (int hWnd);
int PostMessageA (int hWnd, int Msg, int wParam, int lParam);
 int ShowWindow (int hWnd, int nCmdShow);
 int FindWindowA (string lpszClass, string lpszWindow);
 
#import

#define GW_HWNDNEXT 2
#define GW_CHILD 5

#define WM_CLOSE 0x0010


 void start ()
 {

 int hWnd, nMaxCount;
 string sWindowName = "";
  
 hWnd = 5571914;
 nMaxCount = GetWindowTextLengthA (hWnd);
 GetWindowTextA(hWnd,sWindowName,nMaxCount+1);
 Print(sWindowName);
 }
 
Reason: