Saturday, 8 June 2013

Mari Membuat EA (Logic Stoch plus Martingale)

http://www.blogrumahfx.com/2013/01/mari-membuat-ea-logic-stoch-plus.html

//+-----------------------------------------------------------------------+
//|                                        ~~ tes trigger op stoch ~~.mq4 |
//|                                          @tes trigger op stoch        |
//|                                                                       |
//+-----------------------------------------------------------------------+
#property copyright "@tes trigger op stoch"

/*-- Parameter ini ditampilkan di EA dan bisa diubah --*/

extern   int      TakeProfit  10;    // Nilai TP setiap OP di EA Martingale ini
extern   int      PipStep     10;    // Jarak pip dimana akan buka OP baru
extern   int      Slippage    3;    // Apa itu slippage ? Googling sendiri ya..
extern   double   Lots        0.05;  // Nilai lots awal, nantinya akan digandakan setiap step
extern   double   Multiply    3.0;  // Nilai pengali setiap step OP baru
extern   int      MaxTrade    7;   // Banyak OP maksimal yang boleh dijalankan
extern   bool     UseTime     TRUE// Pilihan apakah memakai waktu bekerjanya EA ?
extern   int      HourStart   24;   // Waktu mulai EA bekerja
extern   int      HourEnd     13;   // Waktu akhir EA bekerja

/*-- Parameter ini tidak ditampilkan di EA --*/

string   EAName    "~~tes trigger op stoch~~"// Nama EA, untuk ditampilkan di layar
string   EAComment "~~tes trigger op stoch~~"; // Variabel ini akan kita masukkan di setiap OP sebagai Comment
int      EAMagicNumber 8095;  // Magic Number
double   SetPoint      0;     // Variabel SetPoint untuk kode digit broker 4 atau 5


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+

int init()
  {

   //----

   
SetBroker();
   
//----
   
return(0);
  }

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+

int deinit()
  {
//----

//----
   
return(0);
  }

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+

int start()
  {

   //----

   
int   iTrade=0;


   
Comment(EAName);             // Tampilkan Nama EA di layar

   /* -- Jika tidak ada OP sama sekali, maka jalankan fungsi berikut --*/
   /* -- Disinilah tempat anda memasukkan koding indikator untuk memicu OP --*/
   
if(OrdersTotal()==0)
   {

       if ((
iStochastic(NULLNULL,4,14,1,MODE_SMA,0,MODE_MAIN,0) > iStochastic(NULLNULL,4,14,1,MODE_SMA,0,MODE_SIGNAL,0)))
      {
         
/*-- Order Buy --*/
         
OrderSend(Symbol(), OP_BUYLots,  AskSlippage0Ask+TakeProfit*SetPointEACommentEAMagicNumber);

      }
      else if ((
iStochastic(NULLNULL,4,14,1,MODE_SMA,0,MODE_MAIN,0) < iStochastic(NULLNULL,4,14,1,MODE_SMA,0,MODE_SIGNAL,0)))
      {
         
/*-- Order Sell --*/
         
OrderSend(Symbol(), OP_SELLLotsBidSlippage0Bid-TakeProfit*SetPointEACommentEAMagicNumber);
      }

   }


   
/* -- Inilah Fungsi Martingale. Jika ada OP yang salah, maka lakukan martingale --*/
   
if(OrdersTotal()>=1)
   {
      
GoMartingale();
   }

   
//----
   
return(0);
  }

//+------------------------------------------------------------------+

/*--agar EA bisa running di Broker 4 Digit atau 5 Digit--*/

void SetBroker()
{
   if (
Digits==|| Digits==5// Perintah untuk broker 5 Digits
      
{SetPoint=Point*10;}
   else                        
// Perintah untuk broker 4 Digits
      
{SetPoint=Point;}
}
void GoMartingale()
{
         
int      iCount      =  0;
         
double   LastOP      =  0;
         
double   LastLots    =  0;
         
bool     LastIsBuy   =  FALSE;
         
int      iTotalBuy   =  0;
         
int      iTotalSell  =  0;
         
int      Spread=0;

         
SpreadMarketInfo(Symbol(), MODE_SPREAD);


         for(
iCount=0;iCount<OrdersTotal();iCount++)
         {
       
           
OrderSelect(iCount,SELECT_BY_POS,MODE_TRADES);

           if(
OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
           {
               if(
LastOP==0) {LastOP=OrderOpenPrice();}
               if(
LastOP>OrderOpenPrice()) {LastOP=OrderOpenPrice();}
               if(
LastLots<OrderLots()) {LastLots=OrderLots();}
               
LastIsBuy=TRUE;
               
iTotalBuy++;
  
               
/* Bila mencapai batas OP maksimal, jangan tambah OP lagi */
               
if(iTotalBuy==MaxTrade) {return(0);}
           }

           if(
OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
           {
               if(
LastOP==0) {LastOP=OrderOpenPrice();}
               if(
LastOP<OrderOpenPrice()) {LastOP=OrderOpenPrice();}
               if(
LastLots<OrderLots()) {LastLots=OrderLots();}
               
LastIsBuy=FALSE;
               
iTotalSell++;
  
               
/* Bila mencapai batas OP maksimal, jangan tambah OP lagi */
               
if(iTotalBuy==MaxTrade) {return(0);}
           }

         }

         
/* Jika arah Price adalah DOWNTREND...., Periksa nilai Bid (*/
         
if(LastIsBuy)
         {
            if(
Bid<=LastOP-(Spread*SetPoint)-(PipStep*SetPoint))
            {
               
OrderSend(Symbol(), OP_BUYMultiply*LastLotsAskSlippage0Ask+TakeProfit*SetPointEACommentEAMagicNumber);
               
ModifyTP();
               
LastIsBuy=FALSE;
               return(
0);
            }
         }
         
/* Jika arah Price adalah Sell...., Periksa nilai Ask (*/
         
else if(!LastIsBuy)
         {
            if(
Ask>=LastOP+(Spread*SetPoint)+(PipStep*SetPoint))
            {
               
OrderSend(Symbol(), OP_SELLMultiply*LastLotsBidSlippage0Bid-TakeProfit*SetPointEACommentEAMagicNumber);
               
ModifyTP();
               return(
0);
            }
         }

}

/*-- Fungsi ModifyTP ini untuk mengubah semua OP agar TP di titik yang sama --*/
void ModifyTP()
{
   
int      iCount=0;
   
double   NewTP=0;

        
/*- Ambil nilai Take Profit dari Order terakhir -*/
         
for(iCount=0;iCount<OrdersTotal();iCount++)
         {

           
OrderSelect(iCount,SELECT_BY_POS,MODE_TRADES);

           
/*-- Kalau OP-nya adalah BUY, ambil nilai TP yang paling kecil. Jadikan TP bersama --*/
           
if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
           {
               if(
NewTP==0) {NewTP=OrderTakeProfit();}
               if(
NewTP>OrderTakeProfit()) {NewTP=OrderTakeProfit();}
  
           }

           
/*-- Kalau OP-nya adalah SELL, ambil nilai TP yang paling besar. Jadikan TP bersama --*/
           
if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
           {
               if(
NewTP==0) {NewTP=OrderTakeProfit();}
               if(
NewTP<OrderTakeProfit()) {NewTP=OrderTakeProfit();}
           }
        
         }

        
/*- Ubah semua nilai OP TakeProfit dengan yang baru (2x lipat) -*/
         
for(iCount=0;iCount<OrdersTotal();iCount++)
         {

           
OrderSelect(iCount,SELECT_BY_POS,MODE_TRADES);

           
/*- Kalau semua OP adalah BUY, maka ubahlah TP mereka -*/
           
if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
           {
               
OrderModify(OrderTicket(), OrderLots(), 0NewTP0);
           }

           
/*- Kalau semua OP adalah SELL, maka ubahlah TP mereka -*/
           
if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
           {
               
OrderModify(OrderTicket(), OrderLots(), 0NewTP0);
           }

         }
}  

2 comments:

  1. Any best Sports betting advisors or experts with email alert ...
    EA Builder

    ReplyDelete
  2. Your Affiliate Money Printing Machine is waiting -

    And getting it set up is as simple as 1---2---3!

    This is how it all works...

    STEP 1. Tell the system which affiliate products the system will push
    STEP 2. Add some PUSH button traffic (this ONLY takes 2 minutes)
    STEP 3. Watch the system explode your list and sell your affiliate products on it's own!

    Are you ready to start making money???

    Your MONEY MAKING affiliate solution is RIGHT HERE

    ReplyDelete