Loop in place of start function

 

Hi,


I want to run my ea each second(for exemple), I don't want to wait each tick.

How can I do, I tried to put an infinite loop just after the sart funtion, but it doesn't seem to work.


Thanks

 
crystal7:

Hi,


I want to run my ea each second(for exemple), I don't want to wait each tick.

How can I do, I tried to put an infinite loop just after the sart funtion, but it doesn't seem to work.

I guess you don't ever want to test this EA in the Strategy Tester ?  

OK,  put what is in your start() function, except variable declarations, within a while(true) loop with a sleep(1000) . . .   it will run approx. once per second but will be useless in the Strategy Tester.  

 
crystal7: I want to run my ea each second(for exemple), I don't want to wait each tick.
Can't use the tester or optimize it.
int start(){
   while(!IsStopped()){ // Exit when chart closed
       :
       Sleep(1000);     // One second
       RefreshRates();  // Update predefined variables
   }
}
Can use tester and optimizer but why bother? Nothing has changed from the last tick.
int start(){
   while(!IsStopped()){ // Exit when chart closed
       :
       if(IsTesting()) break; // Allow tester and optimizer
       Sleep(1000);     // One second
       RefreshRates();  // Update predefined variables
   }
}
Remember that the EA MUST exit within 2.5 seconds
int start(){
   while(!IsStopped()){ // Exit when chart closed
       :
       if(IsTesting()) break; // Allow tester and optimizer
       for(int n=0; n<5; n++){  // 10 second sleep
         if(IsStopped())   break;
         Sleep(2000);
      }
       RefreshRates();  // Update predefined variables
   }
}
Also remember that you need an initial tick to call start or must enqueue one
#import "user32.dll"
   int PostMessageA(int hWnd,int Msg,int wParam,int lParam);
   int RegisterWindowMessageA(string lpString);
#import

int init(){
   int hwnd=WindowHandle(Symbol(), Period());
   int msg = RegisterWindowMessageA("MetaTrader4_Internal_Message");
   PostMessageA(hwnd, msg, 2, 1); // enqueue a fake tick and let init() return
   return(0);
}
 

Thank you,


I made the loop, but I don't know if it's works correctly.

I have some text on the window with the EA, and it draws new values only with a new tick on the chart.

But I put a counter, and when a new tick arrive the count is more than one, so I'm not sure...

I use sleep(10)

I want that because I trade on differents symbols with the same EA(this is in the strategy), so I want to know what happens on the other even if the symbol of the EA doesn't moves.

 
Again, why bother? Just trade the current symbol and put it on multiple charts. KISS!
 
crystal7:

Thank you,


I made the loop, but I don't know if it's works correctly.

I have some text on the window with the EA, and it draws new values only with a new tick on the chart.


If you update the chart between ticks you need to use WindowRedraw() to see the changes. 
 
euclid:
If you update the chart between ticks you need to use WindowRedraw() to see the changes. 

It works. Thanks.
Reason: