Recursive Polling

 
Hello all,

Can someone suggest the proper way to code the ability to RECURSIVELY POLL for for the existance of a FILENAME whenever there is NO TICK?

I want to give the TICK routines priority... and POLL for a FILENAME using a sleep function... say every second. Obviously, when the TICK comes in I want to branch to the TICK routines...

The FILENAME will contain dynamic data that will modify the chart/trade, etc. but is secondary to the TICK event.

Hope I explained this well enough for a reply.

Thanks!
-charliev
 
Put your POLL in a separate looping script or EA with Sleep(), and attach to a different chart.
Set a GlobalVariable when a file is found.

Have the EA with tick poll the GlobalVariable, and reset it after taking the file.

If Sleep() is in the EA with tick processing, the wakeup occurs at timeout, not before.
 
Put your POLL in a separate looping script or EA with Sleep(), and attach to a different chart.
Set a GlobalVariable when a file is found.

Have the EA with tick poll the GlobalVariable, and reset it after taking the file.

If Sleep() is in the EA with tick processing, the wakeup occurs at timeout, not before.


Ok, I see. Good idea!
Is there a way to do either of the following:
1. Have EA launch the script that polls? //for trouble-free use
2. Determine if script is loaded? // allowing an Alert if not loaded

BTW, is there something better to use than Sleep()?

Thank you very much for the help!
-charliev
 
1. no
2. not really, EA is more reliable... Script exits, EA restarts on next tick if it "fails" or "finishes"

The same code can run as a script, EA, or indicator, the folder placement determines how MT4 "runs" the code.

For a script to "keep running", it has to loop, but it starts immediately. It also completely exits when it is done.

An EA needs a tick to get started, but does not have to "loop", as it will be restarted on the next tick ( if not running)

---
BTW, is there something better to use than Sleep()?

No. Sleep() gives control beck to MT4 or the Operating System during the Sleep period. A simple loop to kill time will not do that, and you will see 100% CPU and apparent "lockup" of MT4

Well, that is, use Sleep() in a script or EA time loop

On an EA, you can just exit after start if some timer is not yet expired but a tick has arrived to start it.
 
1. no
2. not really, EA is more reliable... Script exits, EA restarts on next tick if it "fails" or "finishes"

The same code can run as a script, EA, or indicator, the folder placement determines how MT4 "runs" the code.

For a script to "keep running", it has to loop, but it starts immediately. It also completely exits when it is done.

An EA needs a tick to get started, but does not have to "loop", as it will be restarted on the next tick ( if not running)

---
BTW, is there something better to use than Sleep()?

No. Sleep() gives control beck to MT4 or the Operating System during the Sleep period. A simple loop to kill time will not do that, and you will see 100% CPU and apparent "lockup" of MT4

Well, that is, use Sleep() in a script or EA time loop

On an EA, you can just exit after start if some timer is not yet expired but a tick has arrived to start it.


Ok, I guess I missed somthing on the first round...

You're suggesting to use an EA, and put the LOOP in Start() // original desire was to have the POLL happen in
// absence of a TICK

The first TICK would start the LOOP, and in the event that the loop fails/stops... it will be re-started with the next TICK (?)

Wouldn't an Indicator do the same thing?

Thanks phy!
-charliev
 
If you use a script, it is less dependable than an EA.
A script can exit completely until manually added again to a chart.
The only real advantage of a script over a looping EA is that a script does not require a tick to get started initially.

An Expert is started at each tick (if it is not already running). It can then go into a loop and not be dependent on further ticks.
It reamains attached to the chart, does not require manual attachment to get it going again if it should "exit". The next tick will start it again

An indicator cannot Sleep or trade, otherwise, is about the equivalent of an Expert. Experts can't do indicator buffers.

---
"Can someone suggest the proper way to code the ability to RECURSIVELY POLL for for the existance of a FILENAME whenever there is NO TICK?"

If you want to be totally independent of ticks, use a looping Script.

If you don't mind waiting for the first tick to get things started, use a looping Expert.

If you don't care about tick independence, use an Indicator.

---
Now that I am thinking about it, you might try calling start() from the init() of the looping EA, that "might" get it started without a tick.


-- looping --

start(){

   while(IsStopped() == false){
      ... do your thing, again, and again
      Sleep( time );
   }
   return(0);
} 




 
Thanks phy, I appreciate the detail!
-charliev
Reason: