banner



binary options stop loss strategy

Contents

1. First appearance
2. Installation
3. Binary Options strategy case
3.1. Define Positional representation system Options scheme
3.2. Create Binary Options scheme
3.2.1. Stimulation parameters
3.2.2. Include Positional notation-Options-Scheme-Library
3.2.3. Add u CallStrategy()
3.2.4. Implement CheckMyRules() and helper-function
3.2.5. Print taboo debug values
3.2.6. Use of external Indicators (ex4 files)
3.3. The complete code
4. Outpouring a backtest (video)
5. Bleed a forward try
6. FAQ
7. Mixed


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 public utility. By default Strategy-Quizzer of Metatrader 4 can test Expert Advisors and Indicators against diachronic information, but it cannot handle Binary Options with expire times. As I need a possibility to test Binary Options strategies automated in Scheme-Tester of MetaTrader 4, the Binary-Options-Strategy-Tester was build as a utility to jibe those necessarily.

The concept contains the following parts:

Binary Options Strategy Tester Concept

This is a bit by bit example how to build a Binary Options strategy stored in an Indicator (marked as red in image higher up) to communicate through Positional notation-Options-Scheme-Library (marked equally green in image higher up) with the Positional representation system-Options-Strategy-Examiner (marked as blue-blooded in image to a higher place), to office virtual orders and matter their results with backtests and forward tests.

Delight living in mind: Backtesting with historical data will never represent the very future, but it mightiness give you an approximate valuate to get your strategy more constant.
The quality of your backtest will depends on your historical data. Hence it is powerfully recommended to use a rigid of hight quality data!


2. Installation

Download and purchase Binary star-Options-Scheme-Quizzer public utility from marketplace:
Test-Framework to examine Binary Options strategies in Strategy-Tester of MetaTrader 4.

Wherefore a purchased adaptation of Binary-Options-Strategy-Examiner utility is needed?
A Binary-Options scheme has to predict a function of the Binary-Options-Strategy-Tester (via Binary-Options-Strategy-Library) to place the practical trades. Related to the license concept of MQL4 this only works if the product has a working permit. Therefore you have to purchase the product to test Binary Options strategies or this lesson.

Download free BinaryOptionsStrategyLibrary.mqh and place it in into brochure \Let in ([path to your MetaTrader 4]\MQL4\Let in):
The free library will provide several functions to build your Binary Options scheme easily and to communicate with the Binary star-Options-Strategy-Tester. See Binary-Options-Strategy-Program library for many details of the subroutine library.

Download complimentary KVO.mq4 index number and set down it (and the compiled KVO.ex4 file) into pamphlet \Indicators\Downloads ([path to your MetaTrader 4]\MQL4\Indicators\Downloads):
The KVO index number is used as an example to show the entree of outward indicators and there ex4 files in surgical incision "3.2.6 Use of extrinsic Indicators (ex4 files)". See https://www.mql5.com/en/code/8677 for more inside information of the indicator.

At present you can go further with section "3. Binary options strategy example" and habitus 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 leaflet \Indicators ([path to your MetaTrader 4]\MQL4\Indicators):
Download the code of this Binary Options strategy example to let 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 in chief and click on release "Compile" or just re-start your MetaTrader 4 later these files are stored in the delineate folders and MetaTrader 4 leave do this automatically for you.


3. Binary Options strategy example

The pursuing stairs will guide you throgh an exemplar how to build an example Binary Options scheme stored in an Indicator to transmit with Positional notation-Options-Scheme-Tester. You can physique it away yourself Beaver State impartial download the code of the BinaryOptionsStrategyExample.mq4.

Please note:This strategy is not a profitable Binary Options scheme! It is just an example how to build a strategy in an indicator to communicate with the Binary star-Options-Scheme-Tester utility. Naturally you hold to build a profitable strategy by yourself. But as you will see, this utility will help you to test and better your Binary Options strategy.


3.1 Define Binary Options strategy

Start of whol 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 port: https://docs.mql4.com/indicators.

Lease us say we like to create a simple Moving Normal cross strategy with one "fast" and one "slow" Moving Average to trade on next candela after they have intersecting each other. Corroboration tells, how we tooshie get the value of a lone Moving Average: https://docs.mql4.com/indicators/ima.

Let us advance say, we like to prefer values for "MA averaging period" (expedited and slow) and for "applied price" as healthy as for the "averaging method acting". Other values (care symbolisation, timeframe and shift) depends on the testcase (e.g. the symbolic representation the tester runs on) and should be set automatically. Thence we 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 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.2 Create Multiple Options strategy

You need to build up an indicator which stores your Positional notation Options strategy to drag it on the chart where Positional notation-Options-Strategy-Quizzer is running on.

Open MetaQuotes Language Editor program (in MetaTrader 4 click on "Tools" -> "MetaQuotes Language editor" or just 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 "Following":

Language Editor Custom Indicator

Enter the name, copyright and link of the strategy equally well as the input parameters with their types and nonpayment values (initial values) by clicking "Add"-Release and press "Next":

Language Editor Custom Indicator Values

On tab outcome handlers blue-ribbon checkbox "OnCalculate" as we need this event to check for our strategy on every tick. Press "Following":

Language Editor Custom Indicator Events

On tab key drawing properties select checkbox "Indicator in seperate windowpane" as we penury a seperate window to print out the debug values. Press "Ending":

Language Editor Custom Indicator Drawing Properties

The initial cypher of your indicator will appear:






#property right of first publication "Copyright 2016, __martin__"
#property link"https://www.mql5.com/en/users/__martin__"
#property translation "1.00"
#attribute strict
#property indicator_separate_window

stimulus int      period_fast=5;
input int      period_slow=10;
stimulus int      method_both=0;
stimulant int      applied_price_both=0;



int OnInit()
{

  
return(INIT_SUCCEEDED);
}



int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &metre[],
const double &adenosine monophosphate;open[],
const double &high[],
const double &low[],
const big &close[],
const long &tick_volume[],
const long &adenosine monophosphate;volume[],
const int &adenylic acid;spread head[])
{


return(rates_total);
}


3.2.1 Input parameters

The initial input parameters are created with the MQL Wizard (see 3.2 Create Multiple 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 metamorphic from int to typecast of reckoning with a nonpayment valuate.

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 plus comments for the stimulant parameters are added to show the comments as labels instead of variable name calling:

...


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 available values to select as advisable as "labels" for the input parameters:

Binary Options Strategy Input Paremeters


3.2.2 Admit Binary-Options-Strategy-Library

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






#property copyright "Copyright 2016, __martin__"
#property link up"https://www.mql5.com/en/users/__martin__"
#property edition "1.00"
#dimension austere
#property indicator_separate_window

#admit <BinaryOptionsStrategyLibrary.mqh>

...

The library will exclusively be available similar described in the example above if you arranged information technology in \Let in folder of your MetaTrader 4.
Changing the calm of the depository library is not needed!

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

  • Place exclusively ane SELL or one BUY trade per candle
  • Discipline lone at the beginning of a new candle for the strategy

Binary Options Strategy Input Parameters Enhanced


3.2.3 Add CallStrategy()

Add a call to CallStrategy()-social function in OnCalculate() of your strategy indicant to call the scheme on every new tick. CallStrategy() is provided aside Positional representation system-Options-Strategy-Library you have inlcuded like discribed above:

...




intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &A;meter[],
constdouble up &adenosine monophosphate;vulnerable[],
constdouble &high[],
constduplicate &low[],
constdouble &adenylic acid;close[],
constmindful &adenylic acid;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 can post your conditions for your Binary Options strategy.
Therefore you have to implement the function CheckMyRules() in your Binary Options strategy index.


3.2.4 Implement CheckMyRules() and helper-function

In CheckMyRules()-function, which is called direct the Binary-Options-Strategy-Library, the conditions for the strategy are implemented and trades are placed through PlaceTrade()-function of the library. Values of some 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.5 Print out debug values

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

...


inputint                period_fast        =5;
inputint                period_slow        =10;
inputENUM_MA_METHOD     method_both        = MODE_SMA;
stimulationENUM_APPLIED_PRICE applied_price_both = PRICE_CLOSE;

...









avoid 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: ",(draw)emaFast_Current,1);
PrintDebugValue("emaSlow_Past: ",(string)emaSlow_Past,2);
PrintDebugValue("emaFast_Past: ",(string)emaFast_Past,3);

if(emaFast_Past > emaSlow_Past
&&adenylic acid; emaFast_Current < emaSlow_Past)
{
PlaceTrade(OP_SELL);
}

if(emaFast_Past < emaSlow_Past
&& emaFast_Current > emaSlow_Past)
{
PlaceTrade(OP_BUY);
}

     }





two-baser 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 dismiss be accessed for the Binary Options scheme, flat if single the compiled ex4-file exists.

Let us enunciat we like to let in the signal line of the KVO index number 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 position the compiled (ex4 file) into booklet \Indicators\Downloads ([path to your MetaTrader 4]\MQL4\Indicators\Downloads).

To compile the needed .ex4 file open KVO.mq4 in MetaQuotes Terminology Editor and sink in on button "Compile" or sportsmanlike restart your MetaTrader 4 after the Indian file is stored in the described folder and MetaTrader 4 will act up this automatically for you.

First we give birth to describe the relevant buffers which stores the relevant values to entree. Therefore we squeeze the button "Data Window" in MetaTrader 4 to show wholly easy buffers of the used indicators and drag the KVO indicator on a chart. By hovering the cross over the chart (press mouse-wheel along chart to bring up the cross) the soften values of the indicator of the hovered timeperiod will be shown in data window:

External Indicator Buffers And Values

The data window labels tells us the forward cowcatcher economic value of the index number stores the signal line. If buffers of indicators did not have labels, we can find the right unity by comparing the buffer values with the displayed note value under the cross in the chart and indicator. Buffers of an indicator starts with 0, and so we have buffer value 1 = pilo 0, buff value 2 = buffer store 1 so on and we feature to approach buffer 1 to get the signal value.

Close we ingest to know all input parameters of the external indicator we like to access. By draging the indicator on a graph, we see complete input paremeters:

Input Parameters KVO

LET U.S.A advance articulate, we suchlike to memory access the indicator with (its default) values: 34, 55 and 13. We use a helper function (founded on iCostum), wich provides U.S.A the possible action to draw the values of the index number with parameters for buffer and shift, while shift 0 will be the value of the current candle, shift 1 the value of the last candle, shift 2 the value of the second to last candle and so on. In summation we temporarilly store the values of the index number cushion and enhance the if-discipline of the strategy:

...


stimulantint                period_fast        =5;
inputint                period_slow        =10;
inputENUM_MA_METHOD     method_both        = MODE_SMA;
inputENUM_APPLIED_PRICE applied_price_both = PRICE_CLOSE;

...









void CheckMyRules()
{



forked 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);


doubly kvoSignal = GetValuesFromIndicator__KVO__(1,0);

   PrintDebugValue("emaSlow_Current: ",(string)emaSlow_Current,0);
PrintDebugValue("emaFast_Current: ",(string)emaFast_Current,1);
PrintDebugValue("emaSlow_Past: ",(cosmic string)emaSlow_Past,2);
PrintDebugValue("emaFast_Past: ",(string along)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)
{
give back iMA(Aught,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 signal parameters of our scheme indicator with the values for the utilized KVO indicator and set the values in helper function by variables. As this tutorial should be just an example and "as simple as possible", this variant is not shown.


3.3 The gross code

Below you will find the complete code of the Positional representation system-Options-Strategy-Example from all the stairs above, ready to drag on the Binary-Options-Strategy-Tester to test and see the results connected chart:






#property right of first publication "Copyright 2016, __martin__"
#property link"https://www.mql5.com/en/users/__martin__"
#material possession version "1.00"
#property self-restraining
#property indicator_separate_window

#include <BinaryOptionsStrategyLibrary.mqh>





stimulation int                period_fast        =5;
input signal int                period_slow        = 10;
stimulation ENUM_MA_METHOD     method_both        = MODE_SMA;
input ENUM_APPLIED_PRICE applied_price_both = PRICE_CLOSE;




int OnInit()
  {


turn back(INIT_SUCCEEDED);
  }




int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &sentence[],
const double &open[],
const large &high[],
const image &A;low[],
const ambiguous &finale[],
const long &tick_volume[],
const long &volume[],
const int &cattle farm[])
  {

   CallStrategy();


generate(rates_total);
  }









void CheckMyRules()
  {

  

double emaSlow_Current = GetValueForMA(period_slow, 0);
double emaFast_Current = GetValueForMA(period_fast, 0);



replicate emaSlow_Past = GetValueForMA(period_slow, 1);
double emaFast_Past = GetValueForMA(period_fast, 1);

  
double kvoSignal = GetValuesFromIndicator__KVO__(1,0);

      PrintDebugValue("emaSlow_Current: ",(drawstring)emaSlow_Current,0);
   PrintDebugValue("emaFast_Current: ",(drawing string)emaFast_Current,1);
   PrintDebugValue("emaSlow_Past: ",(string)emaSlow_Past,2);
   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
   &&A; kvoSignal > 0)
     {
      PlaceTrade(OP_BUY);
     }

    }





