banner



no touch binary options strategy

Table of Contents

i. Introduction
ii. Installation
three. Binary Options strategy example
3.1. Define Binary Options strategy
3.two. Create Binary Options strategy
3.2.1. Input parameters
3.ii.2. 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.ii.half-dozen. Use of external Indicators (ex4 files)
3.three. The complete code
4. Run a backtest (video)
5. Run a forward test
6. FAQ
7. Miscellaneous


1. Introduction

This article shows how to build a Binary Options strategy and test it in Strategy-Tester of Metatrader 4 with Binary-Options-Strategy-Tester utility. By default Strategy-Tester of Metatrader 4 can examination Expert Advisors and Indicators against historical data, but it cannot handle Binary Options with expire times. As I need a possibility to examination Binary Options strategies automatic 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:

Binary Options Strategy Tester Concept

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

Please keep in mind: Backtesting with historical data will never represent the existent future, but it might give you an gauge value to go your strategy more than stable.
The quality of your backtest volition depends on your historical data. Therefore it is strongly recommended to use a set 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 4.

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 identify the virtual trades. Related to the license concept of MQL4 this just works if the product has a working license. Therefore y'all have to purchase the product to test Binary Options strategies or this example.

Download free BinaryOptionsStrategyLibrary.mqh and place it in into binder \Include ([path to your MetaTrader 4]\MQL4\Include):
The free library will provide several functions to build your Binary Options strategy easily and to communicate with the Binary-Options-Strategy-Tester. Encounter Binary-Options-Strategy-Library for more than 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 as an case to show the admission of external indicators and in that location ex4 files in section "3.2.6 Employ of external Indicators (ex4 files)". Run into https://www.mql5.com/en/code/8677 for more details of the indicator.

Now you can go farther with section "iii. Binary options strategy instance" 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 4]\MQL4\Indicators):
Download the code of this Binary Options strategy instance to permit it run without building it by yourself.

To compile the needed .ex4 files open the .mq4 files (KVO.mq4 and BinaryOptionsStrategyExample.mq4 - NOT Binary-Options-Strategy-Library.mqh) in MetaQuotes Language Editor and click on button "Compile" or simply restart your MetaTrader iv after these files are stored in the described folders and MetaTrader 4 will exercise this automatically for you.


3. Binary Options strategy case

The following steps will guide you throgh an instance how to build an instance Binary Options strategy stored in an Indicator to communicate with Binary-Options-Strategy-Tester. You can build information technology by yourself or simply download the code of the BinaryOptionsStrategyExample.mq4.

Please note:This strategy is non a profitable Binary Options strategy! It is only an case how to build a strategy in an indicator to communicate with the Binary-Options-Strategy-Tester utility. Of course yous have to build a assisting strategy past yourself. Merely as you will see, this utility will aid you to test and improve your Binary Options strategy.


three.ane 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 tin can be adressed over the iCustom interface: https://docs.mql4.com/indicators.

Allow us say we like to create a simple Moving Average cross strategy with one "fast" and 1 "slow" Moving Average to merchandise on next candle after they accept crossed each other. Documentation tells, how we can get the value of a single Moving Average: https://docs.mql4.com/indicators/ima.

Permit u.s.a. further say, nosotros like to choose values for "MA averaging period" (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 (east.g. the symbol the tester runs on) and should exist set automatically. Therefore we basically need the following variables for a Moving Boilerplate:

int ma_period
int ma_method
int applied_price

Every bit nosotros demand two Moving Averages to check their crosses, we need the following 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;


3.two 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 MetaQuotes Linguistic communication Editor (in MetaTrader 4 click on "Tools" -> "MetaQuotes Linguistic communication editor" or simply press F4) and click on "New":

Language Editor New

The MQL Sorcerer will announced. Select "Custom Indicator" to create an empty indicator and click on "Side by side":

Language Editor Custom Indicator

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

Language Editor Custom Indicator Values

On tab event handlers select checkbox "OnCalculate" as we demand this event to check for our strategy on every tick. Printing "Next":

Language Editor Custom Indicator Events

On tab drawing properties select checkbox "Indicator in seperate window" every bit we need a seperate window to print out the debug values. Press "Stop":

Language Editor Custom Indicator Drawing Properties

The initial code of your indicator will announced:






#belongings 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=5;
input int      period_slow=ten;
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 &time[],
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);
}


3.2.1 Input parameters

The initial input parameters are created with the MQL Wizard (meet iii.2 Create Binary Options strategy) and we will enhance them with the following steps.

To avoid to have to enter int-values for practical 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 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 testify the comments equally labels instead of variable names:

...


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

Binary Options Strategy Input Paremeters


iii.2.2 Include Binary-Options-Strategy-Library

If yous 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__"
#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 simply be available like described in the case to a higher place if you placed it in \Include folder of your MetaTrader iv.
Irresolute the content of the library is not needed!

Binary-Options-Strategy-Library will enhance the input parameters with two new parameters:

  • Place simply ane SELL or 1 Buy merchandise per candle
  • Check only at the showtime 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 yous take inlcuded similar discribed above:

...




intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &fourth dimension[],
constdouble &open[],
constdouble &loftier[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{

CallStrategy();

render
(rates_total);
}

CallStrategy()-function in Binary-Options-Strategy-Library will call a part named CheckMyRules() in your indicator where yous tin can place your weather for your Binary Options strategy.
Therefore yous have to implement the office CheckMyRules() in your Binary Options strategy indicator.


three.2.4 Implement CheckMyRules() and helper-function

In CheckMyRules()-part, which is called through the Binary-Options-Strategy-Library, the conditions 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        =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);

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.five Print out debug values

The function PrintDebugValue() privides a possibility to impress out debug values while the tester is running. In the case below the values of the Moving Averages are printed out with their variable names every bit labels:

...


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, 1);
double emaFast_Past = GetValueForMA(period_fast, ane);

PrintDebugValue("emaSlow_Current: ",(cord)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)
{
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.6 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, even if just the compiled ex4-file exists.

Permit us say we like to include the signal line of the KVO indicator https://www.mql5.com/en/code/8677 to place trades only if the signal 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 four]\MQL4\Indicators\Downloads).

To compile the needed .ex4 file open KVO.mq4 in MetaQuotes Linguistic communication Editor and click on push "Compile" or but restart your MetaTrader iv after the file is stored in the described folder and MetaTrader four will do this automatically for you lot.

Showtime we have to place the relevant buffers which stores the relevant values to access. Therefore nosotros press the push "Data Window" in MetaTrader 4 to testify 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 data window:

External Indicator Buffers And Values

The data window labels tells us the second buffer value of the indicator stores the signal line. If buffers of indicators did not take labels, nosotros can find the correct ane 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 take buffer value 1 = buffer 0, buffer value 2 = buffer 1 and then on and we have to access buffer ane to get the indicate value.

Adjacent nosotros have to know all input parameters of the external indicator we like to access. By draging the indicator on a chart, we encounter all input paremeters:

Input Parameters KVO

Let the states further say, nosotros like to access the indicator with (its default) values: 34, 55 and 13. We use a helper function (based on iCostum), wich provides the states the possibility to become the values of the indicator with parameters for buffer and shift, while shift 0 will be the value of the current candle, shift 1 the value of the concluding candle, shift two the value of the second to final candle then on. In addition we temporarilly shop 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: ",(string)emaSlow_Current,0);
PrintDebugValue("emaFast_Current: ",(string)emaFast_Current,1);
PrintDebugValue("emaSlow_Past: ",(string)emaSlow_Past,ii);
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)
{
render iMA(Aught,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
)
);

}

Information technology 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 by variables. As this tutorial should be just an example and "as uncomplicated as possible", this variant is not shown.


3.3 The consummate code

Below you will detect the complete lawmaking of the Binary-Options-Strategy-Example 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 "1.00"
#property strict
#holding 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()
  {


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[])
  {

   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, 1);

  
double kvoSignal = GetValuesFromIndicator__KVO__(1,0);

      PrintDebugValue("emaSlow_Current: ",(string)emaSlow_Current,0);
   PrintDebugValue("emaFast_Current: ",(string)emaFast_Current,ane);
   PrintDebugValue("emaSlow_Past: ",(string)emaSlow_Past,ii);
   PrintDebugValue("emaFast_Past: ",(cord)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(Naught,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
                    )
          );
  }


4. 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 4 and set the input parameters
  • Drag your Binary Options strategy indicator on the nautical chart, set the input parameters and check "Let 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)
  • Salvage all settings in a template to run the exam 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 nautical chart


5. Run a forward test

To do a forward exam simply drag the Binary-Options-Strategy-Tester utility and your strategy indicator on your demo or alive chart of your banker 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, gear up the input parameters and check "Let external expert imports" on the "common" tab
  • Drag your used indicators with their used input parameters on the nautical chart to see their values while forward examination is running (optional)
  • Save all settings in a template to run the exam again with all settings (optional)
  • Come across the results of your Binary Options strategy on demo or live nautical chart


6. FAQ

Question: Why do you show an instance of a non 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 examination and improve your strategy.

Question: Binary-Options-Strategy-Tester stops after the exact corporeality of losses with error "Array out of range". Why?
Answere: Binary-Options-Strategy-Tester can rise an mistake after ten losses to stop Tester and to analyse the situaion on the chart. If yous do not want to, just switch off the choice in settings.

Question: No arrows appear on chart subsequently I draged my indicator with a working strategy on information technology. What happened?
Answere: Y'all have to enable "Allow external practiced imports" on the "common" tab while you drag your strategy-indicator on the nautical chart (log message will show an error in this instance).

Question: No arrows appear on chart after I draged my indicator with a working strategy on it with "Let external practiced imports" enabled. Why?
Answere: A strategy has to phone call a function of Binary-Options-Strategy-Tester to place virtual trades. Related to the MQL4 license concept this but works if the production has a working license. Therefore you have 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 like "Cannot call .." or "Cannot load .." in the log of MetaTrader 4. What can I exercise?
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 come across no results on Strategy-Tester tabs "Results", "Graph", "Report". Where I can see the results?
Answere: Strategy-Tester of MetaTrader iv can non handle Binary Options and so these tabs con non be used. Therefore this utility calculates all wins and losses and prints the results on the chart.


7. Miscellaneous

As I demand a possibility to examination Binary Options strategies automated in Strategy-Tester of MetaTrader 4 for long time periods in a brusk fourth dimension and to do foward tests on the chart of the broker, this utility was build. I have spent a lot of time for the concept and the implementation of the Binary-Options-Strategy-Tester as well as for the documentation. Maybe at that place is a ameliorate way to do it and maybe some improvements volition bring it closer to fit the needs of you. Then please feel gratis to contact me for ideas for improvements!

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

Posted by: carpiosamissing.blogspot.com

0 Response to "no touch binary options strategy"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel