banner



fractal strategy for binary options

Table of Contents

i. Introduction
2. Installation
iii. Binary Options strategy instance
3.i. Define Binary Options strategy
3.2. Create Binary Options strategy
iii.2.1. Input parameters
three.2.2. Include Binary-Options-Strategy-Library
three.ii.3. Add CallStrategy()
three.2.iv. Implement CheckMyRules() and helper-role
3.two.5. Print out debug values
iii.2.vi. Use of external Indicators (ex4 files)
three.3. The consummate code
4. Run a backtest (video)
5. Run a forward test
vi. FAQ
seven. Miscellaneous


i. Introduction

This article shows how to build a Binary Options strategy and test it in Strategy-Tester of Metatrader four with Binary-Options-Strategy-Tester utility. By default Strategy-Tester of Metatrader 4 tin can test Expert Advisors and Indicators against historical data, just 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 post-obit parts:

Binary Options Strategy Tester Concept

This is a step by step example how to build a Binary Options strategy stored in an Indicator (marked as red in image above) to communicate through Binary-Options-Strategy-Library (marked as greenish in image above) with the Binary-Options-Strategy-Tester (marked as blue in image above), to place virtual orders and count their results with backtests and frontward tests.

Delight keep in heed: Backtesting with historical data will never represent the real hereafter, but it might give you an approximate value to get your strategy more stable.
The quality of your backtest volition depends on your historical data. Therefore it is strongly recommended to use a prepare of hight quality data!


2. Installation

Download and purchase Binary-Options-Strategy-Tester utility from market:
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 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 production has a working license. Therefore you lot take to buy the product to test Binary Options strategies or this example.

Download costless BinaryOptionsStrategyLibrary.mqh and place it in into binder \Include ([path to your MetaTrader 4]\MQL4\Include):
The free library volition provide several functions to build your Binary Options strategy easily and to communicate with the Binary-Options-Strategy-Tester. See Binary-Options-Strategy-Library for more details of the library.

Download free KVO.mq4 indicator and place information technology (and the compiled KVO.ex4 file) into folder \Indicators\Downloads ([path to your MetaTrader 4]\MQL4\Indicators\Downloads):
The KVO indicator is used as an instance to evidence the access of external indicators and there ex4 files in section "3.2.vi Use of external Indicators (ex4 files)". See https://www.mql5.com/en/code/8677 for more details of the indicator.

At present y'all can become farther with section "3. Binary options strategy case" and build the example lawmaking past yourself or just download the code of this example below.

Optional download BinaryOptionsStrategyExample.mq4 and place it (and the compiled BinaryOptionsStrategyExample.ex4 file) into binder \Indicators ([path to your MetaTrader iv]\MQL4\Indicators):
Download the code of this Binary Options strategy case to let it run without building it past 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 push button "Compile" or but restart your MetaTrader 4 later these files are stored in the described folders and MetaTrader iv will exercise this automatically for you.


iii. Binary Options strategy instance

The following steps will guide yous 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 information technology past yourself or just download the lawmaking of the BinaryOptionsStrategyExample.mq4.

Please note:This strategy is non a profitable Binary Options strategy! Information technology is merely an example how to build a strategy in an indicator to communicate with the Binary-Options-Strategy-Tester utility. Of course yous accept to build a profitable strategy by yourself. But as you will see, this utility volition help you to test and improve your Binary Options strategy.


three.1 Define Binary Options strategy

Commencement of all we have to define the strategy and the changable values (input parameters). MQL4 documentation shows all technical indicators, which tin can be adressed over the iCustom interface: https://docs.mql4.com/indicators.

Let us say nosotros similar to create a simple Moving Average cross strategy with i "fast" and 1 "deadening" Moving Average to trade on next candle after they take crossed each other. Documentation tells, how we can become the value of a single Moving Average: https://docs.mql4.com/indicators/ima.

Allow the states further say, we like to choose values for "MA averaging menstruum" (fast and ho-hum) and for "practical price" equally 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 be set automatically. Therefore nosotros basically need the following variables for a Moving Average:

int ma_period
int ma_method
int applied_price

As we need two Moving Averages to check their crosses, we demand the post-obit input parameters for the strategy example with some default values:

int period_fast        =  v;
int period_slow        = 10;
int method_both        =0;
int applied_price_both =0;


3.ii Create Binary Options strategy

You need 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 up MetaQuotes Linguistic communication Editor (in MetaTrader iv click on "Tools" -> "MetaQuotes Language editor" or only press F4) and click on "New":

