types of binary options strategies
Tabular array of Contents
1. Introduction
ii. Installation
3. Binary Options strategy example
three.1. Define Binary Options strategy
three.2. Create Binary Options strategy
three.2.1. Input parameters
3.ii.ii. Include Binary-Options-Strategy-Library
three.2.3. Add CallStrategy()
3.2.four. Implement CheckMyRules() and helper-function
3.2.5. Impress out debug values
3.2.6. Use of external Indicators (ex4 files)
three.iii. The consummate code
4. Run a backtest (video)
v. Run a forward test
6. FAQ
7. Miscellaneous
1. Introduction
This article shows how to build a Binary Options strategy and examination information technology in Strategy-Tester of Metatrader four with Binary-Options-Strategy-Tester utility. By default Strategy-Tester of Metatrader 4 can test Expert Advisors and Indicators against historical data, but it cannot handle Binary Options with expire times. Equally I need a possibility to examination Binary Options strategies automated in Strategy-Tester of MetaTrader 4, the Binary-Options-Strategy-Tester was build every bit a utility to fit those needs.
The concept contains the following parts:
This is a step by step example how to build a Binary Options strategy stored in an Indicator (marked every bit cherry-red in image above) to communicate through Binary-Options-Strategy-Library (marked as light-green in image above) with the Binary-Options-Strategy-Tester (marked as blue in epitome above), to place virtual orders and count their results with backtests and forrad tests.
Please keep in mind: Backtesting with historical data volition never represent the real future, simply it might requite y'all an estimate value to get your strategy more than stable.
The quality of your backtest will depends on your historical data. Therefore information technology is strongly recommended to utilize a prepare of hight quality data!
2. Installation
Download and purchase Binary-Options-Strategy-Tester utility from market place:
Test-Framework to examination 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 office of the Binary-Options-Strategy-Tester (via Binary-Options-Strategy-Library) to place the virtual trades. Related to the license concept of MQL4 this simply works if the product has a working license. Therefore you accept to purchase the product to test Binary Options strategies or this example.
Download free BinaryOptionsStrategyLibrary.mqh and place information technology in into folder \Include ([path to your MetaTrader 4]\MQL4\Include):
The gratis library will provide several functions to build your Binary Options strategy easily and to communicate with the Binary-Options-Strategy-Tester. Run across Binary-Options-Strategy-Library for more than details of the library.
Download free 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 every bit an example to show the access of external indicators and in that location ex4 files in section "three.2.6 Use of external Indicators (ex4 files)". See https://www.mql5.com/en/code/8677 for more details of the indicator.
Now you can go further with section "3. Binary options strategy example" and build the instance lawmaking by yourself or merely download the code of this case below.
Optional download BinaryOptionsStrategyExample.mq4 and place information technology (and the compiled BinaryOptionsStrategyExample.ex4 file) into folder \Indicators ([path to your MetaTrader 4]\MQL4\Indicators):
Download the code of this Binary Options strategy case to let it run without building information technology by yourself.
To compile the needed .ex4 files open the .mq4 files (KVO.mq4 and BinaryOptionsStrategyExample.mq4 - Non Binary-Options-Strategy-Library.mqh) in MetaQuotes Language Editor and click on button "Compile" or just restart your MetaTrader 4 after these files are stored in the described folders and MetaTrader 4 will do this automatically for y'all.
iii. Binary Options strategy example
The following steps will guide you lot throgh an example how to build an case Binary Options strategy stored in an Indicator to communicate with Binary-Options-Strategy-Tester. You can build information technology past yourself or just download the code of the BinaryOptionsStrategyExample.mq4.
Please notation:This strategy is not a assisting Binary Options strategy! It is but an example how to build a strategy in an indicator to communicate with the Binary-Options-Strategy-Tester utility. Of course y'all have to build a assisting strategy by yourself. Merely as you will see, this utility will help yous to examination and improve your Binary Options strategy.
3.i Ascertain Binary Options strategy
First of all we 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 usa say we like to create a simple Moving Boilerplate cross strategy with i "fast" and 1 "tedious" Moving Average to trade on side by side candle later they have crossed each other. Documentation tells, how we can go the value of a single Moving Average: https://docs.mql4.com/indicators/ima.
Let us farther say, nosotros like to cull values for "MA averaging period" (fast and dull) and for "applied toll" equally well as for the "averaging method". Other values (similar symbol, timeframe and shift) depends on the testcase (e.g. the symbol the tester runs on) and should be set up automatically. Therefore we basically need the following variables for a Moving Average:
int ma_period
int ma_method
int applied_price
As nosotros demand ii Moving Averages to check their crosses, nosotros need the following input parameters for the strategy instance with some default values:
int period_fast = 5;
int period_slow = ten;
int method_both =0;
int applied_price_both =0;
3.2 Create Binary Options strategy
Yous demand to build an indicator which stores your Binary Options strategy to drag it on the chart where Binary-Options-Strategy-Tester is running on.
Open MetaQuotes Language Editor (in MetaTrader 4 click on "Tools" -> "MetaQuotes Linguistic communication editor" or only press F4) and click on "New":
The MQL Wizard will announced. Select "Custom Indicator" to create an empty indicator and click on "Adjacent":
Enter the name, copyright and link of the strategy also as the input parameters with their types and default values (initial values) by clicking "Add"-Button and press "Adjacent":
On tab event handlers select checkbox "OnCalculate" as we demand this issue to bank check for our strategy on every tick. Press "Side by side":
On tab drawing properties select checkbox "Indicator in seperate window" as we need a seperate window to impress out the debug values. Press "Stop":
The initial code of your indicator will announced:
#holding copyright "Copyright 2016, __martin__"
#property link"https://www.mql5.com/en/users/__martin__"
#property version "1.00"
#property strict
#property indicator_separate_window
input int period_fast=five;
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 &time[],
const double &open[],
const double &high[],
const double &low[],
const double &shut[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
render(rates_total);
}
3.2.1 Input parameters
The initial input parameters are created with the MQL Wizard (meet 3.2 Create Binary Options strategy) and we will enhance them with the following steps.
To avoid to take to enter int-values for applied cost 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 evidence the comments as labels instead of variable names:
...
inputint period_fast =5;
inputint period_slow =ten;
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 bachelor values to select besides as "labels" for the input parameters:
3.2.2 Include Binary-Options-Strategy-Library
If you accept downloaded and stored the library (see 2. Installation) into \Include folder ([path to your MetaTrader 4]\MQL4\Include), you lot are able to include the library like this:
#property copyright "Copyright 2016, __martin__"
#property link"https://www.mql5.com/en/users/__martin__"
#belongings version "1.00"
#property strict
#holding indicator_separate_window
#include <BinaryOptionsStrategyLibrary.mqh>
...
The library will only be available similar described in the instance above if you placed it in \Include folder of your MetaTrader 4.
Changing the content of the library is non needed!
Binary-Options-Strategy-Library will raise the input parameters with two new parameters:
- Place only one SELL or one BUY trade per candle
- Bank check just at the outset of a new candle for the strategy
three.ii.iii Add CallStrategy()
Add a call to CallStrategy()-function in OnCalculate() of your strategy indicator to call the strategy on every new tick. CallStrategy() is provided past Binary-Options-Strategy-Library you take inlcuded like discribed above:
...
intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open up[],
constdouble &loftier[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
CallStrategy();
render(rates_total);
}
CallStrategy()-function in Binary-Options-Strategy-Library volition phone call a office named CheckMyRules() in your indicator where you can place your weather condition for your Binary Options strategy.
Therefore you lot accept to implement the function CheckMyRules() in your Binary Options strategy indicator.
3.two.4 Implement CheckMyRules() and helper-function
In CheckMyRules()-part, which is called through the Binary-Options-Strategy-Library, the weather for the strategy are implemented and trades are placed through PlaceTrade()-office of the library. Values of both Moving Averages are temporarilly stored in variables to compare them in if-weather condition while the values of the Moving Averages are taken from the helper-office GetValuesForMA():
...
inputint period_fast =5;
inputint period_slow =x;
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, ane);
double emaFast_Past = GetValueForMA(period_fast, i);
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(Cypher,0,_period,0,method_both,applied_price_both,_shift);
}
3.2.5 Print out debug values
The part 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 as labels:
...
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, 1);
double emaFast_Past = GetValueForMA(period_fast, 1);
PrintDebugValue("emaSlow_Current: ",(cord)emaSlow_Current,0);
PrintDebugValue("emaFast_Current: ",(string)emaFast_Current,1);
PrintDebugValue("emaSlow_Past: ",(cord)emaSlow_Past,2);
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(Nix,0,_period,0,method_both,applied_price_both,_shift);
}
iii.2.6 Use of external Indicators (ex4 files)
In addition an external indicator which stores its values in buffers tin can be accessed for the Binary Options strategy, fifty-fifty if only the compiled ex4-file exists.
Let us say we like to include the signal line of the KVO indicator https://www.mql5.com/en/code/8677 to identify trades only if the signal line is over 0 for Buy trades and under 0 for SELL trades. Download the KVO.mq4 indicator and identify the compiled (ex4 file) into binder \Indicators\Downloads ([path to your MetaTrader four]\MQL4\Indicators\Downloads).
To compile the needed .ex4 file open KVO.mq4 in MetaQuotes Language Editor and click on push button "Compile" or just restart your MetaTrader 4 after the file is stored in the described folder and MetaTrader 4 volition do this automatically for you.
Start we have to identify the relevant buffers which stores the relevant values to admission. Therefore nosotros printing the push "Data Window" in MetaTrader 4 to evidence all available buffers of the used indicators and drag the KVO indicator on a nautical chart. Past hovering the cross over the chart (printing mouse-bicycle on nautical chart to bring up the cantankerous) the buffer values of the indicator of the hovered timeperiod will be shown in information window:
The data window labels tells the states the 2nd buffer value of the indicator stores the signal line. If buffers of indicators did not accept labels, we can notice the right ane past comparing the buffer values with the displayed value under the cross in the chart and indicator. Buffers of an indicator starts with 0, and so we have buffer value 1 = buffer 0, buffer value 2 = buffer 1 so on and nosotros accept to access buffer 1 to go the betoken value.
Next nosotros have to know all input parameters of the external indicator we like to admission. By draging the indicator on a nautical chart, we see all input paremeters:
Let us farther say, nosotros like to admission the indicator with (its default) values: 34, 55 and 13. We use a helper function (based on iCostum), wich provides united states of america 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 concluding candle, shift two the value of the second to last candle then on. In improver we temporarilly store the values of the indicator buffer and raise the if-condition of the strategy:
...
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, 1);
double emaFast_Past = GetValueForMA(period_fast, 1);
double kvoSignal = GetValuesFromIndicator__KVO__(1,0);
PrintDebugValue("emaSlow_Current: ",(string)emaSlow_Current,0);
PrintDebugValue("emaFast_Current: ",(string)emaFast_Current,1);
PrintDebugValue("emaSlow_Past: ",(cord)emaSlow_Past,2);
PrintDebugValue("emaFast_Past: ",(string)emaFast_Past,iii);
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(Goose egg,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 also possible to heighten the input parameters of our strategy indicator with the values for the used KVO indicator and set the values in helper function past variables. Equally this tutorial should be only an example and "as simple as possible", this variant is not shown.
three.3 The complete lawmaking
Below you will find the consummate code of the Binary-Options-Strategy-Case from all the steps above, ready to drag on the Binary-Options-Strategy-Tester to examination and see the results on chart:
#property copyright "Copyright 2016, __martin__"
#property link"https://www.mql5.com/en/users/__martin__"
#property version "ane.00"
#belongings 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[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
CallStrategy();
return(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: ",(cord)emaSlow_Current,0);
PrintDebugValue("emaFast_Current: ",(cord)emaFast_Current,ane);
PrintDebugValue("emaSlow_Past: ",(string)emaSlow_Past,2);
PrintDebugValue("emaFast_Past: ",(cord)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)
{
return iMA(Goose egg,0,_period,0,method_both,applied_price_both,_shift);
}
double GetValuesFromIndicator__KVO__(int _buffer, int _shift=0)
{
render (
iCustom (
NULL,
0,
"\\Downloads\\KVO.ex4",
34,
55,
thirteen,
_buffer,
_shift
)
);
}
iv. Run a backtest (video)
The following video shows how to run a backtest of your Binary Options strategy in Strategy-Tester of MetaTrader 4:
- Start Binary-Options-Strategy-Tester in Strategy-Tester of MetaTrader four and set the input parameters
- Drag your Binary Options strategy indicator on the 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 chart to see their values while tester is running (optional)
- Save all settings in a template to run the test with all settings again - using the pause button of the Strategy-Tester (optional)
- See the results of your Binary Options strategy on the Strategy-Tester chart
v. Run a forward examination
To practice a forward examination only drag the Binary-Options-Strategy-Tester utility and your strategy indicator on your demo or alive chart of your banker instead of using information technology in Strategy-Tester:
- Elevate Binary-Options-Strategy-Tester utility on demo or live nautical chart and prepare the input parameters
- Drag your Binary Options strategy indicator on the chart, set the input parameters and check "Let external practiced imports" on the "common" tab
- Drag your used indicators with their used input parameters on the nautical chart to see their values while forward test is running (optional)
- Relieve all settings in a template to run the examination once again with all settings (optional)
- Encounter the results of your Binary Options strategy on demo or live nautical chart
six. FAQ
Question: Why exercise you show an example of a not profitable Binary Options strategy?
Answere: This is but an instance how to build a strategy in an Indicator to communicate with the Binary-Options-Strategy-Tester utility in market place to examination and meliorate your strategy.
Question: Binary-Options-Strategy-Tester stops later on the exact amount of losses with error "Array out of range". Why?
Answere: Binary-Options-Strategy-Tester can rise an fault subsequently x losses to end Tester and to analyse the situaion on the nautical chart. If you practice not want to, just switch off the pick in settings.
Question: No arrows announced on nautical chart afterwards I draged my indicator with a working strategy on it. What happened?
Answere: You accept to enable "Allow external expert imports" on the "mutual" tab while you drag your strategy-indicator on the chart (log message volition show an fault in this case).
Question: No arrows appear on chart after I draged my indicator with a working strategy on it with "Allow external expert imports" enabled. Why?
Answere: A strategy has to call a function 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 you lot accept to purchase the product.
Question: No arrows announced on chart afterwards I dragged my indicator with a working strategy on it and I got errors similar "Cannot phone call .." or "Cannot load .." in the log of MetaTrader 4. What can I do?
Answere: Utilize the latest version (greater v1.00) of BinaryOptionsStrategyLibrary.mqh. Check version tag in code of your BinaryOptionsStrategyLibrary.mqh and come across changelog v1.01 of BinaryOptionsStrategyLibrary.
Question: I come across no results on Strategy-Tester tabs "Results", "Graph", "Report". Where I can meet the results?
Answere: Strategy-Tester of MetaTrader iv tin 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.
7. Miscellaneous
Equally I need a possibility to test Binary Options strategies automated in Strategy-Tester of MetaTrader 4 for long time periods in a curt time and to exercise foward tests on the nautical chart of the banker, this utility was build. I take spent a lot of time for the concept and the implementation of the Binary-Options-Strategy-Tester likewise equally for the documentation. Mayhap in that location is a better way to do it and maybe some improvements will bring it closer to fit the needs of y'all. So please feel gratuitous to contact me for ideas for improvements!
Source: https://www.mql5.com/en/articles/2820
Posted by: marlowesirstee1955.blogspot.com

0 Response to "types of binary options strategies"
Post a Comment