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

Tanya Jawab MQL

Discussion in 'Belajar MQL dari Nol' started by HendroFX, 09 Apr 2015.

  1. Abi Manyu

    Abi Manyu Member Credit Hunter

    Equity
    Credit
    Ref Point
    setelah ane cek udh dapat gan hanya sepertinya ada yang masih kurang nih kurang cepat proses eksekusinya.
    mungkin ada yang bisa memberikan pencerahan. berikut yang sudah ane edit gan.
    Code:
    //+------------------------------------------------------------------+
    //|                                AA_EA_ModifyPricePendingOrder.mq4 |
    //|                                        Copyright 2015, Abimanyu. |
    //|                                https://www.facebook.com/m4nyunz |
    //+------------------------------------------------------------------+
    #property copyright "Copyright 2015, Abimanyu."
    #property link      "https://www.facebook.com/m4nyunz"
    #property version  "1.00"
    #property strict
    
    //====================================================================================================
    extern string Step_PO = "Jarak pending order dr skrg";
    extern int	  SL	    = 10;
    extern int	  TP	    = 10;
    extern double Step01	 = 15.0,  LOT01  = 1.0;
    int	  ticket;
    double  myPoint, myBid, myAsk, PriceSell1, PriceBuy1;
    
    //====================================================================================================
    int OnInit()
    {
      myPoint  = MarketInfo(Symbol(),MODE_POINT);
      myBid    = MarketInfo(Symbol(),MODE_BID);
      myAsk    = MarketInfo(Symbol(),MODE_ASK);
      PriceSell1  = myBid-Step01*myPoint;  PriceBuy1  = myAsk+Step01*myPoint;
      while(true) {
          ticket=OrderSend(Symbol(),OP_SELLSTOP,LOT01,PriceSell1 ,0,PriceSell1 +SL*myPoint,PriceSell1 -TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
          ticket=OrderSend(Symbol(),OP_BUYSTOP ,LOT01,PriceBuy1  ,0,PriceBuy1  -SL*myPoint,PriceBuy1  +TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
          if(ticket<=0) Print("Error = ",GetLastError());
          else { Print("ticket = ",ticket); break;}
          Sleep(10000);}
      return(INIT_SUCCEEDED);
    }
    
    //====================================================================================================
    void OnDeinit(const int reason)
    {
    }
    
    //====================================================================================================
    int start()
    {
      for (int pos = 0; pos < OrdersTotal(); pos++) {
      OrderSelect(pos, SELECT_BY_POS, MODE_TRADES);
      if (OrderType() == OP_BUYSTOP) {
      OrderModify(OrderTicket(), Bid+Step01*myPoint,0,Bid+TP*myPoint,0,clrNONE);}
      if (OrderType() == OP_SELLSTOP) {
      OrderModify(OrderTicket(), Ask-Step01*myPoint,0,Ask-TP*myPoint,0,clrNONE);}}
    return(0);
    }
     
  2. cr_fx

    cr_fx Member

    Equity
    Credit
    Ref Point
    saya sendiri tidak mengcompile coding yg anda buat,tp menurut sy logika utk modify nya ada yg kurang lengkap utk di jelaskan dan juga ada yg terbalik utk penggunaan Ask dan Bid utk modify buystop/sellstopnya,coba di tambahkan ini di bagian modify
    utk yg buystop :
    if ((Ask + Step01*myPoint)<OrderOpenPrice()) kemudian baru masuk ke OrderModify(....,Ask + Step01*myPoint,...,....dst)
    utk yg sellstop :
    if ((Bid - Step01*myPoint)>OrderOpenPrice()) kemudian baru masuk ke OrderModify(....,Bid - Step01*myPoint,...,....dst)

    maaf klo sy salah cz masih nubi....
     
  3. cr_fx

    cr_fx Member

    Equity
    Credit
    Ref Point
    oya satu lagi utk penggunaan tp dan sl pd OrderModify() dibwt dari acuan harga buystop/sellstop yg baru
     
  4. Abi Manyu

    Abi Manyu Member Credit Hunter

    Equity
    Credit
    Ref Point
    maksudnya om, hee kurang ngerti, bisa di edit aja om kodingnya langsung biar tinggal copas hee... maklum baru bisa buat dan belum ngerti banget... hee :)
     
  5. Abi Manyu

    Abi Manyu Member Credit Hunter

    Equity
    Credit
    Ref Point
    permisi om HendroFX saya sedang coba buat script untuk melakukan pending order dengan beberapa step, namun terdapat masalah tidak mau OP pada step selanjutnya.
    mungkin om bisa bantu cek yang salah dimananya ya om.
    ini Codenya om
    Code:
    //+------------------------------------------------------------------+
    //|                                              TebarProfit_New.mq4 |
    //|                                        Copyright 2015, Abimanyu. |
    //|                                 https://www.facebook.com/m4nyunz |
    //+------------------------------------------------------------------+
    #property copyright "Copyright 2015, Abimanyu."
    #property link      "https://www.facebook.com/m4nyunz"
    #property version   "1.00"
    #property strict
    extern   int      SlipPage = 10;
    extern   string   MaxOPandInstep_ = "adalah Total dari Buy & Sell";
    extern   int      MaxOP = 52;
    extern   double   FirstStep = 15,
                      PlusNexStep = 5,
                      Lot1 = 0.1,
                      Lot2 = 0.2, InStep2 = 22,
                      Lot3 = 0.4, InStep3 = 32;
    //====================================================================================================
    void OnStart(){
    double   myBid = MarketInfo(Symbol(),MODE_BID),
             myAsk = MarketInfo(Symbol(),MODE_ASK),
             myPoint = MarketInfo(Symbol(),MODE_POINT);
    int      ticket, pos;
    ticket=OrderSend(Symbol(),OP_SELLSTOP,Lot1,myBid-FirstStep*myPoint,SlipPage,0,0,"",0,0,clrNONE);
    ticket=OrderSend(Symbol(),OP_BUYSTOP ,Lot1,myAsk+FirstStep*myPoint,SlipPage,0,0,"",0,0,clrNONE);
    
       for(pos = MaxOP; pos > OrdersTotal(); pos--){
       if(OrderSelect(pos,SELECT_BY_POS,MODE_TRADES)){
       if(pos<InStep2){ticket=OrderSend(Symbol(),OP_SELLSTOP,Lot1,myBid-(FirstStep+(pos*PlusNexStep))*myPoint,SlipPage,0,0,"",0,0,clrNONE);
                       ticket=OrderSend(Symbol(),OP_BUYSTOP ,Lot1,myAsk+(FirstStep+(pos*PlusNexStep))*myPoint,SlipPage,0,0,"",0,0,clrNONE);}
       if(pos<InStep3){ticket=OrderSend(Symbol(),OP_SELLSTOP,Lot2,myBid-(FirstStep+(pos*PlusNexStep))*myPoint,SlipPage,0,0,"",0,0,clrNONE);
                       ticket=OrderSend(Symbol(),OP_BUYSTOP ,Lot2,myAsk+(FirstStep+(pos*PlusNexStep))*myPoint,SlipPage,0,0,"",0,0,clrNONE);}
       else{ticket=OrderSend(Symbol(),OP_SELLSTOP,Lot3,myBid-(FirstStep+(pos*PlusNexStep))*myPoint,SlipPage,0,0,"",0,0,clrNONE);
            ticket=OrderSend(Symbol(),OP_BUYSTOP ,Lot3,myAsk+(FirstStep+(pos*PlusNexStep))*myPoint,SlipPage,0,0,"",0,0,clrNONE);}
    }}}
    Penjelasan singkat mengenai tujuan pembuatan ini adalah :
    jika tidak ada OP atau OP bernilai 0 ( NOL ), maka buat OP_BUYSTOP dan OP_SELLSTOP secara terus meneus dengan lot1 hingga total OP adalah sama dengan InStep2,
    dan jika total OP adalah lebih besar dari sama dengan InStep2, maka buat OP_BUYSTOP dan OP_SELLSTOP secara terus menerus dengan lot2 hingga total OP adalah sama dengan InStep3, dan jika total OP adalah lebih besar dari sama dengan InStep3, maka buat OP_BUYSTOP dan OP_SELLSTOP secara terus menerus dengan lot3 hingga total OP adalah sama dengan MaxOP.

    Terimakasih om HendroFX
    Salam Profit Indonesia
     
  6. HendroFX

    HendroFX Moderator Moderator

    Equity
    Credit
    Ref Point
    Untuk menjalankan OrderSend pada InStep3, maka harus difilter dulu dengan sebuh logika, jika Nilai pos ==InStep2 maka buat Order jika nilai pos kurang dari InStep3. Hanya pastikan bahwa order akan jalan jika logika awal sudah dipenuhi, Untuk Lots ketiga buat saja logika sama dengan posisi Instep3. Semoga membantu:)
     
  7. Abi Manyu

    Abi Manyu Member Credit Hunter

    Equity
    Credit
    Ref Point
    terimakasih om HendroFX sudah dijawab
    dan terdapat masalah hanya dia tidak mau looping jadi hanya tereksekusi 6 PO saja mas
    4 PO dengan nilai LOT1 dan 2 PO dengan LOT2.
    kodenya seperti ini om
    Code:
    void OnStart(){
    double   myBid = MarketInfo(Symbol(),MODE_BID),
             myAsk = MarketInfo(Symbol(),MODE_ASK),
             myPoint = MarketInfo(Symbol(),MODE_POINT);
    int      ticket, pos;
    ticket=OrderSend(Symbol(),OP_SELLSTOP,Lot1,myBid-FirstStep*myPoint,SlipPage,0,0,"",0,0,clrNONE);
    ticket=OrderSend(Symbol(),OP_BUYSTOP ,Lot1,myAsk+FirstStep*myPoint,SlipPage,0,0,"",0,0,clrNONE);
    
       for(pos=0;pos<MaxOP;pos--){
       if(OrderSelect(pos,SELECT_BY_POS,MODE_TRADES)){
       if(pos<=InStep2){ticket=OrderSend(Symbol(),OP_SELLSTOP,Lot1,myBid-(FirstStep+(pos*PlusNexStep))*myPoint,SlipPage,0,0,"",0,0,clrNONE);
                        ticket=OrderSend(Symbol(),OP_BUYSTOP ,Lot1,myAsk+(FirstStep+(pos*PlusNexStep))*myPoint,SlipPage,0,0,"",0,0,clrNONE);}
       if(pos<=InStep3){ticket=OrderSend(Symbol(),OP_SELLSTOP,Lot2,myBid-(FirstStep+(pos*PlusNexStep))*myPoint,SlipPage,0,0,"",0,0,clrNONE);
                        ticket=OrderSend(Symbol(),OP_BUYSTOP ,Lot2,myAsk+(FirstStep+(pos*PlusNexStep))*myPoint,SlipPage,0,0,"",0,0,clrNONE);}
       else{ticket=OrderSend(Symbol(),OP_SELLSTOP,Lot3,myBid-(FirstStep+(pos*PlusNexStep))*myPoint,SlipPage,0,0,"",0,0,clrNONE);
            ticket=OrderSend(Symbol(),OP_BUYSTOP ,Lot3,myAsk+(FirstStep+(pos*PlusNexStep))*myPoint,SlipPage,0,0,"",0,0,clrNONE);}
    }}}
    mohon masukkannya kembali om dimana harus saya rubah kembali kodenya.
    terimakasih.
     
  8. HendroFX

    HendroFX Moderator Moderator

    Equity
    Credit
    Ref Point
    Caba tulis dengan jelas RULEnya seperti apa, apa yang akan dibuat dengan Script tersebut, karena script hanya menjalankan perintah sekali jalan saja, berbeda dengan EA
     
  9. Abi Manyu

    Abi Manyu Member Credit Hunter

    Equity
    Credit
    Ref Point
    Rulenya seperti ini OM :
    semua rule dapat diatur sendiri oleh user
    1. Pasang Pending Order BUYSTOP & SELLTOP masing - masing sama banyaknya dengan jumlah yang diinginkan
    2. Penentuan Jarak Pending Order Awal dari harga saat ini
    3. Penentuan Jarak antara Pending Order awal dengan Pending Order berikutnya sama hingga Pending Order sama dengan maksimal jumlah yang diinginkan
    kalau saya buat lebih ribet om, dan semua diinput manual tidak bisa flexible ini code yang saya buat om.
    Code:
    //+------------------------------------------------------------------+
    //|                                         TebarProfit_Standard.mq4 |
    //|                                        Copyright 2015, Abimanyu. |
    //|                                 https://www.facebook.com/m4nyunz |
    //+------------------------------------------------------------------+
    #property copyright "Copyright 2015, Abimanyu."
    #property link      "https://www.facebook.com/m4nyunz"
    #property version   "1.00"
    #property strict
    //====================================================================================================
    void OnStart(){
       int      SL = 10,           TP = 150,        
                ticket;
       double   myBid = MarketInfo(Symbol(),MODE_BID),
                myAsk = MarketInfo(Symbol(),MODE_ASK),
                myPoint = MarketInfo(Symbol(),MODE_POINT),
                Step01     = 15.0,  LOT01  = 0.1,
                Step02     = 25.0,  LOT02  = 0.1,
                Step03     = 35.0,  LOT03  = 0.1,
                Step04     = 40.0,  LOT04  = 0.1,
                Step05     = 45.0,  LOT05  = 0.2,
                Step06     = 50.0,  LOT06  = 0.2,
                Step07     = 55.0,  LOT07  = 0.2,
                Step08     = 60.0,  LOT08  = 0.3,
                Step09     = 65.0,  LOT09  = 0.3,
                Step10     = 70.0,  LOT10  = 0.3,
                PriceSell1 , PriceSell2 , PriceSell3 , PriceSell4 , PriceSell5 ,
                PriceSell6 , PriceSell7 , PriceSell8 , PriceSell9 , PriceSell10,
                PriceBuy1  , PriceBuy2  , PriceBuy3  , PriceBuy4  , PriceBuy5  ,
                PriceBuy6  , PriceBuy7  , PriceBuy8  , PriceBuy9  , PriceBuy10;
       PriceSell1  = myBid-Step01*myPoint;  PriceBuy1  = myAsk+Step01*myPoint;
       PriceSell2  = myBid-Step02*myPoint;  PriceBuy2  = myAsk+Step02*myPoint;
       PriceSell3  = myBid-Step03*myPoint;  PriceBuy3  = myAsk+Step03*myPoint;
       PriceSell4  = myBid-Step04*myPoint;  PriceBuy4  = myAsk+Step04*myPoint;
       PriceSell5  = myBid-Step05*myPoint;  PriceBuy5  = myAsk+Step05*myPoint;
       PriceSell6  = myBid-Step06*myPoint;  PriceBuy6  = myAsk+Step06*myPoint;
       PriceSell7  = myBid-Step07*myPoint;  PriceBuy7  = myAsk+Step07*myPoint;
       PriceSell8  = myBid-Step08*myPoint;  PriceBuy8  = myAsk+Step08*myPoint;
       PriceSell9  = myBid-Step09*myPoint;  PriceBuy9  = myAsk+Step09*myPoint;
       PriceSell10 = myBid-Step10*myPoint;  PriceBuy10 = myAsk+Step10*myPoint;
       while(true) {
             ticket=OrderSend(Symbol(),OP_SELLSTOP,LOT01,PriceSell1 ,0,PriceSell1 +SL*myPoint,PriceSell1 -TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
             ticket=OrderSend(Symbol(),OP_BUYSTOP ,LOT01,PriceBuy1  ,0,PriceBuy1  -SL*myPoint,PriceBuy1  +TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
             ticket=OrderSend(Symbol(),OP_SELLSTOP,LOT02,PriceSell2 ,0,PriceSell2 +SL*myPoint,PriceSell2 -TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
             ticket=OrderSend(Symbol(),OP_BUYSTOP ,LOT02,PriceBuy2  ,0,PriceBuy2  -SL*myPoint,PriceBuy2  +TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
             ticket=OrderSend(Symbol(),OP_SELLSTOP,LOT03,PriceSell3 ,0,PriceSell3 +SL*myPoint,PriceSell3 -TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
             ticket=OrderSend(Symbol(),OP_BUYSTOP ,LOT03,PriceBuy3  ,0,PriceBuy3  -SL*myPoint,PriceBuy3  +TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
             ticket=OrderSend(Symbol(),OP_SELLSTOP,LOT04,PriceSell4 ,0,PriceSell4 +SL*myPoint,PriceSell4 -TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
             ticket=OrderSend(Symbol(),OP_BUYSTOP ,LOT04,PriceBuy4  ,0,PriceBuy4  -SL*myPoint,PriceBuy4  +TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
             ticket=OrderSend(Symbol(),OP_SELLSTOP,LOT05,PriceSell5 ,0,PriceSell5 +SL*myPoint,PriceSell5 -TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
             ticket=OrderSend(Symbol(),OP_BUYSTOP ,LOT05,PriceBuy5  ,0,PriceBuy5  -SL*myPoint,PriceBuy5  +TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
             ticket=OrderSend(Symbol(),OP_SELLSTOP,LOT06,PriceSell6 ,0,PriceSell6 +SL*myPoint,PriceSell6 -TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
             ticket=OrderSend(Symbol(),OP_BUYSTOP ,LOT06,PriceBuy6  ,0,PriceBuy6  -SL*myPoint,PriceBuy6  +TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
             ticket=OrderSend(Symbol(),OP_SELLSTOP,LOT07,PriceSell7 ,0,PriceSell7 +SL*myPoint,PriceSell7 -TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
             ticket=OrderSend(Symbol(),OP_BUYSTOP ,LOT07,PriceBuy7  ,0,PriceBuy7  -SL*myPoint,PriceBuy7  +TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
             ticket=OrderSend(Symbol(),OP_SELLSTOP,LOT08,PriceSell8 ,0,PriceSell8 +SL*myPoint,PriceSell8 -TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
             ticket=OrderSend(Symbol(),OP_BUYSTOP ,LOT08,PriceBuy8  ,0,PriceBuy8  -SL*myPoint,PriceBuy8  +TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
             ticket=OrderSend(Symbol(),OP_SELLSTOP,LOT09,PriceSell9 ,0,PriceSell9 +SL*myPoint,PriceSell9 -TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
             ticket=OrderSend(Symbol(),OP_BUYSTOP ,LOT09,PriceBuy9  ,0,PriceBuy9  -SL*myPoint,PriceBuy9  +TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
             ticket=OrderSend(Symbol(),OP_SELLSTOP,LOT10,PriceSell10,0,PriceSell10+SL*myPoint,PriceSell10-TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
             ticket=OrderSend(Symbol(),OP_BUYSTOP ,LOT10,PriceBuy10 ,0,PriceBuy10 -SL*myPoint,PriceBuy10 +TP*myPoint,"AA_TebarProfit",0,0,clrNONE);
             if(ticket<=0) Print("Error = ",GetLastError());
             else { Print("ticket = ",ticket); break; }
             Sleep(10000);}}
    nah kalau seperti ini jika mau buat tambahan order lagi harus rubah dari MQLnya. nah maunya yang bisa diinput diluar om.
    Terimakasih om HendroFX
    Salam Profit Indonesia
     
  10. HendroFX

    HendroFX Moderator Moderator

    Equity
    Credit
    Ref Point
    Sebenarnya hal yang mendasar adalah bagaimana memahami konsep awal dari sebuah Order.
    Saran saya buatlah fungsi untuk Order Pending order, Lalu jika 1 pending order berhasil buat lagi untuk 2 pending order dengan jarak tertentu sesuai keinginan kita,
    Dari hal yang sederhana ini nanti konsepnya kita kembangkang menjadi fungsi yang jauh lebih kompleks lagi, agar tidak membingungkan.
    Mulailah dari hal yang sederhana sebelum melangkah hal hal yang lebih kompleks
     
  11. argatafx

    argatafx Member Credit Hunter

    Equity
    Credit
    Ref Point
    Selamat Malam om HendroFX dan agan2 sekalian...

    mau tanya donk,
    coding untuk averaging bagaimana ya om,,,
     
  12. HendroFX

    HendroFX Moderator Moderator

    Equity
    Credit
    Ref Point
    Apakah sebelumnya sudah pernah belajar mengenai dasar dasar coding?
    Coba buat Step step dibawah ini:
    Pertama, Buat fungsi Open order
    Kedua,Buat fungsi untuk mendeteksi Type order yang sedang berjalan
    Ketiga,Buat fungsi untuk mengetahui jarak antara order dengan harga sekarang
    Ketempat, buat fungsi untuk mengetahui / menghitung jumlah order
     
  13. jeje_fx

    jeje_fx New Member

    Equity
    Credit
    Ref Point
    Permisi om mohon bimbinganya, ea yg saya bikin ini ud melakukan buy dan tp,
    supaya dia bisa sell dan tp jg gimana caranya ya. mohon maaf seblmnya.

    //+------------------------------------------------------------------+
    //| buy dan sell.mq4 |
    //| Copyright 2015, MetaQuotes Software Corp. |
    //| https://www.mql5.com |
    //+------------------------------------------------------------------+
    [HASHTAG]#property[/HASHTAG] copyright "Copyright 2015, MetaQuotes Software Corp."
    [HASHTAG]#property[/HASHTAG] link "https://www.mql5.com"
    [HASHTAG]#property[/HASHTAG] version "1.00"
    [HASHTAG]#property[/HASHTAG] strict

    extern int Magic = 123;
    extern string EACom= "YD";
    extern int Slippage = 3;
    extern double Lots = 0.10;
    extern int TakeProfit= 30;
    extern int StopLoss= 0;
    extern string Pair ="";


    //+------------------------------------------------------------------+
    //| Expert initialization function |
    //+------------------------------------------------------------------+
    int init()
    {
    //---
    double price = Ask;
    double SL = Ask-(StopLoss*Point);
    double TP= Ask+(TakeProfit*Point);
    if(StopLoss==0) SL=0;
    if(TakeProfit==0) TP=0;



    OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,SL,TP,"EACom",Magic,0,Blue);

    /*/int OrderSend(string symbol,int cmd,double volume,
    double price,int slippage,double stoploss
    double takeprofit, string comment=NULL,
    int magic=0, datatime expiration=0
    color arrow_color=CLR_NONE) //*/

    //---
    return(INIT_SUCCEEDED);
    }
    //+------------------------------------------------------------------+
    //| Expert deinitialization function |
    //+------------------------------------------------------------------+
    void OnDeinit(const int reason)
    {
    //---

    }
    //+------------------------------------------------------------------+
    //| Expert tick function |
    //+------------------------------------------------------------------+
    void OnTick()
    {
    //---

    }
    //+------------------------------------------------------------------+
     
  14. Abi Manyu

    Abi Manyu Member Credit Hunter

    Equity
    Credit
    Ref Point
    PERTAMA = buat filter OP yang mau dibuka apa
    KEDUA = buat kondisi pada ( double price, SL, TP )
     
  15. jeje_fx

    jeje_fx New Member

    Equity
    Credit
    Ref Point
    ap bnr seperti ini om..


    [HASHTAG]#property[/HASHTAG] copyright "Copyright 2015, MetaQuotes Software Corp."
    [HASHTAG]#property[/HASHTAG] link "https://www.mql5.com"
    [HASHTAG]#property[/HASHTAG] version "1.00"
    [HASHTAG]#property[/HASHTAG] strict

    extern int Magic = 123;
    extern string EACom= "YD";
    extern int Slippage = 3;
    extern double Lots = 0.10;
    extern int TakeProfit= 10;
    extern int StopLoss= 0;
    extern string Pair ="";

    string sym;

    //====================================
    int NewOrder(string mySym,int OPType,double myLots)
    {

    double price,SL,TP;
    double myPoint =MarketInfo(mySym,MODE_POINT);
    if (OPType==0)

    { price = MarketInfo(mySym,MODE_ASK);
    SL= price-(StopLoss*myPoint);
    TP= price+(TakeProfit*myPoint);

    }
    if (OPType==1)
    { price=MarketInfo(mySym,MODE_BID);
    SL= price+(StopLoss*myPoint);
    TP= price-(TakeProfit*myPoint);
    }

    if(StopLoss==0) SL=0;
    if(TakeProfit==0) TP=0;

    OrderSend(mySym,OPType,myLots,price,Slippage,SL,TP,"EACom",Magic,0,Blue);

    /*/int OrderSend(string symbol,int cmd,double volume,
    double price,int slippage,double stoploss
    double takeprofit, string comment=NULL,
    int magic=0, datatime expiration=0
    color arrow_color=CLR_NONE) //*/


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

    //+------------------------------------------------------------------+
    //| Expert initialization function |
    //+------------------------------------------------------------------+
    int init()
    {
    if(Pair=="")sym=Symbol();else sym=Pair;
    NewOrder("EURUSD",OP_BUY,0.10);
    NewOrder("EURUSD",OP_SELL,0.10);

    //---
    return(INIT_SUCCEEDED);
    }
     
  16. Threadmark: Cara membuat Order hanya 1 X
    HendroFX

    HendroFX Moderator Moderator

    Equity
    Credit
    Ref Point
    Apa yang ditulis sudah benar hanya EACOM tidak perlu lagi diberi tanda " ", karena sudah di deklarasikan dengan String, walau itu juga tidak masalah namun agar lebih sempurna saja,
    Pemanggilan Fungsi NewOrder pada Init menjunjukkan bahwa EA akan melakukan Perintah sekali saja untuk order BUY dan SELL, setelah perintah berhasil maka tidak akan order lagi
     
  17. Abi Manyu

    Abi Manyu Member Credit Hunter

    Equity
    Credit
    Ref Point
    xixi udh dijawab tuh sama TSnya, untuk keseluruhan udh OK kok gan..
    selamat...
     
  18. jeje_fx

    jeje_fx New Member

    Equity
    Credit
    Ref Point
    ya om cuma sekali buy/sell pas ke tp dia g open lg.
    saranya gimn om biar ea nya open posisi trz pas kena tp?
    terimah kasih seblmnya sdh dikoreksi.
     
  19. Abi Manyu

    Abi Manyu Member Credit Hunter

    Equity
    Credit
    Ref Point
    agar bisa op lagi, ditaruh di sini "void OnTick(){}"
    dan ditambahkan juga untuk filter setiap sudah TP mau OP berapa banyak.
    contoh :
    int TotalOPBuy = 0, TotalOPSell = 0; //ini ditaruh di Deklarasi Global
    void OnTick(){
    for(int i=0;i<OrdersTotal();i++){
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
    if(OrderType()==OP_BUY){TotalOPBuy++;if(TotalOPBuy<1)/*/masukkan signal untuk OP BUY disini/*/;}
    if(OrderType()==OP_SELL){TotalOPSell++;if(TotalOPSell<1)/*/masukkan signal untuk OP SELLdisini/*/;}}
     
  20. HendroFX

    HendroFX Moderator Moderator

    Equity
    Credit
    Ref Point
    Penempatan Fungsinya tidak di Init(), tetapi di OnTick(), dengan catatan buat fungsi pengitung Order
    Jadi logikanya adalah, JIKA Jumlah ORDER BUY=0, maka OP_BUY, begitu juga dengan SELL, coba buat dulu nanti kita bantu koreksi :)
     

Share This Page