runwiseFX

groundbreaking functionality for the MetaTrader platform

TUTORIAL: Sending and Receiving Events

This advanced tutorial provides an example of sending and receiving events using the rule scripting of our EA. Events allow a particular instance of the EA (chart) to send messages to other instances (charts). The example shows how trading can be turned off for the selected trade index/magic number, in multi-trade mode.

Here is the necessary configuration to provide a button that will turn off auto trading (set to EVL evaluate only) for the selected trade index:

The configuration begins by defining a button to execute the example. The direction is set to sell as only one event needs to be sent, but rules for GUI controls get evaluated twice for sell and buy if direction is not set.

Then the rule to responds to the button press is defined. If the trade index that is being evaluated matches the trade index selected on the panel then will send an event. This is done using the command SEND_EVENT, which will send the supplied parameters to all charts (including current one). The parameters have a label of 'autoOff' and provides the trade index as an additional numeric parameter.

Finally, there is a rule of type event which is called when events are received. Note, in multi trade mode and like other rule types then rule will get evaluated for all trade indexes in a loop. The operands t.eventStr provide the label of the event and t.eventLong provides any additional integer value. If the label is 'autoOff' and the integer value is the currently evaluating trade index then SET_AUTO_MODE command is called to turn off auto trading by setting to the recommended EVL (evaluation only). Note, in multi-trade mode SET_AUTO_MODE, like other commands, will just work on the trade index being evaluated, i.e. t.tradeIdx.