double GetValueForMA(int _period,int _shift)
  {
restitution 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
                    )
          );
  }


4. Run a backtest (video)

The pursuing video shows how to run a backtest of your Multiple Options strategy in Strategy-Examiner of MetaTrader 4:

  • Start Binary-Options-Scheme-Tester in Strategy-Tester of MetaTrader 4 and put over the input parameters
  • Drag your Binary Options strategy indicator along the graph, set the input parameters and check "Allow international skilful imports" on the "common" tab
  • Drag your used indicators with their ill-used input parameters on the graph to see their values while examiner is running (optional)
  • Pull through all settings in a guide to run the run with all settings again - using the pause release of the Scheme-Tester (optional)
  • See the results of your Binary star Options scheme on the Strategy-Tester chart


5. Take to the woods a forward try out

To do a forward test simply drag the Binary-Options-Strategy-Tester utility and your scheme indicator on your demo or live graph of your broker instead of exploitation it in Strategy-Tester:

  • Drag Binary-Options-Strategy-Quizzer utility along demo operating theater live graph and primed the input parameters
  • Drag your Binary Options strategy indicator on the chart, set the input parameters and look into "Allow external expert imports" along the "common" lozenge
  • Drag your used indicators with their in use stimulation parameters on the chart to take in their values while forward test is operative (optional)
  • Economize all settings in a template to run the test again with all settings (optional)
  • See the results of your Binary Options strategy on demonstration or live chart


6. FAQ

Interrogative: Wherefore answer you show an example of a non profitable Binary Options strategy?
Answere: This is just an example how to build a strategy in an Indicator to convey with the Binary-Options-Strategy-Tester utility in mart to test and meliorate your scheme.

Question: Binary-Options-Strategy-Tester stops after the right amount of losses with computer error "Array unfashionable of range". Why?
Answere: Binary star-Options-Strategy-Quizzer can rise an error after x losings to stop Tester and to psychoanalyse the situaion on the chart. If you execute not want to, just switch remove the option in settings.

Question: None arrows appear on graph afterwards I draged my indicator with a working strategy on that. What happened?
Answere: You have to enable "Take into account external expert imports" on the "common" tab while you sweep up your scheme-indicator happening the chart (log up message will show an error in this case).

Question: No arrows appear connected chart after I draged my indicator with a working strategy on it with "Set aside external skilled imports" enabled. Why?
Answere: A scheme has to call a subroutine of Binary-Options-Strategy-Examiner to place virtual trades. Attendant the MQL4 license concept this exclusively works if the product has a working permit. Therefore you cause to purchase the mathematical product.

Question: No arrows appear on chart after 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 behave?
Answere: Consumption the latest version (greater v1.00) of BinaryOptionsStrategyLibrary.mqh. Check version tag in code of your BinaryOptionsStrategyLibrary.mqh and see changelog v1.01 of BinaryOptionsStrategyLibrary.

Query: I find no results along Strategy-Tester tabs "Results", "Graph", "Report". Where I can see the results?
Answere: Strategy-Tester of MetaTrader 4 can not handle Positional notation Options so these tabs con non constitute misused. Therefore this utility calculates all wins and losings and prints the results on the chart.


7. Heterogenous

Equally I need a possibility to test Binary Options strategies machine-controlled in Strategy-Tester of MetaTrader 4 for long time periods in a short time and to practise foward tests on the chart of the broker, this utility was build. I have spent a lot of prison term for the construct and the implementation of the Binary-Options-Strategy-Examiner as comfortably arsenic for the documentation. Maybe there is a better way to execute IT and maybe close to improvements will fetch IT closer to fit the needs of you. So please tactile property free to get hold of me for ideas for improvements!

binary options stop loss strategy

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

Posted by: normantione2000.blogspot.com

0 Response to "binary options stop loss strategy"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel