Execute EA without waiting for a tick?

 
After compiling an EA, is there a way have the EA run the start() function without having to wait for the next tick?
 
jtr:
After compiling an EA, is there a way have the EA run the start() function without having to wait for the next tick?

I think you can use refresh rates.

 

EA starts on tick.

Script starts without a tick.

 

there is a way.

save this code to script and run it on the chart with EA.


//+------------------------------------------------------------------+

//| IncomingTick.mq4 |
//| Copyright c 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright c 2006, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#include <WinUser32.mqh>

//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
//----
int MT4InternalMsg = RegisterWindowMessageA("MetaTrader4_Internal_Message");
int hWnd = WindowHandle(Symbol(),Period());
PostMessageA(hWnd,MT4InternalMsg,2,1);
//----
return(0);
}
//+------------------------------------------------------------------+

 
I had to add: int RegisterWindowMessageA(string lpString); to my WinUser32.mqh to get it to work, but it works great. Thanks.
 
jtr:
I had to add: int RegisterWindowMessageA(string lpString); to my WinUser32.mqh to get it to work, but it works great. Thanks.

For those who don't know... WinUser32.mqh is in the INCLUDE folder in the EXPERTS folder.



My question is... does this work for custom indicators?



What I want to do is have an indicator update every X seconds and not wait for ticks at all.

 

Hello,

I've just made it as above (adding the script to chart and change the file WinUser32.mqh) but after that I have some error "uninit reason 0" and information that script is removed... Thanks for a help in advance.

 

hi

for this problem, is there any other way?, that have no need to add an external script.
somethings like putting a simple function in EA itself.

my problem isو i draw some objects like Buttons using EA, when user click on a button, or just change something in EA setting, these objects need to re-draw by new calculations immediately, but it will wait until a new tick and during this time user may think EA stop working or thinks it is working very heavy.

i tried RefreshRates() and also WindowRedraw(). but not solved.

 
Alireza Yadegar #:

hi

for this problem, is there any other way?, that have no need to add an external script.
somethings like putting a simple function in EA itself.

my problem isو i draw some objects like Buttons using EA, when user click on a button, or just change something in EA setting, these objects need to re-draw by new calculations immediately, but it will wait until a new tick and during this time user may think EA stop working or thinks it is working very heavy.

i tried RefreshRates() and also WindowRedraw(). but not solved.

Use chart events 
 
Paul Anscombe #:
Use chart events 

hi, can you explain more please.
notice i just need to force EA to re-calculate again, actually instead of waiting for a tick, run the Ontick() forcedly. 

 
You have multiple options.

OnChartevent ()

OnTimer()

For both go to the docs and read about the event handlers an EA can have.