ZuluScript Creation Guide

Last updated on 24-Jun-2016


ZuluTrade has created a new generation of trading scripts, that allows Traders to create and deploy their own trading robots and indicators, directly via their ZuluTrade Trader account, without the need for any external software or 3rd party registrations!
ZuluScripts are implemented using ZuluTrade Query Language (zql) which has been developed to be compatible with the most commonly used scripting languages of the Forex market.

All you need to do in order to use ZuluScripts is a Trader account with the ZuluTrade+ option enabled as shown at the Settings tab, Broker Account Link Settings, of your account.

Accessing the ZuluTrade Trading Scripts Editor

In order to access the ZuluTrade Trading Scripts, once you have signed up with ZuluTrade and linked your account with the ZuluTrade+ platform, you need to navigate to the ZuluTrade Trading Station and click on 'Trading Scripts'.
A new pop-up window will then appear titled 'Trading Client'.
On top right sidebar of the Scripts Editor, you can find 4 different tabs that switch the functionality mode of the Scripts Editor.
The first one sets the mode to creation of Scripts, the second sets the mode to creation of Custom Indicators, the third to the creation of Headers and the last brings up the ZQL Glossary, where you can find detailed information for each command of the ZQL language.


Creating a ZuluScript

In order to create your ZuluScript, you need to click on the 'Create Script' button of the Scripts Editor.

Upon creating the new script, the editor pane gets filled with a template zql code - it is on this panel where the script code is to be entered.

Below the editor and on the right side there are three buttons, which will assist in creating your ZuluScript - Save, Complile and Deploy.

Save - the Save button saves your script at any given time, so that any changes and progress is not lost.

However, saving a change on a script does not indicate that this change is ready for use. Any change needs to be Compiled and Deployed prior to being available for use.

Compile - Compiling a script will check the code for syntax errors and, if compilation is successful, will create the binary files associated with our script so that it can be executed.
If the compilation process fails, the errors encountered will be listed in the 'Compiler Output' panel.

Please see below an example of an unsuccessful compilation:
Deploy - In order to deploy a script, it has to first have been compiled. Once this has taken place and the .zql file has been created, you can then Deploy the script and have it available for use at your ZuluTrade Trading Station!

Meta Data - On the right side of the window the Meta Data of your script can be amended.
The 'Name' field is the name that will be shown when attaching the script on a chart.
The Filename' field is the filename with which the script is to be stored internally in ZuluTrade's server. It is not mandatory to change this field, but if you wish to do so, keep in mind it needs to end with the '.zql' suffix.
The 'Description' field is a short description that will be visible when attaching the script to a chart. The description can help in reminding you the exact functionality of the script, so please elaborate any details you need in this space.

List of Scripts - Below the Meta Data fields, a list of all the saved scripts is provided. Please note that each new script created, will be saved automatically.
The currently selected script (whose code is displayed at the editor pane) is highlighted
Deleting a script - Should you need to delete a script, you just have to click on the "x" icon next to the script name, and confirm deletion at the relevant pop-up.
Example Script - Lets look at an example zql script, which you can use for testing purposes:

#property copyright "Copyright © 2014, Zulutrade Inc"
#property link "www.zulutrade.com"

extern int BuyThreshold = 40;
extern int SellThreshold = 30;
extern double Lots = 1;
extern int MagicNumber = 33;
extern string comment = "by example script";
extern int maxOpenPositions = 3;
extern int shift = 1;

int RSILength = 14;
int TimeOfFirstBar = 0;

