0% found this document useful (0 votes)
8K views15 pages

Create A Managed Trading Strategy With MetaTrader

Use the MetaTrader 4 plugin to create a Managed Strategy (Public Portfolio) in Zignals. Attract subscribers and earn revenue in a share with Zignals. Get started today.

Uploaded by

Declan Fallon
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8K views15 pages

Create A Managed Trading Strategy With MetaTrader

Use the MetaTrader 4 plugin to create a Managed Strategy (Public Portfolio) in Zignals. Attract subscribers and earn revenue in a share with Zignals. Get started today.

Uploaded by

Declan Fallon
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Managed Strategies External Signals

MetaTrader4 Plugin

Zignals MetaTrader 4 plugin for External Signals Platform

Contents
Installation and setup ................................................................................................................ 3 How to use the API to send Trading Signals and Updates to Zignals ........................................ 7 Possible errors ......................................................................................................................... 13 Troubleshooting ....................................................................................................................... 14

Installation and setup


1. MetaTrader 4 English version has to be installed.
2. If Microsoft .Net 4 Framework is not installed, please download it from here
http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=0a391abd-25c14fc0-919f-b21f31ab88b7 or http://www.microsoft.com/downloads/en/details.aspx?FamilyID=9cfb2d51-5ff4-4491-b0e5b386f32c0992&displaylang=en and install it.

3. Install Microsoft Visual C++ 2010 SP1 Redistributable Package (x86). Follow the install instructions

4. Run registerCOM.cmd as administrator.


To install as admin you have to click with your right mouse button on registerCOM.cmd in the windows explorer, menu will pop up with "run as admin"-see picture below

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

6. Run MetaTrader application


7. Switch to MetaEditor (F4)

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

9. After successful compilation switch back to MetaTrader (F4)

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.

After successful login, an alert should popup

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

API method signatures are available in include\ZESPMT4Unmanaged.mqh

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 get the value of authentication key use this script


string Filename = "zignalsAuth.key"; int start() { int handle = FileOpen(Filename, FILE_READ, ';'); if(handle > 0) { string authKey = (FileReadString(handle)); FileClose(handle); } }

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]);

API call samples: 1. code to create entry:


int strategyId = 440; //how to get strategy id? see this section string symbol = "MSFT.NMS"; bool isBuying = true; double shares = 100; string extraInfo = "low price on the market"; double target = 30.5; double stop = 25.2; bool isProcessed = false; string errorMessage[1] = { "" }; isProcessed = CreateEntry(authKey, strategyId, symbol, shares, isBuying, extraInfo, target, stop, errorMessage);

2. code to update target and stop:


int strategyId = 440; string symbol = "MSFT.NMS"; string extraInfo = "narrowing target & stop range"; double target = 29.5; double stop = 26.2; bool isProcessed = false; string errorMessage[1] = { "" }; isProcessed = UpdateTargetAndStop(authKey, strategyId, symbol, extraInfo, target, stop, errorMessage);

3. code to create preemptive entry:


int strategyId = 440; string symbol = "MSFT.NMS"; bool isBuying = true; double shares = 300; string extraInfo = ""; double triggerPrice = 28.2; double target = 29.1; double stop = 27.8; bool isProcessed = false; string errorMessage[1] = { "" }; isProcessed = CreatePreemptiveEntry(authKey, strategyId, symbol, shares, isBuying, extraInfo, triggerPrice, target, stop, errorMessage);

To logout click on Zignals_Lougout (navigator panel in MetaTrader)

Possible errors (list is incomplete, subject to change):


Error Symbol is not recognized Reason / FIX MSFT is traded on NMS & AMS / it's required to use "MSFT.NMS" instead of "MSFT" Market is closed / use "create premarket entry" instead of "create entry"

Market is not open at the moment

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

Stop price is not set properly

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

MetaTrader crashes with a message like this:

Solution 1. Close Metatrader 2. Run registerCOM.cmd (run as administrator!) (see installation step 3)

Zignals compiling warning.

[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.

You might also like