Calling a Script from an EA

 

is there a way to call a script from an EA?

 
witchazel:
is there a way to call a script from an EA?

Move the code in your script to an include file in the "experts\include" folder.

You can then include this script in your EA by adding the following line to the top of your EA file:

#include

From there you can call whatever function you need from your include file.

 
jhernandez:
Move the code in your script to an include file in the "experts\include" folder.

You can then include this script in your EA by adding the following line to the top of your EA file:

#include

From there you can call whatever function you need from your include file.

Thank you! will this allow it to run autonomously? i have a buy/sell script as well as an exit script i would like to run almost as a "multithread" so my EA doesnt get bogged down.

 

I dont think Metatrader supports multi-threading, when you call your buy/sell function from your include file your main EA will wait for it to finish. You can't 'kick off' your script to start running this way.

 

You can assign a hotkey to your script, and then have your EA simulate 'pressing' the hotkey which will trigger your script to run as a process outside of your EA. That way the EA and the script are independent of each other.

This should give you a 'poor mans' version of multi threading in Metatrader.

 

jhernandez

Can you loop a script so it runs continually. I understand that it will run within an endless loop. Would this be correct?

Can you have two copies of the same currency and or time frame open at the same time and have an entrence script on one and your exit script on the other to operate continually in that way all the scripts have to do is reconize the orders.

If this can be done you will need to entroduce a means to stop the scripts, which should not be to difficault to do.

 

Yes, you can have a script loop endlessly on a chart. Not sure if you need to have two scripts running, since you can probably add the logic for buying/selling in the same script.

I would also try to space out the looping a bit in your code, adding something like Sleep(500); or Sleep(1000);, so that your code waits 1/2 or 1 second in between loops. Otherwise you might see your script take up a lot of your available memory.

Juan

 

How can I set the EA to only call the script ONCE at a specific time and Day?