Kursus Forex Solo Tempat Belajar Trading Forex Solo Pelatihan Forex Solo Edukasi Forex Solo Training Forex Solo Privat Membuat EA Robot Forex

BACA TUTORIAL: CARA DAFTAR MT4 FOREX!

Cara Membuat EA Trailing Stop

Belajar Coding EA - Cara Membuat EA Trailing Stop. 




Coding MQL4 untuk membuat variable EA trailing stop:

extern double  LotsBuy      = 0.03;
extern double  LotsSell     = 0.03;
extern int     TPbUY        = 0;
extern int     SLbUY        = 0;
extern int     TPsELL       = 0;
extern int     SLsELL       = 0;
extern int     TrailingStop = 15;
       int     MagicNumber  = 975;

double StopLossBuy,TakeProfitBuy,StopLossSell,TakeProfitSell,Piips;

Coding MQL4 untuk membuat EA trailing stop supaya support dipakai untuk GOLD:




//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   if(Digits==3 || Digits==5) Piips=1*Point;   else   Piips=Point;
   //EA ini tidak support untuk GOLD atau XAUUSD
   //Supaya support GOLD ganti Digits==3 menjadi Digits==2
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }

Coding MQL4 untuk membuat program EA dengan trailing stop:




//+------------------------------------------------------------------+
//| Expert  tick  function                                           |
//+------------------------------------------------------------------+ 
void OnTick()
  {  
   TrailingStops();
   
   double MA30 = iMA(Symbol(),0,30,0,MODE_SMA,PRICE_CLOSE ,0); 
   double MA100 = iMA(Symbol(),0,100,0,MODE_SMA,PRICE_CLOSE ,0); 
  
   if(SLbUY==0)StopLossBuy=0;else StopLossBuy=Ask-SLbUY*Piips;
   if(SLsELL==0)StopLossSell=0;else StopLossSell=Bid+SLsELL*Piips;
   if(TPbUY==0)TakeProfitBuy=0;else TakeProfitBuy=Ask+TPbUY*Piips;
   if(TPsELL==0)TakeProfitSell=0;else TakeProfitSell=Bid-TPsELL*Piips;

  if(JumlahTransaksi(0)==0 && MA100>MA30 && Volume[2]<Volume[1] && Open[2]<Close[2] && Open[1]<Close[1] && Open[0]<Close[1]) {
  if(OrderSend(Symbol(),OP_BUY,LotsBuy,Ask,3,StopLossBuy,TakeProfitBuy,"EAoPbUY",MagicNumber,0,Blue))
  Print("Transaksi Buy Berhasil");}
  if(JumlahTransaksi(1)==0 && MA100<MA30 && Volume[2]>Volume[1] && Open[2]>Close[2] && Open[1]>Close[1] && Open[0]>Close[1]) 
  {if(OrderSend(Symbol(),OP_SELL,LotsSell,Bid,3,StopLossSell,TakeProfitSell,"EAoPsELL",MagicNumber,0,Red))
  Print("Transaksi Sell Berhasil");}
  }  
//+------------------------------------------------------------------+
int JumlahTransaksi( int tipe)
{
int total=0;
for(int i=0; i<OrdersTotal(); i++)
  {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber || OrderType()!=tipe) continue;
     total++;
  }

return(total);
}

Fungsi Trailing Stop Yang diBuat Dengan Bahasa Pemrograman MetaQuotes Language Editor:




void TrailingStops()

{int mode=0;
for(int i=0; i<OrdersTotal(); i++){
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
        if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber ) continue;
        if(OrderType()==OP_BUY)  {
         if(Bid-OrderOpenPrice()>Piips*TrailingStop)  {
           if((OrderStopLoss()<Bid-Piips*TrailingStop) || (OrderStopLoss()==0)) {
             mode= OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Piips*TrailingStop,OrderTakeProfit(),0,Aqua);
               }
              }
           }
        if(OrderType()==OP_SELL)  {
         if((OrderOpenPrice()-Ask)>(Piips*TrailingStop)){
           if(OrderStopLoss()>(Ask+Piips*TrailingStop) || (OrderStopLoss()==0)){
              mode=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Piips*TrailingStop,OrderTakeProfit(),0,Yellow);
               }
              }
           }
     }
   
}

Kalau ada pertanyaan terkait cara membuat EA trailing stop, tuliskan dikolom comment atau silahkan Anda hubungi ke kontak kami!

0 comments: