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. Trancexe

    Trancexe Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    makasih pak.. saya tulis seperti ini

    double atr_a = iATR(S1,PERIOD_D1,1,0);
    double atr_b = iATR(S2,PERIOD_D1,1,0);

    Gap = (atr_a - atr_b)/_Point;

    comment
    (
    ("\nRange = ",DoubleToStr(Gap,0)," (",DoubleToStr(distance*poin/_Point,0),")"
    )

    tinggal belajar bikin object :D
     
    Last edited: 26 Feb 2016
  2. Trancexe

    Trancexe Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    saya dapat value iAtr seperti ini
    Screenshot_62.jpg
    normal kah? padahal saya kira bisa dapat angka bulat.

    ini saya pake DoubleToStr
     
  3. Trancexe

    Trancexe Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    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)OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,SL,TP,"EACom",Magic,0,clrBlue);}
    if(OrderType()==OP_SELL){TotalOPSell++;if(TotalOPSell<1)OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,SL,TP,"EACom",Magic,0,clrRed);}}

    klo ini di modifikasi untuk membaca profit order yang sedang berjalan gmn?
     
  4. Trancexe

    Trancexe Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    akhirnya bisa melogika untuk penggunaan order send.
    Code:
    double Profit1()
    {
    double _Profit1 =0;
    for(cnt=0;cnt<OrdersTotal();cnt++) 
       {
         if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
         {
         if(OrderMagicNumber()==magic)
            _Profit1 = _Profit1 + OrderProfit()+ OrderSwap() + OrderCommission();
         }   
       }
       return (_Profit1);
    }  
    naah. sekarang saya penasaran lagi dengan cara membaca history profit. wkwkw
    saya buat seperti ini
    Code:
    //Check Profit history
    double checkProfitHst() {
       int daysint = Day();
       profitTemp = 0;
       for (int count = 0; count < OrdersHistoryTotal(); count++) {
          if (!OrderSelect(count, SELECT_BY_POS, MODE_HISTORY)) continue;
          if (OrderMagicNumber() != magic || OrderMagicNumber() != magic2) continue;
          if (OrderSymbol()==S1 || OrderSymbol()==S2 || OrderSymbol()==S3){
          if (TimeDay(OrderOpenTime()) == daysint) profitTemp += OrderProfit();
          }
       }
       return (profitTemp);
    }
    
    dan untuk mengecek kan saya taruh di komen..
    nilai profit oke, nilai history hari ini masih 0.

    kenapa ya?
     
  5. HendroFX

    HendroFX Moderator Moderator

    Equity
    Credit
    Ref Point
    Berarti pada hari itu memang belum ada close order untuk Symbol S1,S2, atau S3, Juga khusus untuk magic1 atau magic2.
     
  6. Trancexe

    Trancexe Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    tapi udah benar ya penulisannya..
    btw perbedaan penggunaan == dan !=. saya perhatikan jika di order select. sering menggunakan OrderMagic Number () !=magic.
    tapi klo ada dua variable yang di gunakan seringnya OrderMagic Number () ==magic || OrderMagic Number () ==magic2
     
  7. Efantri Sumitro

    Efantri Sumitro New Member

    Equity
    Credit
    Ref Point
    Tanya gan, kalau mau menghitung total history profit (jumlah profit yang sudah di close) bagaimana ya codingnya? trma kasih...
     
  8. Trancexe

    Trancexe Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    salah satu contohnya kya gini.
    Code:
    double ProfitHistory(){
    int hari = Day();
    double his=0;
    for(double cnt=0;cnt<OrdersHistoryTotal();cnt++)
      {
       OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY);
       if(TimeDay(OrderCloseTime())==hari)
         {
          his += OrderProfit()+ OrderSwap()+OrderCommission();
         }
      }
      return(his);
    }
    logikanya bisa dikembangin, tambah magic atau pair tertentu
     
    • Like Like x 1
  9. Adam53

    Adam53 Member Credit Hunter

    Equity
    Credit
    Ref Point
    Thank you very much for your help.
    My EA has just contained such errors.
    Now everything works perfectly for your help.
     
  10. Adam53

    Adam53 Member Credit Hunter

    Equity
    Credit
    Ref Point
    5/5,
    This is my review for this thread:
    Thank you very much for your help.
    It's a good post,
     
  11. Efantri Sumitro

    Efantri Sumitro New Member

    Equity
    Credit
    Ref Point
    terima kasih banyak gan...
     
    Master...
    Kalau mau bikin trailing Stop gimana ya codingnya? trm kash sebelumnya
     
  12. Oedyne Gwibroed

    Oedyne Gwibroed New Member

    Equity
    Credit
    Ref Point
    Adakah yang bisa bantu membuat tombol close all di chart dan bs di pakai ketika bt buat menu tambahan di ea
     
    Mumet ikut nyimak
     
  13. HendroFX

    HendroFX Moderator Moderator

    Equity
    Credit
    Ref Point
    Oedyne Gwibroed, untuk membuat Tombol reset sebagai menu tambahan itu bekerja pada OnChartEven, artinya semua coding akan diletakkan pada Fungsi tersebut, coba dibuat dulu Object tombolnya lalu letakkan pada fungsi OnChartEven
    Contoh silahkan dikembangjan...
    Code:
    void OnChartEvent(const int id,  const long &lparam,const double &dparam, const string &sparam)
      {
    //---
       if(sparam=="HdDel")
         {
          ObjectSetInteger(0,"HdDel",OBJPROP_STATE,false);
          Fungsi CLOSE ALL;   
        }
    //---     
      }
     
  14. Oedyne Gwibroed

    Oedyne Gwibroed New Member

    Equity
    Credit
    Ref Point
    Sdh bgt om hendro tp kok gk bs close ya ketika bt, klo ft bs om.
     
  15. HendroFX

    HendroFX Moderator Moderator

    Equity
    Credit
    Ref Point
    Hanya berlaku untuk FT, bukan untuk Back Tes. :)
     
  16. Oedyne Gwibroed

    Oedyne Gwibroed New Member

    Equity
    Credit
    Ref Point
    tp ea smulator ini bs sayang dia trial hanya 5 openan
     
    Ea tersebut bs berfungsi latihan dengan rule yng kita punya sampai betul2 hafal dengan rulenya, ea tsb berlaku juga di backtest
     
    double newStopLoss=0.0;
    int StopLevel = MarketInfo(Symbol(),MODE_STOPLEVEL);
    if(Stop<StopLevel)Stop=StopLevel;
    for (int i = OrdersTotal() - 1; i >= 0; i--){
    bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber ) continue;
    if(OrderType()==OP_BUY) {
    newStopLoss=Bid-(Stop*Point);
    if(Bid-OrderOpenPrice()>Point*Stop) {
    if((OrderStopLoss()<Bid-Point*Stop) || (OrderStopLoss()==0)) {
    if(OrderModify(OrderTicket(),OrderOpenPrice(),newStopLoss,OrderTakeProfit(),0,clrNONE)==false)
    {
    return(false);
    }else
    {
    return(true);
    }
    }
    }
    }
    if(OrderType()==OP_SELL) {
    newStopLoss=Ask+(Stop*Point);
    if((OrderOpenPrice()-Ask)>(Point*Stop)){
    if(OrderStopLoss()>Ask+(Point*Stop) || (OrderStopLoss()==0)){
    if(OrderModify(OrderTicket(),OrderOpenPrice(),newStopLoss,OrderTakeProfit(),0,clrNONE)==false)
    {
    return(false);
    }else
    {
    return(true);
    }
    }
    }
    }
    }
    silahkan koreksi jika ad kekurangan
     

    Attached Files:

    • Like Like x 1
  17. Trancexe

    Trancexe Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    [ask]
    saya coba pengen buat pending order bertingkat. saya kepikiran menggunakan fungsi for.
    for(int i=0;i<maxpendingorder;i++)
    {

    }

    nah bisa ga kita gunakan hasil dari fungsi hitung untuk membuat Pending order bertingkat..
     
  18. Trancexe

    Trancexe Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    akhirnya saya nemu coding seperti ini
    Code:
    //+------------------------------------------------------------------+
    //|                                                Pending Order.mq4 |
    //|                        Copyright 2016, MetaQuotes Software Corp. |
    //|                                             https://www.mql5.com |
    //+------------------------------------------------------------------+
    #property copyright "Copyright 2016, MetaQuotes Software Corp."
    #property link      "https://www.mql5.com"
    #property version   "1.00"
    #property strict
    #define major   1
    #define minor   1
    #include <stdlib.mqh>
    #include <stderror.mqh>
    //+------------------------------------------------------------------+
    //|Input                                                             |
    //+------------------------------------------------------------------+
    input int maxpendingorder                     = 5;
    input int magicbuy                            = 121;
    input int magicsell                           = 212;
    input int firstpipstep                          = 5;
    input int pipstep                             = 10;
    input double lot                              = 1;
    //+------------------------------------------------------------------+
    //Global variable                                                             |
    //+------------------------------------------------------------------+
    int tradebuy=0, tradesell=0;
    int signal1,signal2;
    
    //+------------------------------------------------------------------+
    //| Expert initialization function                                   |
    //+------------------------------------------------------------------+
    int OnInit()
      {
    //---
       
    //---
       return(INIT_SUCCEEDED);
      }
    //+------------------------------------------------------------------+
    //| Expert deinitialization function                                 |
    //+------------------------------------------------------------------+
    void OnDeinit(const int reason)
      {
    //---
       
      }
    //+------------------------------------------------------------------+
    //| Expert tick function                                             |
    //+------------------------------------------------------------------+
    int start()
      {
    //---
    int TOB=OrderCountBuy(OP_BUYSTOP);
    int TOS=OrderCountSell(OP_SELLSTOP);
    //Pending Order Buy
    if(TOB<maxpendingorder)
      {
       tradebuy=maxpendingorder-TOB;
      }
      else
        {
      return(0);   
        }
    if(OrderCountBuy(OP_BUY)==0)
       {
        for(int i=0;i<tradebuy;i++)
          {
           int ticketbuy=OrderSend(Symbol(),OP_BUYSTOP,lot,(MarketInfo(Symbol(),MODE_ASK)+firstpipstep*10*Point)+(pipstep*10*Point*i),0,0,0,"some comment",magicbuy,0,Green);
          if(ticketbuy<=0)
                   Print("Error = ",GetLastError());
          else
                {
                   Print("ticketbuy = ",ticketbuy);
                   while(IsTradeContextBusy())
                   Sleep(2000);           
               
                }   
         
          }}
    //Pending Order sell
    if(TOS<maxpendingorder)
      {
       tradesell=maxpendingorder-TOB;
      }
      else
        {
      return(0);   
        }
    if(OrderCountSell(OP_SELL)==0)
       {
        for(int i=0;i<tradesell;i++)
          {
           int ticketsell=OrderSend(Symbol(),OP_SELLSTOP,lot,(MarketInfo(Symbol(),MODE_BID)-firstpipstep*10*Point)-(pipstep*10*Point*i),0,0,0,"some comment",magicbuy,0,Green);
          if(ticketsell<=0)
                   Print("Error = ",GetLastError());
          else
                {
                   Print("ticketsell = ",ticketsell);
                   while(IsTradeContextBusy())
                   Sleep(2000);           
               
                }   
         
          }
         
       }
     
    
      return(0);
      }
    //+------------------------------------------------------------------+
    //count buy order
    int OrderCountBuy(int order_type) {
       int countb = 0;
       for (int i = OrdersTotal() - 1; i >= 0; i--) {
          if (OrderSelect(i, SELECT_BY_POS))
             if (OrderType() == order_type && OrderMagicNumber() == magicbuy) countb++;
       }
       return (countb);
    }
    //count sell order
    int OrderCountSell(int order_type) {
       int countb = 0;
       for (int i = OrdersTotal() - 1; i >= 0; i--) {
          if (OrderSelect(i, SELECT_BY_POS))
             if (OrderType() == order_type && OrderMagicNumber() == magicsell) countb++;
       }
       return (countb);
    }
    kelemahannya.. saat Pendong Order terbentuk.. ehh.. muncul pending order baru. yang harusnya max=10 pending order(5B 5S).. begitu Buy kesentuh.. muncul lagi 5 Pending Order Sell
     
  19. Oedyne Gwibroed

    Oedyne Gwibroed New Member

    Equity
    Credit
    Ref Point
    1. Coba ente jadi kan stu Magic nya
    2. buat lg deklarasi
    int TOB_1=OrderCountBuy(OP_BUY);
    int TOS_1=OrderCountSell(OP_SELL);
    3. buat if(TOB==0 && TOB_1==0)
    {
    }
    4. buat if(TOS==0 && TOS_1==0)
    {
    }
     
  20. Trancexe

    Trancexe Active Member Credit Hunter

    Equity
    Credit
    Ref Point
    oke di coba.
     

Share This Page