How to stop the expert working in mql4/mql5 language - mql4

Is there an easier way to have 2 experts installed on mt4/mt5 and 1 expert stop the other expert from running?

Easiest way is to use GlobalVariables. Use the expert that will stop the other to set a GlobalVariable. Make the other EA check for the presence of the global variable and if found, it can be set to pause operations.

Related

How to exit the program if the user leaves a certain checkbox blank

So I'm going to be writing an IT test tomorrow and we code using Delphi. My IT teacher hinted that one of the questions would involve us using code that would terminate the program if the user leaves the checkbox blank. Just wondering how I would go about doing this in Delphi.
Look at Application.Terminate(). Or, if you simply close the MainForm, the app will terminate itself automatically.
Another possibility to terminate the program is the halt command. But one should use this command very very rarely!
You may also use FatalExit(0);
This command is available for VCL application.
thanks

Is there a way to access the state of a GenServer?

Is there a built in way to see the current state of a GenServer? You can always implement a simple call to return the state, but is there a more generic way?
When I run :observer.start I can look at the running applications and see their state, so it seems possible. But it may be doing some double-secret Erlang voodoo to get that.
It depends on how you're going to use it.
If obtaining the state is part of your business logic, then yes - this should be properly modelled in your application with GenServer.call to return the state.
If you need this only in terms of debugging/insights of your application, you could use :sys.get_state like this:
iex> :sys.get_state(pid)
# some state printed
Please be aware of that :sys.get_state will accept either pid or the name of the server (if it is registered under one).
Also, please take a look at this section about debugging with :sys module in Elixir's GenServer documentation as it is very useful.
Hope that helps!

How to set an event preiodically with ACE library

I need to set a callback that will be called every pre-set time, according to a definition in a configuration file - suppose every 10 hours, by using the ACE library. I tried to use ACE_reactor and it seems to work, but it makes the application collapse after about 30 minutes of idle activity. I guess there's a way to do the same by using a timer, but so far I couldn't find a good code sample that demonstrates how to do it. Does anybody know how to do it by using C++ and ACE library? Does ACE have something equivalent to SetWaitableTimer() of Win API?
The ACE Reactor is the way to schedule timers, it works perfect at our side, are you sure you specify the correct timeout?

Specflow Feature File Best Practice

Thanks in advance for the help.
My question pertains to best practices inside a SpecFlow feature file?
Question:
Is using a wait command inside of the feature file considered bad practice.
Example:
And i click on the username
And wait 5 seconds
And i input new value into last name
The wait command forces a 5 second wait. I am doing this to make sure the page is loaded to prevent "element not found" errors or other errors. Basically to make sure I have a clean page to manipulate.
Would a better practice be to use a wait inside of the Step file itself?
//using Fluent Automation
I.WaitUntil(() => ());
//or
I.Wait(); //timespan
My reasoning for not using the Fluent Automation wait is:
By utilizing the Fluent Automation method you are dependent on the default timeout in the Settings object. The default timeout in some cases may not be long enough or may be to long. Seems very verbose to me to continually change/reset the Settings object with the only benefit being to remove wait commands from the feature file.
So what is really the best practice?
Thanks,
-n
I think the best practice is to keep the feature file for your scenarios, and free of the implementation details.
Since we are following a BDD process (http://dannorth.net/introducing-bdd) then the feature file is the output of that conversation between you and the process expert, and the scenario represents the steps that you are going to take to prove that your functionality works for that example. You could hope that those steps define the business process and could be performed by any system, not just the one we might be developing now. Ideally this logic captures our intent and can be reused on any future systems that might replace the current one.
So I just don't see you saying that you need to wait
....
Although you might want to say
When the page has loaded
and that maps quite nicely onto the fluent automation.

How would someone create a preemptive scheduler for the Lua VM?

I've been looking at lua and lvm.c. I'd very much like to implement an interface to allow me to control the VM interpreter state.
Cooperative multitasking from within lua would not work for me (user contributed code)
The debug hook gets me only about 50% of the way there, instruction execution limits, but it raises an exception which just crashes the running lua code - but I need to be able to tweak it even further.
I want to create a system where 10's of thousands of lua user scripts are running - individual threads would not work, and the execution limits would cause headache for beginning developers, I'm going to control execution speeds too. but ultimately
while true do
end
will execute forever, and I really don't care that it is.
Any ideas, help or other implementations that I could look at?
EDIT: This is not about sandboxing pretend I'm an expert in that field for this conversation
EDIT: I do not want to use an internally ran lua code coroutine based controller.
EDIT: I want to run one thread, and manage a large number of user contributed lua scripts, an external process level control mechansim would not scale at all.
You can search for Lua Sandbox implementations; for example, this wiki page and SO question provide some pointers. Note that most of the effort in sandboxing is focused on not allowing you to execute bad code, but not necessarily on preventing infinite loops. For better control you may need to combine Lua sandboxing with something like LXC or cpulimit. (not relevant based on the comments)
If you are looking for something Lua-based, lightweight, but not necessarily 100% foolproof, then you can try running your client code in a separate coroutine and set a debug hook on that coroutine that will be triggered every N-th line. In that hook you can check if the process you are running exceeded its quotes. You also need to take care of new coroutines started as those need to have their own hooks set (you either need to disable coroutine.create/wrap or to replace them with something that sets the debug hook you need).
The code in this case may look like:
local coro = coroutine.create(client_func)
debug.sethook(coro, debug_hook, "l", 1000) -- trigger hook on every 1000th line
It's not foolproof, because it may block on some IO operation and the debug hook will not help there.
[Edit based on updated question and comments]
Between "no lua code coroutine based controller" and "no external process control mechanism" I don't think you are left with much choice. It may be that your only option is to run one VM per user script and somehow give ticks to those VMs (there was a recent question on SO on this, but I can't find it). Before going this route, I would still try to do this with coroutines (which should scale to tens of thousands easily; Tir claims supporting 1M active users with coroutine-based architecture).
The mechanism would roughly look like this: you install the debug hook as I shown above and from that hook you yield back to your controller, which then decides what other coroutine (user script) to resume. I have this very mechanism working in the Lua debugger I've been developing (although it only does it for one client script). This doesn't protect you from IO calls that can block and for that you may still need to have a watchdog at the VM level to see if it's been blocked for longer than needed.
If you need to serialize and deserialize running code fragments that preserve upvalues and such, then Pluto is probably your only option.
Look at implementing lua_lock and lua_unlock.
http://www.lua.org/source/5.1/llimits.h.html#lua_lock
Take a look at lulu. It is lua VM written on lua. It's for Lua 5.1
For newer version you need to do some work. But it's then you really can make a schelduler.
Take a look at this,
https://github.com/amilamad/preemptive-task-scheduler-for-lua
I maintain this project. It,s a non blocking preemptive scheduler for running lua code. Suitable for long running game scripts.

Resources