Tuesday 25 December 2012

Belajar Membuat EA Sederhana 15


http://jumforex.blogspot.com/2012/10/belajar-membuat-ea-sederhana-15.html

Pastian sudah membaca part 14 disini 

Pada bagian ini kita akan memodifikasi EA pada part 14 dengan sedikit penambahan hedge average
Seperti pada part-part sebelumnya telah dibahas juga op hedge (buy dan sell) .

Supaya terjadi ordernya tidak satu arah tetapi order berdasarkan signal yang terjadi , maka bagian yang di rubah adalh pagian trigernya dengan menghilangkan filter jumlah order yang berlawanan , sebagai berikut:


  if( jumlahorder(0)<Max_order  && Trade_buy  && signal==1  && wt!=Time[0] ){tiket = OrderSend(Symbol(),OP_BUY,NR(Lots),Ask,3,slb, tpb,Nama_EA,Magic,0,Blue);
  if(tiket>0) wt=Time[0];
  }
  if( jumlahorder(1)<Max_order && Trade_sell && signal==2  && wk!=Time[0]) {ticet = OrderSend(Symbol(),OP_SELL,NR(Lots),Bid,3,sls, tps,Nama_EA,Magic,0,Red);
  if(ticet>0) wk=Time[0];
  }


Sehingga bila dimasukkan ke dalam EAnya :


//+------------------------------------------------------------------+
//|                                             EA MA Cross AntiQ+   |
//|                                                gifaesa@yahoo.com |
//|                                     http://JumForex.blogspot.com |
//+------------------------------------------------------------------+

#property copyright "JumForex.blogspot.com"
#property link      "Gifaesa@yahoo.com"

extern string  Nama_EA                 = "Cross AntiQ+";
extern bool    Trade_buy               = true;
extern bool    Trade_sell              = true;
extern int     Mulai_Jam               = 6;
extern int     Akhir_Jam               = 20;
extern bool    Tp_in_Money             = true;
extern double  TP_in_money             = 2;
extern int     TP                      = 100;
extern int     SL                      = 100;
extern int     Max_order               = 10;
extern double  Lots                    = 0.1;
extern bool    TrailingStop_           = true;
extern int     TrailingStop            = 20;
extern int     Magic                   = 69;
extern string  Seting_MA               = "Sesuka Hati";
extern int     Pereode_1                 = 4;
extern int     Pereode_2                 = 4;

double slb,tpb,sls,tps,pt;
int wt,wk,tiket,ticet;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   if(Digits==3 || Digits==5) pt=10*Point;   else   pt=Point;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {

if(TrailingStop_)dtrailing();
if(Tp_in_Money && TP_in_money<= money()) closeall();
//----
double MA_1O =iMA(Symbol(),0,Pereode_1,0,MODE_SMA,PRICE_OPEN ,1);
double MA_1C =iMA(Symbol(),0,Pereode_1,0,MODE_SMA,PRICE_CLOSE ,1);
double MA_2O =iMA(Symbol(),0,Pereode_2,0,MODE_SMA,PRICE_OPEN ,2);
double MA_2C =iMA(Symbol(),0,Pereode_2,0,MODE_SMA,PRICE_CLOSE ,2);

int signal;
if(MA_2O >MA_2C && MA_1O < MA_1C) signal=1;// aturan buy
if(MA_2O <MA_2C && MA_1O > MA_1C) signal=2;//aturan sell
if(Jam_trade()==1){
   if(SL==0)slb=0;else slb=Ask-SL*pt;
   if(SL==0)sls=0;else sls=Bid+SL*pt;
   if(TP==0)tpb=0;else tpb=Ask+TP*pt;
   if(TP==0)tps=0;else tps=Bid-TP*pt;
  if( jumlahorder(0)<Max_order  && Trade_buy  && signal==1  && wt!=Time[0] ){tiket = OrderSend(Symbol(),OP_BUY,NR(Lots),Ask,3,slb, tpb,Nama_EA,Magic,0,Blue);
  if(tiket>0) wt=Time[0];
  }
  if( jumlahorder(1)<Max_order && Trade_sell && signal==2  && wk!=Time[0]) {ticet = OrderSend(Symbol(),OP_SELL,NR(Lots),Bid,3,sls, tps,Nama_EA,Magic,0,Red);
  if(ticet>0) wk=Time[0];
  }
 }
//----
   return(0);
  }
//+------------------------------------------------------------------+

int Jam_trade()
{
   bool trade = false;
   if(Mulai_Jam > Akhir_Jam){
     if (Hour() >= Mulai_Jam || Hour() < Akhir_Jam) trade = true;
   } else
     if (Hour() >= Mulai_Jam && Hour() < Akhir_Jam) trade = true;

   return (trade);
}

int jumlahorder( int tipe)
{
int total=0;
for(int i=0; i<OrdersTotal(); i++)
  {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic || OrderType()!=tipe) continue;
     total++;
  }

return(total);
}
double NR(double thelot)
{
    double maxlots = MarketInfo(Symbol(), MODE_MAXLOT),
    minilot = MarketInfo(Symbol(), MODE_MINLOT),
    lstep = MarketInfo(Symbol(), MODE_LOTSTEP);
    double lots = lstep * NormalizeDouble(thelot / lstep, 0);
    lots = MathMax(MathMin(maxlots, lots), minilot);
    return (lots);
}

void dtrailing()
{
for(int i=0; i<OrdersTotal(); i++){
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
        if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic ) continue;
        if(OrderType()==OP_BUY)  {
         if(Bid-OrderOpenPrice()>pt*TrailingStop)  {
           if((OrderStopLoss()<Bid-pt*TrailingStop) || (OrderStopLoss()==0)) {
              OrderModify(OrderTicket(),OrderOpenPrice(),Bid-pt*TrailingStop,OrderTakeProfit(),0,Green);
              return(0);
              }
              }
           }
        if(OrderType()==OP_SELL)  {
         if((OrderOpenPrice()-Ask)>(pt*TrailingStop)){
           if(OrderStopLoss()>(Ask+pt*TrailingStop) || (OrderStopLoss()==0)){
              OrderModify(OrderTicket(),OrderOpenPrice(),Ask+pt*TrailingStop,OrderTakeProfit(),0,Red);
              return(0);
              }
              }
           }
     }
  
}
void closeall()
{
for (int i = OrdersTotal() - 1; i >= 0; i--) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber()!=Magic ) continue;
if (OrderType() > 1) OrderDelete(OrderTicket());
else {
if (OrderType() == 0) OrderClose(OrderTicket(), OrderLots(), Bid, 3, CLR_NONE);
else               OrderClose(OrderTicket(), OrderLots(), Ask, 3, CLR_NONE);
}
}
}
double money()
{
double dp = 0;
int i;
for (i = 0; i < OrdersTotal(); i++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol()  || OrderMagicNumber()!=Magic) continue;
dp += OrderProfit();
}
return(dp);
}

Jadideh..........
Semoga sukses deh

Salam

2 komentar:

  1. Assalamu'alaikum!
    Maaf master, mau tanya, kalau coding untuk biar OP mengikuti trend besar gimana ya? contohnya begini :
    Jika Trend besar turun, EA hanya akan OP SELL meskipun ada sinyal buy, begitu sebaliknya.
    jadi bisa otomatis, tidak usah mengubah settingan Trade_Buy = true/false & Trade_Sell = True/False
    sekian master, mohon maaf sebelumnya.
    wassalam
    Balas
    Balasan
    1. berarti perlu ditambah filter di trigernya
      contoh pada ea di atas
      if(MA_2O >MA_2C && MA_1O < MA_1C && tambah aturan trend besar buy) signal=1;// aturan buy
      if(MA_2O MA_1C && tambah aturan trend besar sell) signal=2;//aturan sell

2 comments:

  1. Hey Everybody,

    Below is a list of the most recommended forex brokers:
    1. Most Recommended Forex Broker
    2. eToro - $50 minimum deposit.

    Here is a list of the best forex tools:
    1. ForexTrendy - Recommended Probability Software.
    2. EA Builder - Custom Indicators Autotrading.
    3. Fast FX Profit - Secret Forex Strategy.

    Hopefully these lists are helpful to you...

    ReplyDelete
  2. Imagine if you had a robot with 6 years authenticated live proof?

    I just finished a webinar with Mark and his partner, Antony, two days ago and it was AWESOME.

    During the webinar Mark and Antony shared their secrets to success and answered questions about their new version of the GPS Forex Robot that came out TODAY!

    ReplyDelete