Language Editor New

The MQL Wizard will appear. Select "Custom Indicator" to create an empty indicator and click on "Next":

Language Editor Custom Indicator

Enter the name, copyright and link of the strategy besides as the input parameters with their types and default values (initial values) by clicking "Add"-Button and press "Next":

Language Editor Custom Indicator Values

On tab event handlers select checkbox "OnCalculate" every bit we demand this result to check for our strategy on every tick. Press "Adjacent":

Language Editor Custom Indicator Events

On tab drawing properties select checkbox "Indicator in seperate window" every bit nosotros need a seperate window to impress out the debug values. Printing "Finish":

Language Editor Custom Indicator Drawing Properties

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
#belongings indicator_separate_window

input int      period_fast=v;
input int      period_slow=10;
input int      method_both=0;
input int      applied_price_both=0;



int OnInit()
{

  
return(INIT_SUCCEEDED);
}



int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &fourth dimension[],
const double &open up[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{


return(rates_total);
}


iii.two.i Input parameters

The initial input parameters are created with the MQL Wizard (see 3.ii Create Binary Options strategy) and nosotros will heighten them with the post-obit steps.

To avoid to accept 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 inverse from int to blazon 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 addition comments for the input parameters are added to show the comments every bit labels instead of variable names:

...


inputint                period_fast        =5;
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 bachelor values to select as well as "labels" for the input parameters:

Binary Options Strategy Input Paremeters


iii.2.2 Include Binary-Options-Strategy-Library

If you have downloaded and stored the library (see 2. Installation) into \Include folder ([path to your MetaTrader 4]\MQL4\Include), you are able to include the library like this:






#property copyright "Copyright 2016, __martin__"
#belongings link"https://world wide web.mql5.com/en/users/__martin__"
#property version "one.00"
#property strict
#property indicator_separate_window

#include <BinaryOptionsStrategyLibrary.mqh>

...

The library will only be available like described in the case higher up if you placed it in \Include folder of your MetaTrader iv.
Changing the content of the library is not needed!

Binary-Options-Strategy-Library will heighten the input parameters with 2 new parameters:

  • Place only ane SELL or ane BUY trade per candle
  • Cheque only at the start of a new candle for the strategy

Binary Options Strategy Input Parameters Enhanced


3.2.3 Add CallStrategy()

Add together a call to CallStrategy()-function in OnCalculate() of your strategy indicator to call the strategy on every new tick. CallStrategy() is provided by Binary-Options-Strategy-Library you have inlcuded like discribed above:

...




intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &shut[],
constlong &tick_volume[],
constlong &book[],
constint &spread[])
{

CallStrategy();

render
(rates_total);
}

CallStrategy()-role in Binary-Options-Strategy-Library will call a function named CheckMyRules() in your indicator where y'all tin can identify your atmospheric condition for your Binary Options strategy.
Therefore y'all take to implement the role CheckMyRules() in your Binary Options strategy indicator.


3.2.four 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()-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        =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, 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)
{
return iMA(NULL,0,_period,0,method_both,applied_price_both,_shift);
}


3.2.5 Print out debug values

The role PrintDebugValue() privides a possibility to print out debug values while the tester is running. In the example below the values of the Moving Averages are printed out with their variable names as labels:

...


inputint                period_fast        =five;
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, i);
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,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);
}


three.two.six Use of external Indicators (ex4 files)

In addition an external indicator which stores its values in buffers can be accessed for the Binary Options strategy, fifty-fifty if but the compiled ex4-file exists.

Let usa say we like to include the signal line of the KVO indicator https://www.mql5.com/en/code/8677 to identify trades merely 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 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 button "Compile" or merely restart your MetaTrader 4 after the file is stored in the described binder and MetaTrader four will do this automatically for yous.

First nosotros have to identify the relevant buffers which stores the relevant values to access. Therefore we press the button "Data Window" in MetaTrader 4 to show all available buffers of the used indicators and drag the KVO indicator on a chart. Past hovering the cantankerous over the chart (press mouse-wheel on chart to bring upwardly the cross) the buffer values of the indicator of the hovered timeperiod will be shown in data window:

External Indicator Buffers And Values

The data window labels tells the states the second buffer value of the indicator stores the point line. If buffers of indicators did non have labels, we can notice the right one by comparing the buffer values with the displayed value under the cross in the chart and indicator. Buffers of an indicator starts with 0, so nosotros accept buffer value i = buffer 0, buffer value ii = buffer i then on and nosotros have to access buffer 1 to get the indicate value.

Side by side nosotros have to know all input parameters of the external indicator we like to admission. By draging the indicator on a chart, we see all input paremeters:

Input Parameters KVO

Let u.s.a. further say, we similar to access the indicator with (its default) values: 34, 55 and 13. Nosotros utilize a helper office (based on iCostum), wich provides us the possibility to become the values of the indicator with parameters for buffer and shift, while shift 0 volition be the value of the current candle, shift one the value of the last candle, shift 2 the value of the second to last candle and then on. In addition we temporarilly store the values of the indicator buffer and heighten the if-condition of the strategy:

...


inputint                period_fast        =five;
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);


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,ii);
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)
{
return iMA(Zilch,0,_period,0,method_both,applied_price_both,_shift);
}








double GetValuesFromIndicator__KVO__(int _buffer, int _shift=0)
{

return (
iCustom (
Nada,
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 by variables. Every bit this tutorial should be just an instance and "every bit simple as possible", this variant is non shown.


three.three The complete code

Below you lot volition find the consummate code of the Binary-Options-Strategy-Case from all the steps above, ready to elevate on the Binary-Options-Strategy-Tester to test and see the results on chart:






#property copyright "Copyright 2016, __martin__"
#property link"https://www.mql5.com/en/users/__martin__"
#property version "1.00"
#holding strict
#property indicator_separate_window

#include <BinaryOptionsStrategyLibrary.mqh>





input int                period_fast        =5;
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, ane);
double emaFast_Past = GetValueForMA(period_fast, one);

  
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,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)
  {
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
                    )
          );
  }


iv. Run a backtest (video)

The following video shows how to run a backtest of your Binary Options strategy in Strategy-Tester of MetaTrader four:

  • Commencement Binary-Options-Strategy-Tester in Strategy-Tester of MetaTrader iv 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 "common" tab
  • Elevate your used indicators with their used input parameters on the chart to see their values while tester is running (optional)
  • Salve all settings in a template to run the test with all settings once again - using the pause button of the Strategy-Tester (optional)
  • See the results of your Binary Options strategy on the Strategy-Tester chart


5. Run a forward test

To do a forward test simply drag the Binary-Options-Strategy-Tester utility and your strategy indicator on your demo or live chart of your banker instead of using it in Strategy-Tester:

  • Drag Binary-Options-Strategy-Tester utility on demo or alive chart 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 "common" tab
  • Drag your used indicators with their used input parameters on the chart to see their values while forward examination 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


half dozen. FAQ

Question: Why do you testify an case of a not profitable Binary Options strategy?
Answere: This is just an example how to build a strategy in an Indicator to communicate with the Binary-Options-Strategy-Tester utility in market place to exam and amend your strategy.

Question: Binary-Options-Strategy-Tester stops after the exact amount of losses with error "Assortment out of range". Why?
Answere: Binary-Options-Strategy-Tester can rise an mistake after 10 losses to stop Tester and to analyse the situaion on the chart. If you lot do not want to, just switch off the pick in settings.

Question: No arrows announced on chart after I draged my indicator with a working strategy on information technology. What happened?
Answere: You have to enable "Permit external expert imports" on the "mutual" tab while you drag your strategy-indicator on the chart (log message volition show an error in this case).

Question: No arrows appear on nautical chart after I draged my indicator with a working strategy on information technology with "Allow external expert imports" enabled. Why?
Answere: A strategy has to call a function of Binary-Options-Strategy-Tester to identify virtual trades. Related to the MQL4 license concept this but works if the production has a working license. Therefore y'all have to purchase the product.

Question: No arrows appear on chart subsequently I dragged my indicator with a working strategy on it and I got errors like "Cannot phone call .." or "Cannot load .." in the log of MetaTrader 4. What can I do?
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 see no results on Strategy-Tester tabs "Results", "Graph", "Report". Where I tin see the results?
Answere: Strategy-Tester of MetaTrader four 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

As I need a possibility to exam Binary Options strategies automated in Strategy-Tester of MetaTrader 4 for long time periods in a curt time and to practice foward tests on the 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 as well every bit for the documentation. Maybe in that location is a better way to do it and perhaps some improvements will bring it closer to fit the needs of you. So please experience free to contact me for ideas for improvements!

Source: https://www.mql5.com/en/articles/2820

Posted by: marchandmoroate.blogspot.com

0 Response to "fractal strategy for binary options"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel