Dasar pembuatan Robot forex tranding atau yang kita kenal dengan EA (Expert Advisors) sebenarnya sangat mudah. Sebagai pemula kita di tuntut mengenal dasar dasar bagaimana kita membuat robot forex .
Berikut cara membuat robot forex bagi pemula :
Pertama, buka Meta Editor, File - New , lalu muncul gambar berikut ini:
Klik Next terus, ikuti saja apa maunya, sampai muncul code begini:
//+------------------------------------------------------------------+
//| Nayla_Author.mq4 |
//| Copyright 2016 @ forexxxu.blogspot.co.id|
//| http://forexxxu.blogspot.co.id|
//+------------------------------------------------------------------+
#property copyright "Copyright 2016 @ forexxxu.blogspot.co.id"
#property link "http://forexxxu.blogspot.co.id"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
}
//+------------------------------------------------------------------+
//| Nayla_Author.mq4 |
//| Copyright 2016 @ forexxxu.blogspot.co.id|
//| http://forexxxu.blogspot.co.id|
//+------------------------------------------------------------------+
#property copyright "Copyright 2016 @ forexxxu.blogspot.co.id"
#property link "http://forexxxu.blogspot.co.id"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
}
//+------------------------------------------------------------------+
Dari sini kita telah selesai membuat template awal, atau kerangka dasar, atau apalah istilahnya itu. Sekarang tinggal memasukkan perintah-perintah supaya robotnya bisa berjalan.
Kita gunakan indikator MA saja ya, untuk percobaan, karena gampang. Rumusnya logikanya begini:
- Jika Ask price diatas MA periode 14, maka Buy.
- Jika Bid price dibawah MA periode 14, maka Sell.
- Input Lot = 0.1 , SL 20 pip dan TP 20 pip.
Pertama kita tuliskan dulu kode inputnya, kodenya begini:
input double Lot = 0.1;
input int TP = 200;
input int SL = 200;
input int TP = 200;
input int SL = 200;
kode diatas kita tempatkan tepat dibawah #property sebelum int OnInit()
Secara default nilai 20 pip itu ditulis 200, dan ini belum bisa membedakan antara 4 dan 5 digit. Nanti saja kita beri kodenya.
Sekarang kita masukkan perintah logika kita diatas, kodenya begini:
Rumus MA
double MA = iMA(NULL,NULL,14,0,0,0,1);
Logika OP nya
if (Ask>MA){
int ticket = OrderSend(NULL,OP_BUY,Lot,Ask,3,Ask-SL*Point,Ask+TP*Point);
}
if (Bid<MA) {
int ticket = OrderSend(NULL,OP_SELL,Lot,Bid,3,Bid+SL*Point,Bid-TP*Point);
}
int ticket = OrderSend(NULL,OP_BUY,Lot,Ask,3,Ask-SL*Point,Ask+TP*Point);
}
if (Bid<MA) {
int ticket = OrderSend(NULL,OP_SELL,Lot,Bid,3,Bid+SL*Point,Bid-TP*Point);
}
Tempatkan kode Rumus dan Logika itu di bawah void OnTick() setelah kurung kurawal {
jadinya begini:
//+------------------------------------------------------------------+
//| forexxxu.mq4 |
//| Copyright 2016 @ forexxxu.blogspot.co.id |
//| https://forexxxu.blogspot.co.id |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017 @forexxxu.blogspot.co.id"
#property link "https://forexxxu.blogspot.co.id"
#property version "1.00"
#property strict
input double Lot = 0.1;
input int TP = 200;
input int SL = 200;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
double MA = iMA(NULL,NULL,14,0,0,0,1);
if (OrdersTotal()==0) {
if (Ask>MA){
int ticket = OrderSend(NULL,OP_BUY,Lot,Ask,3,Ask-SL*Point,Ask+TP*Point);
}
if (Bid<MA) {
int ticket = OrderSend(NULL,OP_SELL,Lot,Bid,3,Bid+SL*Point,Bid-TP*Point);
}
}
}
//+------------------------------------------------------------------+
//| forexxxu.mq4 |
//| Copyright 2016 @ forexxxu.blogspot.co.id |
//| https://forexxxu.blogspot.co.id |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017 @forexxxu.blogspot.co.id"
#property link "https://forexxxu.blogspot.co.id"
#property version "1.00"
#property strict
input double Lot = 0.1;
input int TP = 200;
input int SL = 200;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
double MA = iMA(NULL,NULL,14,0,0,0,1);
if (OrdersTotal()==0) {
if (Ask>MA){
int ticket = OrderSend(NULL,OP_BUY,Lot,Ask,3,Ask-SL*Point,Ask+TP*Point);
}
if (Bid<MA) {
int ticket = OrderSend(NULL,OP_SELL,Lot,Bid,3,Bid+SL*Point,Bid-TP*Point);
}
}
}
//+------------------------------------------------------------------+
Setelah itu, Compile, dan selesailah EA pertama kita. Coba jalankan di strategy tester, kalau bisa jalan, berarti berhasil.
Demikian secara singkat cara membuat Robot Forex untuk pemula. Semoga bermanfaat.