int init() {

int start() {
double RSI = 0.0;

if (isFirstTickOfCurrentBar()) {
Print("Got RSI value for period H1 and shift ", shift, " equals to ", RSI);
// Buy Condition
if ( RSI >= BuyThreshold && OrdersTotal() < maxOpenPositions) {
if (doBuy() == false) {
return (0);
// Close condition
if ( RSI <= SellThreshold && OrdersTotal() > 0) {
if(doClose() == false) {

// Figures out the first tick of a new bar
bool isFirstTickOfCurrentBar() {
if (TimeOfFirstBar != Time[1]) {
TimeOfFirstBar = Time[1];
return (true);
return (false);

// Close an order checking magic number to make sure it is generated from current script
bool doClose() {
if (OrderClose( OrderTicket(), OrderLots(), Ask, 0, White) == -1) {
Print ("Failed to close trade ", OrderTicket(),", error # ", GetLastError());
Print ("Successfully closed trade ", OrderTicket(),", error # ", GetLastError());

// Open a new order
bool doBuy() {
int ticket = OrderSend( Symbol(), OP_BUY, Lots, Ask, 0, 0.0, 0.0, comment, MagicNumber, 0, Lime);
if (ticket < 0) {
Print ("Failed to open trade, error # ", GetLastError());
return (false);
Print ("Successfully opened ticket ", ticket);
return (true);
This script checks in every cycle for the number of open positions. If there are none open and some indicator conditions are met, the script opens a new position. Otherwise, if there are many open positions, it closes one.
NOTE: It's not a real trading strategy and is only for demonstration purposes.

If at any point you need to create a new script, you simply click on the 'Create Script' button and start this process again.


Creating a Custom Indicator

Custom indicators can be created and used in another trading script extending the technical indicators already available in the language.

Custom indicators can be used in any ZuluScript using the iCustom() ZQL function after having saved, compiled and deployed your custom indicator.

Note: For the moment, we cannot render Custom indicators on the charts.

In order to create your Custom Indicator, you need to click on the 'Create Indicator' button of the Scripts Editor.

Please make sure the Editor is switched to Custom indicators tab:

You then need to Edit, Name, Save and Deploy your custom indicator when ready!

Edit, Name, Save and Deploy work on a similar manner to ZuluScripts
Note: the Name of the indicator will be the one to be used later calling the iCustom() function to access it on your ZuluScripts.

Using the custom indicator in a new Script is as simple as follows:

extern int index = 0;
int MODE = 0;
int init() {
int start() {
double value = iCustom(NULL, NULL, "my_new_indicator", 0, index);

Print("my_new_indicator value for bar ", index, " is ", value);


Creating a Header

Here you can define reusable functions that can be imported and used by any Script or Custom Indicator.

Please note that Headers are not ZQL scripts so they do not require an init(), start() or deinit() function.

In order to create your Header, you need to click on the 'Create Header' button of the Scripts Editor.

Please make sure the Editor is switched to Headers tab:
Note I: It is the filename that should be used in the #include<> directive on the script that you will need to access the functions.

Note II: Headers are only saved. Compilation or deployment is not necessary as the code will be compiled and deployed when imported by a Script or Custom Indicator.

Using the header in a new Script is as simple as including the header file as follows

#include "my_common_functions.zqh"

int init() {

int start() {



Inside the Glossary you can find detailed information for each command of the ZQL language.

Simply click on the letters on the top to auto-scroll to the letter's listing. Also, by clicking on the letter headers of the list, you can expand/collapse each letter's functions and by clicking on a function name/header you can expand/collapse the function details.


Using a Script on your Trader account

After having a Script successfully compiled and deployed, you can close the Script Editor window and attach the Script to a chart.

In order to do this, you need to navigate to the currency pair and period of your choice. For this example, on the EURUSD chart with a period of H1.

Click on the Trading Scripts button (highlighted in the screenshot below) and select the script of your choice.

If you leave the mouse over the script, a tooltip will appear containing the Script's description.

In order to start the script on the selected Chart/Period, simply click on the script's name and a new window will appear, containing the description of the script as well as any initialization fields for the external variables of the script.

Having adjusting the parameters according to your needs, you then need to click on the "Start" button and the script is attached on the chart!

Note: The script will run on this chart from the ZuluTrade servers, irrespective of your PC being switched on or whether you are logged in to your account or not.

Trading Scripts tab - Here you can review all the currently active trading scripts on each Chart/Period, together with the running version and time of last update.

You can also navigate directly to the Chart where the Script is running via the Chart icon.

Messages tab - Any messages from your Script, prints, messages from ZuluTrade regarding your Script etc will appear on this section.


Stop and Undeploy a Script

You can Stop and Undeploy a Script at any given time

Stopping a Script - In order to stop a script from running on a Chart/Period all you need to do is navigate to the 'Trading Scripts' tab, click on the 'x' button on the right of the Script you wish to Stop, and confirm Stoppage at the relevant pop-up.

Note: Stopping a script, will only stop it from running on a Chart/Period. The Script will remain on your Trader account and on your Trading Scripts

Undeploying a Script - In order to undeploy a script all we have to do is navigate to the Trading Scipts section, click on the 'x' button near its name, and confirm Undeployment at the relevant pop-up.

Note: Undeploying the script will just remove it from the list of available Scripts at your Trader account, it will not delete the script from the Script Editor window.


ZQL Standalone Compiler User Guide

Getting started with ZQL Standalone Compiler

ZQL Standalone Compiler is the standalone mode of the ZQL Script compiler which zulutrade offers in its web platform. It will compile any ZQL compatible script (e.g. mq4) to a .zl file.


ZQL Standalone Compiler is distributed from ZuluTrade's site.

The compiler is available in zip or tar file formats.

zql-standalone-compiler-stable.zip zql-standalone-compiler-stable.zip.md5 zql-standalone-compiler-stable.zip.sha1
zql-standalone-compiler-stable.tar.bz2 zql-standalone-compiler-stable.tar.bz2.md5 zql-standalone-compiler-stable.tar.bz2.sha1


  • Java JDK 6 (we recommend that you use Java JDK 6 hotspot)


Simply extract your chosen download to the directory of your choice. You can install ZQL Standalone Compiler on any operating system that supports the zip or tar formats. Refer to the Release Notes for additional information related to the release.

A Quick Tour

Now that you’ve downloaded ZQL Standalone Compiler, the next thing to discuss is the layout of the distribution and explore the compiler's directory structure, key configuration files, log files and so on.

Directory Structure
Directory Description
Contains the compiler's library dependencies.
Contains crucial configuration files that should not be altered in any way.
The run script for Windows machines.
The run script for Linux/Unix machines.
Compiler Options
Parameter Name
Parameter Short Name
help h - Prints the help message to the console.
class c Any string value The generated class name.
package p Any string in the form of a package path The generated package name
output o Any string value The name of the compiled output file without extension
zqh z Any string in the form of a directory path (relative or absolute) Include directory path with custom zqh files
name n

The desired scripts name

if you have spaces make sure you put it between " in Windows and \" in Linux

The name of the script to show once it is loaded in ZuluTrade's system
description d

The desired scripts description

if you have spaces make sure you put it between " in Windows and \" in Linux

The description of the script to show once it is loaded in ZuluTrade's system
Compile a custom expert script Output
run.bat -c MyCustomExpert -p org.test -o my_expert -n "My Expert" custom_expert.zql
Compile a custom expert script with a custom header script (e.g. in headers directory) Output
run.bat -c MyCustomExpert -p org.test -o my_expert -n "My Expert" -z headers custom_expert.zql