1. Welcome back! Thank you for being a part of this Traders Community. Let's discuss and share :)
    Selamat datang kembali! Trimakasih telah menjadi bagian dari Komunitas Trader ini. Mari berdiskusi dan berbagi :)
    Dismiss Notice

Tutorial Bedah Source Code Expert Advisor

Discussion in 'Belajar MQL dari Nol' started by Pherry Chandra, 13 Nov 2015.

  1. Pherry Chandra

    Pherry Chandra Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    Ane ingin sharing ilmu MQL Code. karena ane tidak terlalu bisa dalam menjelas kan. let make it simple with Example :clap:

    thread ini ane persembahkan untuk mastah almando ,Rizarma, resa2410 dan pangestu

    EA pertama yg akan kita bedah adalah EA ane sendiri . silahkan di baca2 dulu thread nya dan sedot EA nya :rofl:

    https://soehoe.com/free-taste-asami-reserve-v-2.t847/

    Ada perbedaan Struktur / Kerangka di MetaTrader yg dulu dan sekarang untuk penulisan EA

    yg sekarang :
    Code:
    //+------------------------------------------------------------------+
    //|                                                          New.mq4 |
    //|                        Copyright 2015, MetaQuotes Software Corp. |
    //|                                            https://www.mql5.com |
    //+------------------------------------------------------------------+
    #property copyright "Copyright 2015, MetaQuotes Software Corp."
    #property link      "https://www.mql5.com"
    #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()
      {
    //---
     
      }
    //+------------------------------------------------------------------+
    
    yg dulu kira2 seperti ini

    Code:
    //+------------------------------------------------------------------+
    //|                                                Raito System.mq4  |
    //|                                                  @Pherry Chandra |
    //|                                            TIPE : EA            |
    //+------------------------------------------------------------------+
    #property copyright "@Pherry Chandra"
    #property link      "http://"
    #property version    "1.0"      // Current version of the Expert Advisor
    #property description "High Low Signal"
    #property tester_indicator "HighLow.ex4"
    
    //YOUR PARAMETER
    
    
    //INIT
    int init()
    {
    	return(0);
    }
    
    //DEINIT
    int deinit()
    {
        return(0);
    }
    
    //START LOGIC
    int start()
    {
    	//LOGIC EA
    	
    	return(0);
    }
    
    //FUNCTION
    Inti nya kurang lebih sama bisa sequensial maupun object oriented :cool: (bahasa IT).

    ok sampe disini ada pertanyaan ? sebelum lanjut ke Bedah EA
     
    • Like Like x 3
  2. almando

    almando Member Credit Hunter

    Equity
    Credit
    Ref Point
    pertalite ..
     
  3. Pherry Chandra

    Pherry Chandra Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    lanjutt nti malam ya ... mau keluar dulu :rofl:
     
  4. almando

    almando Member Credit Hunter

    Equity
    Credit
    Ref Point
    siap komandan ...
     
  5. Rizarma

    Rizarma Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    holy mama :shake:
     
  6. pangestu

    pangestu Member Credit Hunter

    Equity
    Credit
    Ref Point
    persiapan dulu,,, kopi sember .. roko 3 slop. asbak 3... gorengan seplastik gede ...
    gelar tiker , kasur , bantal selimut .. berlian.....nyimak
     
  7. Rizarma

    Rizarma Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    bau2nya mau bikin EA + MA21 nih :D
     
  8. pangestu

    pangestu Member Credit Hunter

    Equity
    Credit
    Ref Point
    :cry:stop jangan ditebak ilang ide cemerlangnya nih, tahap awal nyimak dulu sambil tumpang kaki
     
  9. resa2410

    resa2410 Well-Known Member Credit Hunter

    Equity
    Credit
    Ref Point
    ane sdh bawa kasur kesini.. siap nyimak.. :D
     
  10. pangestu

    pangestu Member Credit Hunter

    Equity
    Credit
    Ref Point
    saya liat bagian penting nya dulu yahh ,,, spertinya INIT,DEINIT , STARLOGIC,FUNCTION...ada kurung buka kurung tutup .. tengah2 ada return ,,, kecuali yang function
    mohon buat teman teman yang mastah berikan lah hamba ini sedikit pelita karen amasih gelap gulita banget. ( pake banget )
     
  11. Rizarma

    Rizarma Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    tahap pertama kira2 ngapain dulu yah?
     
  12. pangestu

    pangestu Member Credit Hunter

    Equity
    Credit
    Ref Point
    yang paling sulit logic kayanya
     
  13. Pherry Chandra

    Pherry Chandra Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    ayo kita mulai .. pertama adalah pengenalan apa itu Parameter, Function dan Prosedur.

    sudah ada yang tau ? ane rasa sudah pada tau ya :cool:

    Contoh :

    1. Prosedur : "Prosedur Delete Buy Limit Order"

    Code:
    void ForceCloseAllBuyLimit()
    {
      for (int cnt = OrdersTotal()-1 ; cnt >= 0; cnt--)
      {
          OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
          if (OrderSymbol() == Symbol() && OrderCloseTime()==0)
          {
                if(OrderType()==OP_BUYLIMIT) OrderDelete(OrderTicket());
          }
      }
    }
    2. Function : "Function Time Filter "

    Code:
    int Tradetime()
    {
      int TradingTime=0;
      if(OpenHour<CloseHour)
      {
          if (Hour() >= OpenHour && Hour() <= CloseHour) TradingTime=1;
      }
      else if(OpenHour>CloseHour)
      {
          if (Hour() >= OpenHour || Hour() <= CloseHour) TradingTime=1;
      }
      return(TradingTime);
    }
    3. Parameter

    Pakai Extern

    Code:
    extern  string  HourComment  = "=== TIME FILTER ===";
    extern  bool    UseTime      = FALSE;
    extern  int      OpenHour      = 0;
    extern  int      CloseHour    = 24;
    
    
    Non Extern

    Code:
    string  EAName                = "ETradingPips";    
    string  EAComment            = "Follow Twitter @ETradingPips";          
    int      EAMagicNumber        = 288;
    int      EAMagicNumberReserve        = 888;    
    Sekarang pertanyaan-nya:

    1. Beda Function dan Procedur itu apa ?
    2. Beda Parameter Extern dan Non Extern itu ?

    ane rasa gan pangestu bisa memberikan jawaban nya di thread ini.. monggo di bantu jawab gan :party:
     
  14. pangestu

    pangestu Member Credit Hunter

    Equity
    Credit
    Ref Point
  15. ngasqus

    ngasqus Active Member Pioneer

    Equity
    Credit
    Ref Point
    Untuk extern dan non extern penempatannya apa harus di awal ya??? Untuk declare??? Nah kalo untuk procedure sama function bisa ditaruh dipaling akhir????
    Bingung mo tanya apa masih belum paham ane
     
  16. Pherry Chandra

    Pherry Chandra Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    untuk peletakan bebas gan, ane cm terbiasa dengan code yg seperti itu :rofl:
     
  17. Pherry Chandra

    Pherry Chandra Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    1. Beda Function dan Procedur itu apa ?
    "Function itu mengeluarkan value sedang kan prosedur atau void tidak wajib mengeluarkan value"
    2. Beda Parameter Extern dan Non Extern itu ?
    "Extern supaya parameter dapat di input dari EA kalo Non berarti EA nya gak bisa di ubah2 parameter-nya"
     
  18. pangestu

    pangestu Member Credit Hunter

    Equity
    Credit
    Ref Point
    ohh gituuu
     
  19. Pherry Chandra

    Pherry Chandra Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    ini contoh simple penggunaan Procedure dan Function

    Code:
    #property copyright "@Pangestu"
    #property link      "http://"
    
    
    // Parameter
    extern  string  MgmComment    = "=== MANAGEMENT ORDER ==="; 
    extern  int      TakeProfit    = 30;
    extern  int      StopLoss      = 50;
    
    extern  string  MgmComment    = "=== Indikator Setting ==="; 
    extern int      RSIperiod = 5;
    extern int      rsilo_level      = 20;
    extern int      rsiup_level      = 80;
    
    
    //Init Awal
    int init()
    {
    	SetBroker(); ==> Prosedur untuk Set broker 4 atau 5 digit
    	return(0);
    }
    
    //DeInit
    int deinit()
    {
        ObjectsDeleteAll(0,OBJ_LABEL); ==> Function Bawaan MT4 yg memerlukan parameter
        return(0);
    }
    
    //Mulai Logic EA
    int start()
    {
      //Cek Signal == 1 Buy, 0 Sell
      if(CekSignal() == 1)
          Buy();
      else if(CekSignal() == 0)   
          Sell();
    	return(0);
    }
    
    //Prosedur dan Function
    void SetBroker()
    {
      if (Digits==3 || Digits==5) // Perintah untuk broker 5 Digits
          {SetPoint=Point*10;}
      else                        // Perintah untuk broker 4 Digits
          {SetPoint=Point;}
    }
    
    int CekSignal()
    {
    	int signal = -1;
    	int MA_sig = -1;
     
      double prevRSI=iRSI(Symbol(),0,RSIperiod,PRICE_MEDIAN,1);
      double RSI=iRSI(Symbol(),0,RSIperiod,PRICE_MEDIAN,0);
               
      if(RSI<=rsiup_level && prevRSI > rsiup_level)  MA_sig =1; //Buy
      else if(RSI>=rsilo_level && prevRSI < rsilo_level)  MA_sig = 0; //Sell
             
    	//Signal	
    	if (MA_sig == 1) //Buy
    		signal = 1;
    	else if(MA_sig == 0) //Sell
    		signal = 0;
    	
    	return(signal);
    }
    
    void Buy()
    {
      //Logic
    }
    
    
    void Sell()
    {
      //Logic
    }
     
  20. Pherry Chandra

    Pherry Chandra Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    dengan menggunakan Function dan Prosedure. pembuatan dan tracking error lbh mudah karena sudah di bagi2 logic nya. tinggal fokus ke mana yg error :wasntme:

    ini awal aja gan :yawn: ... nanti di implementasi lbh komplek :rofl:
     

Share This Page