Let's trade using computer science!

Hi traders!

If you want to burn your fingers on Binary Options trading, then do it right and use MetaTrader platform;) So, lately I did some investigation on how to connect MT4 or MT5 metatrader to a binary broker like “binary.com“. It seems there are 3 options to interface your EA with an external binary option broker:

  • 1. Using a dedicated API
  • 2. Using customized OrderSend() query
  • 3. Using a mouse control interface
I have found solution for all three possibilities but in this short example I will describe only first one, which can be added within few minutes to your EA code.


1. Connect your MT4 or MT5 EA using a dedicated API interface to your binary broker:


In order to connect you EA to binary.com broker you need to follow the following steps:
1a). Go to your API dashboard on binary.com website and get your own API token using the following link:

GET YOU API KEY HERE

binary options on MT4
1b). Write down your API token (YourApiKey)
1c). And here comes the nice part. I did all hard work for you, so only thing you need to do, to open a new trade on your binary account, is to visit the following link, with the following format:

BUY ORDER:
https://fx.coensio.com/nodejs/coensio_trade_bo.php?cmd=YourApiKey|Symbol|BettingValue|ExpireTimeInMinutes|CALL|MaxContractPrice
Example:
https://fx.coensio.com/nodejs/coensio_trade_bo.php?cmd=shNiLECJ8TqJu|EURUSD|10|1|CALL|5.72

SELL ORDER:
https://fx.coensio.com/nodejs/coensio_trade_bo.php?cmd=YourApiKey|Symbol|BettingValue|ExpireTimeInMinutes|PUT|MaxContractPrice
Example:
https://fx.coensio.com/nodejs/coensio_trade_bo.php?cmd=shNiLECJ8TqJu|EURUSD|10|1|CALL|5.72

Note that the last parameter “MaxContractPrice” is used to exacute contracts or binary option orders only with a defined “PayOut” rate. In this example the contract price is limited to $5.72. With a “BettingValue” equal to $10, this results in: ($10-$5.72)/$5.72=0.75 or 75% payout rate. And in order to be profitable with your binary option trading you do not want to take orders with a payout rate lower than 75%!

That’s it!

But there is more: having an url based interface we can easily execute trades directly from our MT4 or MT5 EA code. This because MT4 and MT5 allow external URL calls. Below an example of EA that can automatically open binary option positions from the MQL code.

//+------------------------------------------------------------------+
//|                                     CoensioBinaryOptionEaV01.mq4 |
//|                                         © Copyright 2017 Coensio |
//|                                           https://www.coensio.com |
//+------------------------------------------------------------------+
#property copyright "© 2017 Coensio.com"
#property link      "https://www.coensio.com"
#define VERSION "1.00"
#property version VERSION

input string      ReadMoreAt           = "https://www.coensio.com/wp/trade-binary-options-with-mt4/"; 
input string      TRDE                 = "==== Trading Settings ===="; 
input string      ApiKey               = "Your API Key";
input int         BettingAmount        = 10;
input int         ExpirationMinutes    = 5;
input double      MaxContractPrice     = 5.72;
input string      Url                  = "https://fx.coensio.com/nodejs/coensio_trade_bo.php?cmd=";
input bool        SendTestTradeOnInit  = false;

//Web request params
string            Cookie=NULL,Headers;
char              Post[],Result[];
int               Timeout              = 300000;
int               Res;
string            TxCmd                = "";

int OnInit()
{

   if(SendTestTradeOnInit)
   {
      //Format: https://fx.coensio.com/nodejs/coensio_trade_bo.php?cmd=ishNiLECJ8TqJuY|Symbol|BettingAmount|ExpirationMinutes|PUT or CALL|MaxContractPrice
      TxCmd=ApiKey+"|"+Symbol()+"|"+IntegerToString(BettingAmount)+"|"+IntegerToString(ExpirationMinutes)+"|PUT|"+DoubleToString(MaxContractPrice,2);
      Res=WebRequest("GET",Url+TxCmd,Cookie,NULL,Timeout,Post,0,Result,Headers);
      Alert("Remote Trade: ",Url+TxCmd);        
   }
   Alert("Read more at: https://www.coensio.com/wp/trade-binary-options-with-mt4/");
   return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason)
{

   
}

void OnTick()
{
   /*
   
   //Go Long
   if(your BUY entry condition == true) 
   {
      //Request: https://fx.coensio.com/nodejs/coensio_trade_bo.php?cmd=ishNiLECJ8TqJuY|Symbol|BettingAmount|ExpirationMinutes|CALL|MaxContractPrice
      TxCmd=ApiKey+"|"+Symbol()+"|"+IntegerToString(BettingAmount)+"|"+IntegerToString(ExpirationMinutes)+"|CALL|"+DoubleToString(MaxContractPrice,2);
      Res=WebRequest("GET",Url+TxCmd,Cookie,NULL,Timeout,Post,0,Result,Headers);   
   }
   //Go Long
   if(your SELL entry condition == true)
   {
      //Request: https://fx.coensio.com/nodejs/coensio_trade_bo.php?cmd=ishNiLECJ8TqJuY|Symbol|BettingAmount|ExpirationMinutes|PUT|MaxContractPrice
      TxCmd=ApiKey+"|"+Symbol()+"|"+IntegerToString(BettingAmount)+"|"+IntegerToString(ExpirationMinutes)+"|PUT|"+DoubleToString(MaxContractPrice,2);
      Res=WebRequest("GET",Url+TxCmd,Cookie,NULL,Timeout,Post,0,Result,Headers);   
   }
   
   */
}

*** IMPORTANT ***
Before you can run external URL calls you need to add my server to allowed URLs in MT4/MT5 options. To do so, go to Tools->Options on your MT4/MT5 window and add my server to allow URLs:
binary options on MT4
You can download the source code for MT4 or MT5 platform using the links below:

BinaryOptionEa for MT4
BinaryOptionEa for MT5



2. Interface MT4 or MT5 EA using customized binary options OrderSend() function


The second best way to interface your EA with a binary broker is by selecting a broker which already provides possibility to open binary trades from withn the MQL code. Two examples of brokrs that are supporting MT4 platform, are:
DirectFx
GoMarkets


Both brokers provide a simple way of executing Binary Orders using customized OrderSend() function as show below:

if(Direction=="BUY")
Ticket = OrderSend(Symb, OP_BUY, BettingAmount, 0, 0, 0, 0, "BO exp:"+DoubleToString(ExpTimeMin*60,0), MagicNr, 0, clrBlue); 
if(Direction=="SELL")
Ticket = OrderSend(Symb, OP_SELL, BettingAmount, 0, 0, 0, 0, "BO exp:"+DoubleToString(ExpTimeMin*60,0), MagicNr, 0, clrRed); 

Where "BettingAmount" is the value of your bet and "ExpTimeMin" is the expiration time in minutes.


3. Interface MT4 or MT5 EA with your binary broker using a mouse click function


Many people do not know that it is possible to execute mouse clicks on specified X/Y locations from the MQL code. In this way it is possible to "click" on an external button, e.g.: on a website of a binary broker and so to control your binary trades using logic directly from the EA code. This smart mechanism opens doors to many different brokers that do not provide MT4 or MT5 trading platform for binary options. This is a complex solution and for now, I've decided not to share my source-code for free. If you are interested in this option just contact me on my email.
Metatrader to mouse interface



If you have any questions about this or other two possibilities to integrate your binary option trading with metatrader or just like this post please let me know and leave your comment!
If you need any help with EA coding please visit my EA coding service page: HERE

Greets,
Chris  

8 Responses to How to trade binary options with mt4

  • Hello Chris.

    First of all, I’m sorry about my awful level of English.
    I need your help. I’m operating with binary options with a real account through the SMFX broker.
    When I open a DOWN option with the ticket = OrderSend(miSymbol, OP_SELL, 1, 0, 0, 0, 0, “BO exp:300”, miMagic, 0, clrRed), the program opens it correctly at the BID price of that moment.
    However, if I open an UP option with the ticket = OrderSend(miSymbol, OP_BUY, 1, 0, 0, 0, 0, “BO exp:300”, miMagic, 0, clrGreen), the program opens it at the ASK price of that moment. I contacted the broker in order to require him a solution for this problem but he told me that it should be a mistake of my EA programming.
    Since then, I’ve tried to open multiple price values BID, Close[0], NULL, but the program always opens the option at the ASK price.
    If I open manually the option through the FXLite interface, the broker price is the correct price (BID).
    Would you know how to solve this problem?

    Thank you for your atention in advance.

    Kind regards from El Campello, Alicante (Spain).

    Contact number: Francisco Vela (+34 678069418).

    • Hi,
      I am using the very same format, with no problems at all:

      Ticket = OrderSend(Symb, OP_BUY, BettingAmount, 0, 0, 0, 0, “BO exp:”+DoubleToString(ExpTimeMin*60,0), MagicNr, 0, clrBlue);

      I do not see anything strange. It should work properly.

      Greets,
      Chris

  • Hi Chris,
    This is interesting, thanks. Is there any way to test your interface with a binary.com virtual account? I’m assuming your application automatically looks for the real money account associated with that API key and then executes the trade on that account?

  • use in iqoption.?

  • thank you
    Does it execute signals. Indicator. On broker binary?

    • Hi,

      Yes I do have a professional version of this Ea for binary brokers. Price is €200/year. Binary version includes also possibility to backtest and optimize binary strategies.

      Gr
      Chris

Leave a Reply to tameur Cancel reply

Your email address will not be published. Required fields are marked *

Short about me

Welcome to my Blog!

My name is Chris, I'm a Dutch engineer with Polish roots. By day I'm an engineer, forex trader and an internet entrepreneur, and by night I'm fighting internet crime;) I hope you will enjoy my website and my free MT4 software. Do not forget to check out my blog.
B.t.w: 'coensio' (Latin) = assessing, assessment, census, estimating, opinion, rating, taxing.

StrategyQuant with discount!
Ads
ArrowHunterEA project
Coensio MT4 Charts
Follow me on Facebook!
My newsletter

Subscribe to my newsletter

Ads