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

Answered Coding di Multi Pairs

Discussion in 'Belajar MQL dari Nol' started by derryss, 11 Feb 2016.

  1. derryss

    derryss Member Credit Hunter

    Equity
    Credit
    Ref Point
    Ada yang bisa bantu contoh coding untuk EA supaya berjalan di multi pair tanpa attach EA di setiap pair ? cukup di attach di 1 pairs aja . dan bisa kita pilih pair apa aja yang akan di eksekusi analisa EA ini.

    thanks
     
  2. ngasqus

    ngasqus Active Member Pioneer

    Equity
    Credit
    Ref Point
    dapet dari googling
    Code:
    //+------------------------------------------------------------------+
    //|                                                          jkh.mq4 |
    //|                      Copyright © 2009, MetaQuotes Software Corp. |
    //|                                        http://www.metaquotes.net |
    //+------------------------------------------------------------------+
    #property copyright "Copyright © 2009, MetaQuotes Software Corp."
    #property link      "http://www.metaquotes.net"
    
    bool wannaBuy = true;
    bool wannaBuy1 = true;
    extern double LotSize = 0.01;
    extern string symbol1 = "EURUSD";
    extern string symbol2 = "USDCHF";
    extern int MaxDifference = 6;
    extern int Slippage = 3;
    extern int Magicnumber1 = 786;
    extern int Magicnumber2 = 123;
    int sendticket = 3;
    string pairs[18];
    
    //+------------------------------------------------------------------+
    //| expert initialization function                                   |
    //+------------------------------------------------------------------+
    int init()
      {
    //----
    pairs[0] = symbol1;
    pairs[1] = symbol2;
    wannaBuy = true;
    wannaBuy1 = true;
    
    //----
       return(0);
      }
    //+------------------------------------------------------------------+
    //| expert deinitialization function                                 |
    //+------------------------------------------------------------------+
    int deinit()
      {
    //----
       
    //----
       return(0);
      }
    //+------------------------------------------------------------------+
    //| expert start function                                            |
    //+------------------------------------------------------------------+
    int start()
      {
    //----
       // Send order for EURUSD & USDCHF
       if (wannaBuy) {   
       int ticket1;
       RefreshRates();
       ticket1 = OrderSend(symbol1, OP_BUY, LotSize, MarketInfo(symbol1,MODE_ASK), Slippage, 0, 0, 0,0,Magicnumber1,0) & OrderSend(symbol2, OP_BUY, LotSize, MarketInfo(symbol2,MODE_ASK), Slippage, 0, 0, 0,0,Magicnumber2,0);
       if (ticket1 <0 )
       {
       Print ("OrderSend failed with error #", GetLastError());
       return(0);
       }
       wannaBuy = false;
       }
    
    //----
       return(0);
      }
    //+------------------------------------------------------------------+
    kalo untuk analisa pair tertentu bisa pake MarketInfo()
     
  3. derryss

    derryss Member Credit Hunter

    Equity
    Credit
    Ref Point
    Thanks Om momod, tak coba pahami dulu .. masih belajar nih om.

     
  4. Amir Syarifudin

    Amir Syarifudin Member Credit Hunter

    Equity
    Credit
    Ref Point
    kalau multipair harus pake event OnTimer(), gak bisa pake ontick atau start karena pergerakan harga setiap pair tidak bersamaan
     
  5. derryss

    derryss Member Credit Hunter

    Equity
    Credit
    Ref Point
    bisa di kasih contoh coding nya om? pleaseee
     
  6. Amir Syarifudin

    Amir Syarifudin Member Credit Hunter

    Equity
    Credit
    Ref Point
    setelah ane kasih contoh pahami dan kembangkan sendiri ya...
     
  7. Amir Syarifudin

    Amir Syarifudin Member Credit Hunter

    Equity
    Credit
    Ref Point
    Code:
    //+------------------------------------------------------------------+
    //|                                              contohMultiPair.mq4 |
    //|                                                  Amir Syarifudin |
    //|                                 www.facebook.com/syarifudin.amir |
    //+------------------------------------------------------------------+
    #property copyright "Amir Syarifudin"
    #property link      "www.facebook.com/syarifudin.amir"
    #property version   "1.00"
    #property strict
    //+------------------------------------------------------------------+
    //| Expert initialization function                                   |
    //+------------------------------------------------------------------+
    string pair[]={"EURUSD","GBPUSD","AUDJPY"};
    string cmt="TestMultiPair";
    int OnInit()
      {
    //--- create timer
       EventSetMillisecondTimer(10);
         
    //---
       return(INIT_SUCCEEDED);
      }
    //+------------------------------------------------------------------+
    //| Expert deinitialization function                                 |
    //+------------------------------------------------------------------+
    void OnDeinit(const int reason)
      {
    //--- destroy timer
       EventKillTimer();
         
      }
    //+------------------------------------------------------------------+
    //| Expert tick function                                             |
    //+------------------------------------------------------------------+
    void OnTimer()
      {
    //---
      int cnt=ArrayRange(pair,0);
      for(int i=0;i<cnt;i++)
         {
         string spair=pair[i];
         _run(spair);
         }
      }
    //+------------------------------------------------------------------+
    void _run(string sym)
      {
      double o=iOpen(sym,PERIOD_M5,0);
      double c=iClose(sym,PERIOD_M5,0);
      int ordertotal=ordersCount(sym);
      if(ordertotal==0)
        {
        double ask=MarketInfo(sym,MODE_ASK);
        double bid=MarketInfo(sym,MODE_BID);
        if(ask!=0 && bid!=0)
          {
           if(c>o)
             {
             int suc=OrderSend(sym,OP_BUY,0.01,ask,3,0,0,cmt,0,0,clrNONE);
             }
           if(c<o)
             {
             int suc=OrderSend(sym,OP_SELL,0.01,bid,3,0,0,cmt,0,0,clrNONE);
             }
           }
         }
      }
    int ordersCount(string sym)
      {int ct=0;
       int c=OrdersTotal();
       for(int i=c;i>=0;i--)
          {if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){continue;}
          if(OrderSymbol()!=sym){continue;}
          ct++;}
        return(ct);}
     
    • Like Like x 2
  8. Trancexe

    Trancexe Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    Klo seandainya ngeyel di taruh do start efek nya apa ya?
     
  9. Amir Syarifudin

    Amir Syarifudin Member Credit Hunter

    Equity
    Credit
    Ref Point
    do start itu hanya mengeksekusi bila ada pergerakan harga pada chart pair ea dipasang, kita tahu kalau pergerakan harga semua pair tidak bersamaan. Misal harga EURUSD sudah bergerak 10 kali tapi USDJPY bergerak baru 1 kali, seandainya ea multipair dipasang di chart USDJPY maka akan ketinggalan moment 10 kali.
     
  10. Trancexe

    Trancexe Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    saya soalnya masang di int start ><
     
  11. Amir Syarifudin

    Amir Syarifudin Member Credit Hunter

    Equity
    Credit
    Ref Point
    :):ok:
     
  12. Trancexe

    Trancexe Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    saya masih bingung dengan penggunaan "void _run(string sym)"
    dari mana variable sym didapat?
     
  13. Amir Syarifudin

    Amir Syarifudin Member Credit Hunter

    Equity
    Credit
    Ref Point
    didapat saat digunakan,,, misal _run("EURUSD"); maka sym="EURUSD"
     
  14. Trancexe

    Trancexe Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    bearti di mulai dari _run(spair)?
    klo boleh tau.. buku apa yang bisa saya baca untuk belajar logika mq4.
     
  15. Amir Syarifudin

    Amir Syarifudin Member Credit Hunter

    Equity
    Credit
    Ref Point
    betul, dimulai dari _run(spair)
    saya belajar logika mq4 melihat contoh script yang bisa didownload di Code Base MT4 dan MetaEditor,,,, o iya, ane sudah terbiasa bahasa program dan sering buat software-software kecil untuk keperluan sendiri dikerjaan.
     
  16. Trancexe

    Trancexe Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    >< basicnya sudah sering bikin program jadi. tinggal penyesuaian.
    harus banyak belajar saya hehe

    btw bisa tidak saya membuat logika di int start()
    dan di eksekusi di void onTimer()..

    misal di int start()
    {
    if(close1>open1 && open1>ma24)
    {
    signal1=1;
    }
    if(close1<open1 && open1<ma24)
    {
    signal2=1;
    }
    }

    nah nanti di void OnTimer()
    baru saya kasih perintah untuk OrderSend
     
  17. Amir Syarifudin

    Amir Syarifudin Member Credit Hunter

    Equity
    Credit
    Ref Point
    bisa saja,tapi start() hanya jalan bila ada perubahan harga di chart ea di attach. Lebih baik dicoba saja biar tau bagaimana efeknya...
     
  18. Trancexe

    Trancexe Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    wokeeee.. makasih masukannya. coba pake simple rule 1 pair dlu.. klo OP lanjut 2 pair
     
  19. Trancexe

    Trancexe Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    berhasil saya pake OnTimer..

    tapi muncul masalah..
    Fungsi Order Count ane telat eksekusi.. jadinya ketika di loop per 10ms..
    OP muncul terus..
    contoh saya mau OP2.. nah pas OP dah 2. order count masih hitung 0. begitu 4.. baru order count naik.

    solusinya gmn ya.. apa loopnya kita per lambat?
     

    Attached Files:

  20. Amir Syarifudin

    Amir Syarifudin Member Credit Hunter

    Equity
    Credit
    Ref Point
    tambahkan Sleep(2000); setelah ordersend untuk memberi jeda order sukses.
     
    • Bad Spelling Bad Spelling x 1

Share This Page