trading binary option on strategy tester
Table of Contents
1. Introduction
2. Installation
3. Binary Options strategy case
three.ane. Ascertain Binary Options strategy
3.ii. Create Binary Options strategy
3.ii.1. Input parameters
iii.ii.two. Include Binary-Options-Strategy-Library
iii.2.3. Add CallStrategy()
3.2.4. Implement CheckMyRules() and helper-function
iii.two.5. Impress out debug values
3.2.6. Use of external Indicators (ex4 files)
3.iii. The complete lawmaking
iv. Run a backtest (video)
5. Run a forrard examination
6. FAQ
vii. Miscellaneous
ane. Introduction
This commodity shows how to build a Binary Options strategy and test it in Strategy-Tester of Metatrader iv with Binary-Options-Strategy-Tester utility. By default Strategy-Tester of Metatrader 4 can test Skillful Advisors and Indicators against historical data, but it cannot handle Binary Options with expire times. As I demand a possibility to test Binary Options strategies automated in Strategy-Tester of MetaTrader 4, the Binary-Options-Strategy-Tester was build as a utility to fit those needs.
The concept contains the following parts:
This is a step by step case how to build a Binary Options strategy stored in an Indicator (marked as red in prototype above) to communicate through Binary-Options-Strategy-Library (marked every bit green in image above) with the Binary-Options-Strategy-Tester (marked as blue in image to a higher place), to place virtual orders and count their results with backtests and forward tests.
Please keep in heed: Backtesting with historical information volition never correspond the real future, just information technology might give y'all an approximate value to get your strategy more than stable.
The quality of your backtest will depends on your historical data. Therefore it is strongly recommended to use a gear up of hight quality data!
ii. Installation
Download and buy Binary-Options-Strategy-Tester utility from marketplace:
Test-Framework to test Binary Options strategies in Strategy-Tester of MetaTrader four.
Why a purchased version of Binary-Options-Strategy-Tester utility is needed?
A Binary-Options strategy has to call a function of the Binary-Options-Strategy-Tester (via Binary-Options-Strategy-Library) to place the virtual trades. Related to the license concept of MQL4 this only works if the product has a working license. Therefore you accept to purchase the product to exam Binary Options strategies or this instance.
Download free BinaryOptionsStrategyLibrary.mqh and identify information technology in into binder \Include ([path to your MetaTrader 4]\MQL4\Include):
The free library will provide several functions to build your Binary Options strategy hands and to communicate with the Binary-Options-Strategy-Tester. See Binary-Options-Strategy-Library for more details of the library.
Download costless KVO.mq4 indicator and place it (and the compiled KVO.ex4 file) into folder \Indicators\Downloads ([path to your MetaTrader 4]\MQL4\Indicators\Downloads):
The KVO indicator is used equally an example to show the access of external indicators and there ex4 files in section "3.2.6 Apply of external Indicators (ex4 files)". Run into https://www.mql5.com/en/code/8677 for more details of the indicator.
At present you can go further with section "3. Binary options strategy example" and build the example code by yourself or just download the code of this example below.
Optional download BinaryOptionsStrategyExample.mq4 and place it (and the compiled BinaryOptionsStrategyExample.ex4 file) into folder \Indicators ([path to your MetaTrader four]\MQL4\Indicators):
Download the code of this Binary Options strategy instance to let it run without building it by yourself.
To compile the needed .ex4 files open up the .mq4 files (KVO.mq4 and BinaryOptionsStrategyExample.mq4 - NOT Binary-Options-Strategy-Library.mqh) in MetaQuotes Language Editor and click on push button "Compile" or just restart your MetaTrader 4 after these files are stored in the described folders and MetaTrader 4 volition do this automatically for you.
three. Binary Options strategy case
The following steps volition guide you throgh an example how to build an example Binary Options strategy stored in an Indicator to communicate with Binary-Options-Strategy-Tester. You can build it by yourself or only download the code of the BinaryOptionsStrategyExample.mq4.
Delight note:This strategy is not a assisting Binary Options strategy! It is just an example how to build a strategy in an indicator to communicate with the Binary-Options-Strategy-Tester utility. Of grade you have to build a profitable strategy by yourself. But equally yous will see, this utility volition aid you to test and improve your Binary Options strategy.
3.1 Define Binary Options strategy
First of all nosotros have to define the strategy and the changable values (input parameters). MQL4 documentation shows all technical indicators, which can be adressed over the iCustom interface: https://docs.mql4.com/indicators.
Let us say we similar to create a simple Moving Average cross strategy with ane "fast" and 1 "ho-hum" Moving Boilerplate to trade on adjacent candle after they accept crossed each other. Documentation tells, how nosotros tin can get the value of a single Moving Boilerplate: https://docs.mql4.com/indicators/ima.
Permit the states farther say, we like to choose values for "MA averaging menses" (fast and slow) and for "applied price" as well as for the "averaging method". Other values (like symbol, timeframe and shift) depends on the testcase (e.thousand. the symbol the tester runs on) and should exist set up automatically. Therefore we basically demand the following variables for a Moving Boilerplate:
int ma_period
int ma_method
int applied_price
As we demand ii Moving Averages to check their crosses, we demand the post-obit input parameters for the strategy example with some default values:
int period_fast = 5;
int period_slow = 10;
int method_both =0;
int applied_price_both =0;
three.ii Create Binary Options strategy
Y'all need to build an indicator which stores your Binary Options strategy to drag information technology on the chart where Binary-Options-Strategy-Tester is running on.
Open up MetaQuotes Language Editor (in MetaTrader iv click on "Tools" -> "MetaQuotes Language editor" or just press F4) and click on "New":
The MQL Magician will appear. Select "Custom Indicator" to create an empty indicator and click on "Adjacent":
Enter the name, copyright and link of the strategy as well as the input parameters with their types and default values (initial values) by clicking "Add"-Push and printing "Next":
On tab event handlers select checkbox "OnCalculate" as we need this event to cheque for our strategy on every tick. Press "Next":
On tab cartoon backdrop select checkbox "Indicator in seperate window" every bit we need a seperate window to print out the debug values. Press "Finish":
The initial code of your indicator will announced:
#property copyright "Copyright 2016, __martin__"
#property link"https://www.mql5.com/en/users/__martin__"
#property version "1.00"
#property strict
#holding indicator_separate_window
input int period_fast=5;
input int period_slow=10;
input int method_both=0;
input int applied_price_both=0;
int OnInit()
{
render(INIT_SUCCEEDED);
}
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &fourth dimension[],
const double &open[],
const double &loftier[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
render(rates_total);
}
3.two.1 Input parameters
The initial input parameters are created with the MQL Wizard (see 3.ii Create Binary Options strategy) and we volition heighten them with the following steps.
To avoid to have to enter int-values for applied price and averaging method of the Moving Averages for input parameters, the type for method_both and applied_price_both is changed from int to type of enumeration with a default value.
ENUM_MA_METHOD: https://docs.mql4.com/constants/indicatorconstants/enum_ma_method
ENUM_APPLIED_PRICE: https://docs.mql4.com/constants/indicatorconstants/prices#enum_applied_price_enum
In add-on comments for the input parameters are added to show the comments as labels instead of variable names:
...
inputint period_fast =v;
inputint period_slow =10;
inputENUM_MA_METHOD method_both = MODE_SMA;
inputENUM_APPLIED_PRICE applied_price_both = PRICE_CLOSE;
...
With this modifications the input parameters provides a dropdown with the available values to select besides as "labels" for the input parameters:
3.2.two Include Binary-Options-Strategy-Library
If you have downloaded and stored the library (run across 2. Installation) into \Include folder ([path to your MetaTrader iv]\MQL4\Include), y'all are able to include the library like this:
#property copyright "Copyright 2016, __martin__"
#property link"https://world wide web.mql5.com/en/users/__martin__"
#property version "i.00"
#property strict
#holding indicator_separate_window
#include <BinaryOptionsStrategyLibrary.mqh>
...
The library will only be available similar described in the example above if you placed it in \Include folder of your MetaTrader 4.
Changing the content of the library is not needed!
Binary-Options-Strategy-Library will enhance the input parameters with 2 new parameters:
- Identify only ane SELL or one BUY merchandise per candle
- Bank check only at the offset of a new candle for the strategy
iii.two.3 Add CallStrategy()
Add a call to CallStrategy()-function in OnCalculate() of your strategy indicator to telephone call the strategy on every new tick. CallStrategy() is provided by Binary-Options-Strategy-Library y'all accept inlcuded like discribed above:
...
intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &depression[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
CallStrategy();
return(rates_total);
}
CallStrategy()-function in Binary-Options-Strategy-Library will call a function named CheckMyRules() in your indicator where you tin place your conditions for your Binary Options strategy.
Therefore you have to implement the function CheckMyRules() in your Binary Options strategy indicator.
3.2.4 Implement CheckMyRules() and helper-function
In CheckMyRules()-function, which is called through the Binary-Options-Strategy-Library, the weather for the strategy are implemented and trades are placed through PlaceTrade()-function of the library. Values of both Moving Averages are temporarilly stored in variables to compare them in if-conditions while the values of the Moving Averages are taken from the helper-function GetValuesForMA():
...
inputint period_fast =5;
inputint period_slow =ten;
inputENUM_MA_METHOD method_both = MODE_SMA;
inputENUM_APPLIED_PRICE applied_price_both = PRICE_CLOSE;
...
void CheckMyRules()
{
double emaSlow_Current = GetValueForMA(period_slow, 0);
double emaFast_Current = GetValueForMA(period_fast, 0);
double emaSlow_Past = GetValueForMA(period_slow, i);
double emaFast_Past = GetValueForMA(period_fast, 1);
if(emaFast_Past > emaSlow_Past
&& emaFast_Current < emaSlow_Past)
{
PlaceTrade(OP_SELL);
}
if(emaFast_Past < emaSlow_Past
&& emaFast_Current > emaSlow_Past)
{
PlaceTrade(OP_BUY);
}
}
double GetValueForMA(int _period,int _shift)
{
render iMA(NULL,0,_period,0,method_both,applied_price_both,_shift);
}
3.two.5 Print out debug values
The function PrintDebugValue() privides a possibility to impress out debug values while the tester is running. In the example beneath the values of the Moving Averages are printed out with their variable names every bit labels:
...
inputint period_fast =5;
inputint period_slow =10;
inputENUM_MA_METHOD method_both = MODE_SMA;
inputENUM_APPLIED_PRICE applied_price_both = PRICE_CLOSE;
...
void CheckMyRules()
{
double emaSlow_Current = GetValueForMA(period_slow, 0);
double emaFast_Current = GetValueForMA(period_fast, 0);
double emaSlow_Past = GetValueForMA(period_slow, 1);
double emaFast_Past = GetValueForMA(period_fast, 1);
PrintDebugValue("emaSlow_Current: ",(string)emaSlow_Current,0);
PrintDebugValue("emaFast_Current: ",(cord)emaFast_Current,1);
PrintDebugValue("emaSlow_Past: ",(cord)emaSlow_Past,ii);
PrintDebugValue("emaFast_Past: ",(cord)emaFast_Past,3);
if(emaFast_Past > emaSlow_Past
&& emaFast_Current < emaSlow_Past)
{
PlaceTrade(OP_SELL);
}
if(emaFast_Past < emaSlow_Past
&& emaFast_Current > emaSlow_Past)
{
PlaceTrade(OP_BUY);
}
}
double GetValueForMA(int _period,int _shift)
{
return iMA(Cipher,0,_period,0,method_both,applied_price_both,_shift);
}
3.2.6 Use of external Indicators (ex4 files)
In addition an external indicator which stores its values in buffers tin be accessed for the Binary Options strategy, even if only the compiled ex4-file exists.
Let the states say we like to include the signal line of the KVO indicator https://world wide web.mql5.com/en/lawmaking/8677 to place trades simply if the bespeak line is over 0 for BUY trades and under 0 for SELL trades. Download the KVO.mq4 indicator and place the compiled (ex4 file) into folder \Indicators\Downloads ([path to your MetaTrader 4]\MQL4\Indicators\Downloads).
To compile the needed .ex4 file open KVO.mq4 in MetaQuotes Language Editor and click on push "Compile" or but restart your MetaTrader 4 later the file is stored in the described folder and MetaTrader 4 will practise this automatically for you.
First we have to identify the relevant buffers which stores the relevant values to admission. Therefore nosotros printing the push button "Information Window" in MetaTrader 4 to bear witness all available buffers of the used indicators and drag the KVO indicator on a nautical chart. By hovering the cross over the chart (printing mouse-bicycle on chart to bring up the cross) the buffer values of the indicator of the hovered timeperiod volition be shown in information window:
The data window labels tells u.s. the second buffer value of the indicator stores the point line. If buffers of indicators did not have labels, we can discover the right i by comparison the buffer values with the displayed value under the cross in the chart and indicator. Buffers of an indicator starts with 0, so we have buffer value one = buffer 0, buffer value ii = buffer ane and and so on and we accept to access buffer 1 to get the betoken value.
Side by side we have to know all input parameters of the external indicator we similar to access. By draging the indicator on a nautical chart, we come across all input paremeters:
Allow us further say, we like to access the indicator with (its default) values: 34, 55 and thirteen. We use a helper role (based on iCostum), wich provides united states the possibility to get the values of the indicator with parameters for buffer and shift, while shift 0 will be the value of the electric current candle, shift 1 the value of the terminal candle, shift 2 the value of the second to final candle and so on. In addition we temporarilly store the values of the indicator buffer and enhance the if-status of the strategy:
...
inputint period_fast =5;
inputint period_slow =10;
inputENUM_MA_METHOD method_both = MODE_SMA;
inputENUM_APPLIED_PRICE applied_price_both = PRICE_CLOSE;
...
void CheckMyRules()
{
double emaSlow_Current = GetValueForMA(period_slow, 0);
double emaFast_Current = GetValueForMA(period_fast, 0);
double emaSlow_Past = GetValueForMA(period_slow, 1);
double emaFast_Past = GetValueForMA(period_fast, ane);
double kvoSignal = GetValuesFromIndicator__KVO__(1,0);
PrintDebugValue("emaSlow_Current: ",(cord)emaSlow_Current,0);
PrintDebugValue("emaFast_Current: ",(string)emaFast_Current,1);
PrintDebugValue("emaSlow_Past: ",(string)emaSlow_Past,two);
PrintDebugValue("emaFast_Past: ",(string)emaFast_Past,3);
if(emaFast_Past > emaSlow_Past
&& emaFast_Current < emaSlow_Past
&& kvoSignal < 0)
{
PlaceTrade(OP_SELL);
}
if(emaFast_Past < emaSlow_Past
&& emaFast_Current > emaSlow_Past
&& kvoSignal > 0)
{
PlaceTrade(OP_BUY);
}
}
double GetValueForMA(int _period,int _shift)
{
render iMA(NULL,0,_period,0,method_both,applied_price_both,_shift);
}
double GetValuesFromIndicator__KVO__(int _buffer, int _shift=0)
{
return (
iCustom (
NULL,
0,
"\\Downloads\\KVO.ex4",
34,
55,
13,
_buffer,
_shift
)
);
}
It is likewise possible to enhance the input parameters of our strategy indicator with the values for the used KVO indicator and set the values in helper function past variables. As this tutorial should exist just an example and "as simple every bit possible", this variant is not shown.
3.iii The complete code
Below you will discover the complete code of the Binary-Options-Strategy-Example from all the steps above, ready to drag on the Binary-Options-Strategy-Tester to test and meet the results on chart:
#property copyright "Copyright 2016, __martin__"
#property link"https://www.mql5.com/en/users/__martin__"
#property version "1.00"
#property strict
#property indicator_separate_window
#include <BinaryOptionsStrategyLibrary.mqh>
input int period_fast =five;
input int period_slow = 10;
input ENUM_MA_METHOD method_both = MODE_SMA;
input ENUM_APPLIED_PRICE applied_price_both = PRICE_CLOSE;
int OnInit()
{
return(INIT_SUCCEEDED);
}
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open up[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &book[],
const int &spread[])
{
CallStrategy();
render(rates_total);
}
void CheckMyRules()
{
double emaSlow_Current = GetValueForMA(period_slow, 0);
double emaFast_Current = GetValueForMA(period_fast, 0);
double emaSlow_Past = GetValueForMA(period_slow, 1);
double emaFast_Past = GetValueForMA(period_fast, ane);
double kvoSignal = GetValuesFromIndicator__KVO__(1,0);
PrintDebugValue("emaSlow_Current: ",(string)emaSlow_Current,0);
PrintDebugValue("emaFast_Current: ",(string)emaFast_Current,1);
PrintDebugValue("emaSlow_Past: ",(string)emaSlow_Past,two);
PrintDebugValue("emaFast_Past: ",(cord)emaFast_Past,three);
if(emaFast_Past > emaSlow_Past
&& emaFast_Current < emaSlow_Past
&& kvoSignal < 0)
{
PlaceTrade(OP_SELL);
}
if(emaFast_Past < emaSlow_Past
&& emaFast_Current > emaSlow_Past
&& kvoSignal > 0)
{
PlaceTrade(OP_BUY);
}
}
double GetValueForMA(int _period,int _shift)
{
return iMA(NULL,0,_period,0,method_both,applied_price_both,_shift);
}
double GetValuesFromIndicator__KVO__(int _buffer, int _shift=0)
{
return (
iCustom (
Nothing,
0,
"\\Downloads\\KVO.ex4",
34,
55,
thirteen,
_buffer,
_shift
)
);
}
4. Run a backtest (video)
The following video shows how to run a backtest of your Binary Options strategy in Strategy-Tester of MetaTrader iv:
- Start Binary-Options-Strategy-Tester in Strategy-Tester of MetaTrader 4 and ready the input parameters
- Drag your Binary Options strategy indicator on the nautical chart, set the input parameters and check "Allow external expert imports" on the "mutual" tab
- Drag your used indicators with their used input parameters on the nautical chart to run across their values while tester is running (optional)
- Save all settings in a template to run the test with all settings again - using the intermission push of the Strategy-Tester (optional)
- See the results of your Binary Options strategy on the Strategy-Tester chart
5. Run a forward examination
To practice a forward test simply drag the Binary-Options-Strategy-Tester utility and your strategy indicator on your demo or live chart of your broker instead of using it in Strategy-Tester:
- Drag Binary-Options-Strategy-Tester utility on demo or live chart and set the input parameters
- Drag your Binary Options strategy indicator on the chart, set the input parameters and bank check "Let external proficient imports" on the "common" tab
- Drag your used indicators with their used input parameters on the chart to see their values while forward test is running (optional)
- Save all settings in a template to run the test again with all settings (optional)
- See the results of your Binary Options strategy on demo or alive chart
6. FAQ
Question: Why practice you show an example of a non profitable Binary Options strategy?
Answere: This is just an case how to build a strategy in an Indicator to communicate with the Binary-Options-Strategy-Tester utility in market place to exam and improve your strategy.
Question: Binary-Options-Strategy-Tester stops after the verbal amount of losses with fault "Array out of range". Why?
Answere: Binary-Options-Strategy-Tester can rise an mistake subsequently ten losses to stop Tester and to analyse the situaion on the chart. If yous practise not want to, only switch off the option in settings.
Question: No arrows appear on chart afterward I draged my indicator with a working strategy on it. What happened?
Answere: You have to enable "Permit external skilful imports" on the "common" tab while you lot drag your strategy-indicator on the chart (log message will evidence an error in this case).
Question: No arrows appear on chart after I draged my indicator with a working strategy on it with "Permit external skillful imports" enabled. Why?
Answere: A strategy has to call a role of Binary-Options-Strategy-Tester to place virtual trades. Related to the MQL4 license concept this only works if the product has a working license. Therefore y'all take to purchase the product.
Question: No arrows announced on chart afterward I dragged my indicator with a working strategy on it and I got errors similar "Cannot call .." or "Cannot load .." in the log of MetaTrader 4. What can I practise?
Answere: Use the latest version (greater v1.00) of BinaryOptionsStrategyLibrary.mqh. Check version tag in lawmaking of your BinaryOptionsStrategyLibrary.mqh and see changelog v1.01 of BinaryOptionsStrategyLibrary.
Question: I encounter no results on Strategy-Tester tabs "Results", "Graph", "Study". Where I can run into the results?
Answere: Strategy-Tester of MetaTrader iv can not handle Binary Options so these tabs con not be used. Therefore this utility calculates all wins and losses and prints the results on the chart.
vii. Miscellaneous
As I need a possibility to test Binary Options strategies automated in Strategy-Tester of MetaTrader 4 for long time periods in a short time and to practise foward tests on the nautical chart of the banker, this utility was build. I have spent a lot of fourth dimension for the concept and the implementation of the Binary-Options-Strategy-Tester too as for the documentation. Perchance there is a better way to do information technology and maybe some improvements volition bring it closer to fit the needs of you. So delight feel free to contact me for ideas for improvements!
Source: https://www.mql5.com/en/articles/2820
Posted by: shillingeverecten.blogspot.com

0 Response to "trading binary option on strategy tester"
Post a Comment