EA OnTick OnTimer OnStart and DLL synchronization

 

Hi, I'm new in EA programming and I have this problem >

I communicate with DLL from EA

I need to push new prices to DLL and it will all be handled there

OnTimer and OnTick are not working for me

I made a loop in OnStart but DLL UI is lagging

Can somebody help me? Is there any asynchronous timer in MQL which can handle messaging to DLL?

#define MAX_BUFFER 20
#include <stdlib.mqh>
#include <WinUser32.mqh>

int pnt = 0;
bool isLoaded = false;

#include <SymbolsLib.mqh>

#import "myterminal.dll"
        int CreateWebPanel(int pnt);
        int SubclassWindow(int hWnd);
        int UnsubclassWindow(int hWnd);
        int OnMarketData(string symbol, double bid, double ask);
        
   bool GetFromQueue(int hWnd, int & EventType[], int & Param1[], int & Param2[], int & Param3[], int & EventLocalTime[]);
#import


#import "user32.dll"
   int RegisterWindowMessageA(string lpString);
#import

#import "kernel32.dll"
   int SystemTimeToFileTime(int& TimeArray[], int& FileTimeArray[]);
   int FileTimeToLocalFileTime(int& FileTimeArray[], int& LocalFileTimeArray[]);
   void GetSystemTime(int& TimeArray[]);
   void OutputDebugStringA(string msg);
#import

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+

string SymbolsList[];
   
int OnInit()
  {
      if (!IsDllsAllowed()) {
         MessageBox("DLL import is not allowed");
      } else {
         // Set up the subclassing on the window 
         Print(WindowHandle(Symbol(),Period()));
         if (!SubclassWindow(WindowHandle(Symbol(),Period()))) {
            MessageBox("Failed to set up the subclassing of the chart window. Is myterminal.dll correctly installed?");
         }
         
         EventSetTimer(1);
      }
      return(0);     
   
  }
  
int OnDeinit()
{
   // Remove the subclassing from the window - VERY IMPORTANT
   UnsubclassWindow(WindowHandle(Symbol(), 0));
  
   return(0);
} 


int OnStart()
{
   Print("Start()");
   EventSetTimer(1);
   if (!IsDllsAllowed()) {
      MessageBox("You must turn on \'Allow DLL imports\' in order to use this script");
      return (0);
   }
   
   if(SymbolsList(SymbolsList, true) == 0)
   {
     Print("Problem with reading symbol list");
   }

   bool bContinue = true;
   int execution=0;
   
   // Keep looping forever until the script is removed from the 
   // chart, or Ctrl+Shift+X is pressed
   while (bContinue){// && !IsStopped()) { //when !isStoped() is uncomented, then it wont run in loop
      execution = GetTickCount();
      
      GetMarketData();
      
      Sleep(1000-(GetTickCount()-execution));  // needs to be set on to slow down script
   }

   return(0);
}

void OnTick(){
   Print("Tick");   // I got no Tick message
}
void OnTimer(){
   Print("Timer");   // I got no Timer message
}


// retrieve market data
void GetMarketData(){
   for(int i = 0; i < ArraySize(SymbolsList); i++)
   {
      OnMarketData(SymbolsList[i], MarketInfo(SymbolsList[i],MODE_BID), MarketInfo(SymbolsList[i],MODE_ASK));   /// sends market data to DLL
   }
}
 
You have to code the EA rather than a script, if you intend to use the timer. The timer triggers the OnTimer() method, not sure what you meant by "asynchronous timer". BTW, the price change triggers OnTick() method in an EA.