Create A Managed Trading Strategy With MetaTrader
Create A Managed Trading Strategy With MetaTrader
MetaTrader4 Plugin
Contents
Installation and setup ................................................................................................................ 3 How to use the API to send Trading Signals and Updates to Zignals ........................................ 7 Possible errors ......................................................................................................................... 13 Troubleshooting ....................................................................................................................... 14
3. Install Microsoft Visual C++ 2010 SP1 Redistributable Package (x86). Follow the install instructions
5. Copy experts directory to the folder where you have installed Metatrader4 (e.g. C:\Program Files (x86)\MetaTrader 4\), these files are copied:
C:\Program Files (x86)\MetaTrader4\experts\include\ZESPMT4Unmanaged.mqh C:\Program Files (x86)\MetaTrader4\experts\libraries\ZESPMT4Unmanaged.dll C:\Program Files (x86)\MetaTrader4\experts\scripts\Zignals_CreateSignalSamples.mq4 C:\Program Files (x86)\MetaTrader4\experts\scripts\Zignals_GetStrategies.mq4 C:\Program Files (x86)\MetaTrader4\experts\scripts\Zignals_Login.mq4 C:\Program Files (x86)\MetaTrader4\experts\scripts\Zignals_Logout.mq4
8. Using navigator open and compile following files (one after another)
include\ ZESPMT4Unmanaged.mqh scripts\ Zignals_CreateSignalSamples.mq4 scripts\ Zignals_GetStrategies.mq4 scripts\ Zignals_Login.mq4 scripts\ Zignals_Logout.mq4
How to use the API to send Trading Signals and Updates to Zignals
First, allow for DLL imports. You can set this from the Tools => Options => Allow DLL imports.
Next, in the Navigator panel on the left, click on Zignals_Login, and log in with your Zignals details. If you haven't registered with Zignals you can do so here. Remember you need to switch to the Inputs tab of the Zignal_Login dialog to enter your membership details.
To view your existing strategies click on Zignals_GetStrategies (navigator panel 1): The number on the left is the strategy id which is required when creating signals (2) The name of the strategy is on the right (3)
A sample how to create a signal is in Zignals_CreateSignalSamples script file: 1. 2. 3. 4. Open MetaTrader and switch to MetaEditor (F4) Open Zignals_CreateSignalSamples script Change your code to your needs Don't forget to compile
The authentication key is required for every API call is created when you login using Zignals_Login script is stored (when you login) to file files\zignalsAuth.key is removed when you logout using Zignals_Logout script
To use API calls in your script you have to insert into your script #include
#property copyright "Copyright 2010, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" #include <ZESPMT4Unmanaged.mqh> int start() { }
<ZESPMT4Unmanaged.mqh>
Every API Call which creates a signal returns true or false depending on the result of the operation (true for success). If the returnValue is false, the errorMessage contains information about the error (see this section)
string errorMessage[1] = { "" }; bool isProcessed = false; isProcessed = CreateEntry(authKey, strategyId, symbol, shares, isBuying, extraInfo, target, stop, errorMessage); Alert(isProcessed); Alert(errorMessage[0]);
Positive integer is required for 'numbers of shares' - parameter. Market is open - price is available. Please use entry Target price is not set properly For long position the target price has to be greater than actual price For long position the stop price has to be less than actual price
Target & Stop are not properly set. Symbol is in short position. If you own 1000 shares, you can't short 1000 shares / use exit to sell all 1000 shares
Symbol is in long position. Symbol is not in open position. You can't sell 1000 shares if you don't own them / buy shares first with "create entry"
Troubleshooting
ZESPMT4Unmanaged.dll (error 126)
Solution 1. Make sure Microsoft Visual C++ 2010 SP1 Redistributable Package (x86) is installed. Follow the install instructions 2. Restart MetaTrader and Login
Solution 1. Close Metatrader 2. Run registerCOM.cmd (run as administrator!) (see installation step 3)
[MetaTrader1 278 x 113; no lightbox][Alt: Compiling error in MetaTrader] Solution: 1. There is no need to fix anything. The files will have compiled.