Tuesday, 25 December 2012

Belajar Membuat EA Sederhana 14


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

Pastikan anda membaca di part 13 disini

Nah  part 14 kali ini kita akan memodifikasi EA pada part 13 supaya EAnya bertipe average

Rule yang saya tambahkan adalah order dalam pergantian candel bila terjadi order lanjutan (average) .
Order lanjutan tersebut tidak berdasarkan range atau pips tetapi dibuat order persignal, sehingga ketika ada order buy dan terjadi cross ma signal buy maka akan melakukan order lanjutan dala pergantian candel

Adapun bagian yang penting perlu ditambahkan adalah batasan op == Max_order
Hal lain adalah saya tambahkan pilihan trailing =false/true;

Sedangkan bagian pentingnya adalah penambahan filter pergantian candel , sy tambahan
if(wt!=Time[0]){ blabla..........................

if(tiket>0) wt=Time[0];
}


ini adalah filter untuk order pada pergantian candel

Nah ini hasilnya:

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

Oke deh semboga menambah wawasan

salam sukses

Jangan lupa kasih komen ya

1 comment:

  1. Hello Ya'll,

    I've included a list of the highest ranking forex brokers:
    1. Most Recommended Forex Broker
    2. eToro - $50 minimum deposit.

    Here is a list of top forex tools:
    1. ForexTrendy - Recommended Odds Software.
    2. EA Builder - Custom Strategies Autotrading.
    3. Fast FX Profit - Secret Forex Strategy.

    Hopefully these lists are benificial to you...

    ReplyDelete