Saturday 23 February 2013

MQL4 Trailing Stop sample code:

MQL4 Trailing Stop sample code:

// YOUR CODE HERE!
extern double TrailingStop = 100;
int MagicNumber = 101090;
//+------------------------------------------------------------------+
int start()
{
int cnt,total;
total = OrdersTotal();
// YOUR CODE HERE!
for(cnt=0;cnt
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) //<-- Long position is opened
{
TrailOrder(OrderType()); return(0); //<-- Trailling the order
}
if(OrderType()==OP_SELL) //<-- Go to short position
{
TrailOrder(OrderType()); return(0); //<-- Trailling the order
}
}

}
return(0);
}
//+------------------------------------------------------------------+
void TrailOrder(int type)
{
if(TrailingStop>0)
{
if(OrderMagicNumber() == MagicNumber)
{
if(type==OP_BUY)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-
Point*TrailingStop,OrderTakeProfit(),0,Green);
}
}
}
if(type==OP_SELL)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) ||
(OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProf
it(),0,Red);
}
}
}
}
}
}


In the code above, we are trailing all the opened positions using thefunction
TrailOrder().
It will go through all the opened positions using a loop that starts from 0 and counts orders returned by OrdersTotal() function.To be certain that we are working with the order of current chart, we will check the Symbol against the selected OrderSymbol. Then, we will call the TrailOrder(), which takes only one parameter; the type of order: OP_SELL or OP_BUY.

TrailOrder() function: 

This is the function that handles the Trailing Stop for us. There are two types of orders: 

Buy order:

In the case of a Buy order, we check that the profit (current Bid price minus the open price) is greater than the Trailing Stop value that we have set (or the user set). We also modify the order to new Stop Loss level, which is equal to the current Bid price minus the Trailing Stop value.

Sell order: 

In the case of Sell order, we check that the profit (the open price minus current Ask price) is greater than the Trailing Stop value that we have set (or the user set). We also modify the order to new Stop Loss level which is equal to the current Ask price plus the Trailing Stop value.

Belajar Membuat EA Sederhana 26 (Otomatik Close)


Belajar Membuat EA Sederhana 26 (Otomatik Close)

http://jumforex.blogspot.com/2013/02/belajar-membuat-ea-sederhana-26.html
Pastikan sudah mengunjungi part 25

Setelah pada part sebelumnya sudah banyak share dan cara membuat Ea berjenis kelamin Martingel...
Kali ini saya lanjutkan dengan membuat Ea sederhana dan cukup profitabel dan model yang saya akan share ini salah satu model dari EA riel saya ......
Ea ini merupakan sedikit dari ngoprek EA pada part 12 disini

ini hasil pada account salah satu frend saya:

Ini Juga baru dimulai hehehe



Pada Ea tersebut akan saya tambahkan close otomatis ketika ada signal yang berlawanan.....


//+------------------------------------------------------------------+
//|                                                 EA Jum MantiQ+   |
//|                                                gifaesa@yahoo.com |
//|                                     http://JumForex.blogspot.com |
//+------------------------------------------------------------------+

#property copyright "JumForex.blogspot.com"
#property link      "Gifaesa@yahoo.com"

extern bool    Trade_buy               = true;
extern bool    Trade_sell              = true;
extern int     Mulai_Jam               = 6;
extern int     Akhir_Jam               = 20;
extern int     TP                      = 0;
extern int     SL                      = 0;
extern double  Lots                    = 0.1;
extern int     TrailingStop            = 40;
extern int     Magic                   = 69;
extern bool    Close_Oto               = true;
extern string  Seting_MA               = "Sesuka Hati";
extern int     Pereode                 = 33;
double slb,tpb,sls,tps,pt,x;
string  Nama_EA   = "Jum+MantiQ";
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   if(Digits==3 || Digits==5) pt=10*Point;   else   pt=Point;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  label();
dtrailing();
//----
double MA2 =iMA(Symbol(),0,Pereode,0,MODE_SMA,PRICE_CLOSE ,2);
double MA1 =iMA(Symbol(),0,Pereode,0,MODE_SMA,PRICE_CLOSE ,1);
int signal;
if(Open[2]<MA2 && Close[2]>MA2 && Open[1]>MA1 && Close[1]>MA1 && Ask>MA1){ signal=1;if(Close_Oto)closeall(1); }// aturan buy
if(Open[2]>MA2 && Close[2]<MA2 && Open[1]<MA1 && Close[1]<MA1 && Bid<MA1){ signal=2;if(Close_Oto)closeall(0); }//aturan sell
if(Jam_trade()==1 && jumlahorder(1)+jumlahorder(0)==0){
   if(SL==0)slb=0;else slb=Ask-SL*pt;
   if(SL==0)sls=0;else sls=Bid+SL*pt;
   if(TP==0)tpb=0;else tpb=Ask+TP*pt;
   if(TP==0)tps=0;else tps=Bid-TP*pt;
  if( Trade_buy  && signal==1) {OrderSend(Symbol(),OP_BUY,NR(Lots),Ask,3,slb, tpb,Nama_EA,Magic,0,Blue);}
  if( Trade_sell && signal==2) {OrderSend(Symbol(),OP_SELL,NR(Lots),Bid,3,sls, tps,Nama_EA,Magic,0,Red);}
 }

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

int Jam_trade()
{
   bool trade = false;
   if(Mulai_Jam > Akhir_Jam){
     if (Hour() >= Mulai_Jam || Hour() < Akhir_Jam) trade = true;
   } else
     if (Hour() >= Mulai_Jam && Hour() < Akhir_Jam) trade = true;

   return (trade);
}

int jumlahorder( int tipe)
{
int total=0;
for(int i=0; i<OrdersTotal(); i++)
  {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic || OrderType()!=tipe) continue;
     total++;
  }

return(total);
}
double NR(double thelot)
{
    double maxlots = MarketInfo(Symbol(), MODE_MAXLOT),
    minilot = MarketInfo(Symbol(), MODE_MINLOT),
    lstep = MarketInfo(Symbol(), MODE_LOTSTEP);
    double lots = lstep * NormalizeDouble(thelot / lstep, 0);
    lots = MathMax(MathMin(maxlots, lots), minilot);
    return (lots);
}

void dtrailing()
{
for(int i=0; i<OrdersTotal(); i++){
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
        if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic ) continue;
        if(OrderType()==OP_BUY)  {
         if(Bid-OrderOpenPrice()>pt*TrailingStop)  {
           if((OrderStopLoss()<Bid-pt*TrailingStop) || (OrderStopLoss()==0)) {
              OrderModify(OrderTicket(),OrderOpenPrice(),Bid-pt*TrailingStop,OrderTakeProfit(),0,Green);
              return(0);
              }
              }
           }
        if(OrderType()==OP_SELL)  {
         if((OrderOpenPrice()-Ask)>(pt*TrailingStop)){
           if(OrderStopLoss()>(Ask+pt*TrailingStop) || (OrderStopLoss()==0)){
              OrderModify(OrderTicket(),OrderOpenPrice(),Ask+pt*TrailingStop,OrderTakeProfit(),0,Red);
              return(0);
              }
              }
           }
     }
 
}
void label()
{
 Comment("\n ",
   "\n ",
   "\n ------------------------------------------------",
   "\n :: =>+Jum+MantiQ<=",
   "\n :: =>JumForex.blogspot.com<=",
   "\n ------------------------------------------------",
   "\n :: Spread                 : ", MarketInfo(Symbol(), MODE_SPREAD),
   "\n :: Leverage               : 1 : ", AccountLeverage(),
   "\n :: Equity                 : ", AccountEquity(),
   "\n :: Jam Server             :", Hour(), ":", Minute(),
   "\n ------------------------------------------------",
   "\n :: >>By: Jum69<<",
   "\n ------------------------------------------------");

}

void closeall(int m)
{
 for (int i = OrdersTotal() - 1; i >= 0; i--) {
  OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
  if (OrderSymbol() != Symbol() || OrderMagicNumber()!=Magic || OrderType()!=m) continue;
  if (OrderType() > 1) OrderDelete(OrderTicket());
  if (OrderType() == 0) OrderClose(OrderTicket(), OrderLots(), Bid, 3, CLR_NONE);
  if (OrderType() == 1)OrderClose(OrderTicket(), OrderLots(), Ask, 3, CLR_NONE);
 }
}


========================================




  • Belajar Membuat EA sederhana part 15
  • Belajar Membuat EA sederhana part 16
  • Belajar Membuat EA sederhana part 17
  • Belajar Membuat EA sederhana part 18
  • Belajar Membuat EA sederhana part 19
  • Belajar Membuat EA sederhana part 20
  • Belajar Membuat EA sederhana part 21
  • Belajar Membuat EA sederhana part 22
  • Belajar Membuat EA sederhana part 23
  • Belajar Membuat EA sederhana part 24
  • Belajar Membuat EA sederhana part 25
  • Belajar Membuat EA sederhana part 26

  • Belajar Membuat EA Sederhana 25 (Cut Switching)


    Belajar Membuat EA Sederhana 25 (Cut Switching)

    http://jumforex.blogspot.com/2013/02/belajar-membuat-ea-sederhana-25-cut.html

    Mungkin sudah pada ngintip di part 24 

    Kali ini kita akan bahas tentang EA model cut switching , saya sih juga gak begitu memahami betul tentang strategy ini tapi yang jelas ini termasuk juga EA martingel tapi untuk kondisi trending.

    Ea ini setelah order maka bila floting negatif maka akan di cut loss dan dilanjutkan dengan order baru dengan arah yang berlawanan dengan memeperhitungkan kelipatan lotsnya

    Nah sebenarnya bisa dibuat dengan beberapa model , tapi kali ini kita akan buat model menggunakan tidak menggunakan pending stop.
    bagian triger digunakan indikator fractals
    Perhatikan cara codingnya:

    for(int d=0; d< Bars ; d++){ double up=iFractals(Symbol(),0,MODE_UPPER,d);     if(up!=0 ) break;} 
    for(int e=0; e< Bars ; e++){ double lo=iFractals(Symbol(),0,MODE_LOWER,e); if( lo!=0) break;} 
    int signal; 
    if(Bid > up) signal=1;// signal buy 
    if(Ask < lo)signal=2;//signal sell 


    Bagian lain yang perlu diperhatikan adalah membaca history orderprofit, ordertype dan magic number




    double trad(int m)

    {
      double pr,op; 
      for (int i = 0; i < OrdersHistoryTotal(); i++) {
       if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
       if (OrderSymbol() != Symbol()/* || OrderComment() != Nama_EA*/) continue;
       if(m==1)pr=OrderProfit();
       if(m==2)pr=OrderType();
       if(m==3)pr=OrderMagicNumber();
       }
    return(pr);
    }

    1. history orderprofit diperlukan untuk mengetahui orderprofit pada order close yang terakhir itu untung ata rugi
    2. history ordertype diperlukan untuk mengetahui type order pada order close yang terakhir itu type buy atau sell
    3. history magicnumber diperlukan untuk mengetahui membatasidan memperhitungkan level order 
    Untuk memperhitungkan perkalian lotsnya digunakan fungsi sbb:

    double xlot()
    {
     double ylot,dlot; 
      for (int i = 0; i < OrdersHistoryTotal(); i++) {
       if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
       if (OrderSymbol() != Symbol()/* || OrderComment() != Nama_EA */) continue;
         dlot=OrderLots();
         }
        ylot=NR(dlot*DiMarti);
    return(ylot);
    }



    Untuk penentuan trigernya saya coba gunakan indikator Fractals


    //+------------------------------------------------------------------+
    //|                                                Jum+switch+.mq4 |
    //|                                                gifaesa@yahoo.com |
    //|                                     http://JumForex.blogspot.com |
    //+------------------------------------------------------------------+

    #property copyright "JumForex.blogspot.com"
    #property link      "Gifaesa@yahoo.com"

    extern string  Target_Equety_          = "Harus lebih besar dari Equety+";
    extern double  Target_Equety           = 1000;
    extern int     Mulai_Jam               = 0;
    extern int     Akhir_Jam               = 20;
    extern int     TP                      = 30;
    extern int     SL                      = 20;
    extern double  Lots                    = 0.01;
    extern int     Max_order               = 12;
    extern double  DiMarti                 = 2;
    extern int     Magic                   = 69;
    string  Nama_EA                 = "Jum+SwitchFractals+";


    double slb,tpb,sls,tps,pt,bal;
    //+------------------------------------------------------------------+
    //| expert initialization function                                   |
    //+------------------------------------------------------------------+
    int init()
      {
    //----
     bal= AccountBalance();
     if(Digits==3 || Digits==5) pt=10*Point;   else   pt=Point;   
    //----
       return(0);
      }
    //+------------------------------------------------------------------+
    //| expert deinitialization function                                 |
    //+------------------------------------------------------------------+
    int deinit()
      {
    //----
    ObjectDelete("j");
    //----
       return(0);
      }
    //+------------------------------------------------------------------+
    //| expert start function                                            |
    //+------------------------------------------------------------------+
    int start()
      {
      if(SL==0||TP==0){Alert(" Isi dulu TP Dan SLnya"); return(0);}
      label();
      if(Target_Equety<AccountEquity()) {
        closeall(0);
        closeall(1);
        Alert("Cek Target_Equetynya salah ");
       return(0);
       }
        for(int d=0; d< Bars  ; d++){
        double up=iFractals(Symbol(),0,MODE_UPPER,d);
        if(up!=0 ) break;}
        for(int e=0; e< Bars  ; e++){
        double lo=iFractals(Symbol(),0,MODE_LOWER,e);
        if( lo!=0) break;}
        int signal;

    if(Bid > up) signal=1;
    if(Ask < lo)signal=2;
    if(Jam_trade()==1 && DayOfWeek()>1){
    if((trad(1)>0) || (trad(1)==0)){  
      if(jumlahorder(0)==0 && jumlahorder(1)==0){
        if(signal==1) {OrderSend(Symbol(),OP_BUY,NR(Lots),Ask,3,Ask-SL*pt, Ask+TP*pt,Nama_EA,Magic,0,Blue);}
        if(signal==2) {OrderSend(Symbol(),OP_SELL,NR(Lots),Bid,3,Bid+SL*pt, Bid-TP*pt,Nama_EA,Magic,0,Red);}
        }
       }
     }
    if(jumlahorder(0)==0 && jumlahorder(1)==0 && trad(3)<Max_order+Magic ){
    if(trad(1)<0 && trad(2)==1) {OrderSend(Symbol(),OP_BUY,xlot(),Ask,3,Ask-SL*pt, Ask+TP*pt,Nama_EA,trad(3)+1,0,Blue);  }
    if(trad(1)<0 && trad(2)==0) {OrderSend(Symbol(),OP_SELL,xlot(),Bid,3,Bid+SL*pt, Bid-TP*pt,Nama_EA,trad(3)+1,0,Red);   }
    }



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

    int Jam_trade()
    {
       bool trade = false;
       if(Mulai_Jam > Akhir_Jam){
         if (Hour() >= Mulai_Jam || Hour() < Akhir_Jam) trade = true;
       } else
         if (Hour() >= Mulai_Jam && Hour() < Akhir_Jam) trade = true;

       return (trade);
    }

    int jumlahorder( int tipe)
    {
    int total=0;
    for(int i=0; i<OrdersTotal(); i++)
      {
          OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
          if(OrderSymbol()!=Symbol() || OrderComment() != Nama_EA || OrderType()!=tipe) continue;
         total++;
      }

    return(total);
    }
    double NR(double thelot)
    {
        double maxlots = MarketInfo(Symbol(), MODE_MAXLOT),
        minilot = MarketInfo(Symbol(), MODE_MINLOT),
        lstep = MarketInfo(Symbol(), MODE_LOTSTEP);
        double lots = lstep * NormalizeDouble(thelot / lstep, 0);
        lots = MathMax(MathMin(maxlots, lots), minilot);
        return (lots);
    }


    void closeall(int m)
    {
     for (int i = OrdersTotal() - 1; i >= 0; i--) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderComment() != Nama_EA ||  OrderType()!=m) continue;
      if (OrderType() > 1) OrderDelete(OrderTicket());
       else {
        if (OrderType() == 0) OrderClose(OrderTicket(), OrderLots(), Bid, 3, CLR_NONE);
        else               OrderClose(OrderTicket(), OrderLots(), Ask, 3, CLR_NONE);
      }
     }
    }
    double money()
    {
     double dp = 0;
     int i;
     for (i = 0; i < OrdersTotal(); i++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol()  || OrderComment() != Nama_EA) continue;
      dp += OrderProfit();
     }
     return(dp);
    }

    double trad(int m)
    {
      double pr,op; 
      for (int i = 0; i < OrdersHistoryTotal(); i++) {
       if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
       if (OrderSymbol() != Symbol()/* || OrderComment() != Nama_EA*/) continue;
       if(m==1)pr=OrderProfit();
       if(m==2)pr=OrderType();
       if(m==3)pr=OrderMagicNumber();
       }
    return(pr);
    }
    double xlot()
    {
     double ylot,dlot; 
      for (int i = 0; i < OrdersHistoryTotal(); i++) {
       if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
       if (OrderSymbol() != Symbol()/* || OrderComment() != Nama_EA */) continue;
         dlot=OrderLots();
         }
        ylot=NR(dlot*DiMarti);
    return(ylot);
    }
    void label()
    {
       ObjectCreate("j",OBJ_LABEL,0,0,0);
       ObjectSet("j",OBJPROP_CORNER,4);
       ObjectSet("j",OBJPROP_XDISTANCE,10);
       ObjectSet("j",OBJPROP_YDISTANCE,10);
       ObjectSetText("j","Jum+switchFractals from : JumForex.blogspot.com ",21,"Mistral",Aqua);
     Comment("\n ",
       "\n ",
       "\n ------------------------------------------------",
       "\n :: Spread                 : ", MarketInfo(Symbol(), MODE_SPREAD),
       "\n :: Leverage               : 1 : ", AccountLeverage(),
       "\n :: Jam Server             :", Hour(), ":", Minute(),
       "\n ------------------------------------------------",
       "\n :: Equity sekarang        : ", AccountEquity(),"  $",
       "\n :: Target_Equety          : ", Target_Equety ,"  $",
       "\n ------------------------------------------------",
       "\n :: Posisi floting         :",money(),"  $",
       "\n :: Level                  :",trad(3)-Magic,
       "\n ------------------------------------------------",
       "\n :: >>By: Jum69<<",
       "\n ------------------------------------------------");
    //+------------------------------------------------------------------+
    }




    Nah  begini  testnya:



    Okey silahkan di test dan mudaha2an bisa digunakan untuk mendia belajar

    Belajar Membuat EA Sederhana 24 (Martingel trending)


    Belajar Membuat EA Sederhana 24 (Martingel trending)

    http://jumforex.blogspot.com/2013/02/belajar-membuat-ea-sederhana-24.html

    Okey bro semuanya pada kesempatan kali ini saya akan coba 
    mengoprek   ea pada part 22 
    Tipenya Ea  martingel tapi ini sedikit berbeda dengan tipe martingel  yang sudah ada yaitu martingel yang cocok untuk kondisi trending , biasanya martingel yang umumnya adalah takut terhadap kondisi trending .

    Ini sebenarnya ada sedikit memenuhi permintaan dari rekan2 yang sudah 2 orang menhubungi ym dan email saya tentang ea ini.

    Pada ea part 22 ini merupakan ea jebakan dimana order pertamanya mengunakan pending stop dan bila pending stop sudah tersentuh maka akan dilanjutkan dengan martingel bila ternyata mengalami floting pada jarak tertentu dan martingel nya adalah satu arah
    Nah pada part 24 ini kita akan gunakan martingelnya adalah 2 arah (hedge ) dengan mengunakan pending stop.
    Ordernya saya akan mengacu pada jam trending dan indikator yang sederhan yaitu candel 
    Karena ini ea untuk trending saya tambahkan filter untuk hari senin = notrade (DayOfWeek()!=1)

    Rulenya sederhana aja
    bila candel bullis maka buy dan bila floting minus pada jarak tertentu pasang sellstop
    bila ternyata sellstop tersentuh maka akan pasang buystop .
    Take profit mengacu pada tp in money alias pada $.

    Simpel deh....!

    Ini Hasilnya :


    //+------------------------------------------------------------------+
    //|                                                    EA Jum+SmaRt |
    //|                                                gifaesa@yahoo.com |
    //|                                     http://JumForex.blogspot.com |
    //+------------------------------------------------------------------+

    #property copyright "JumForex.blogspot.com"
    #property link      "Gifaesa@yahoo.com"

    extern string  SmaRt_Marti             = "Trending EA";
    extern string  Jam_server              = "Set sesuai selera";
    extern int     Mulai_Jam               = 6;
    extern int     Akhir_Jam               = 20;
    extern bool    Tp_in_Money             = true;
    extern double  TP_in_money             = 10;
    extern int     Max_order               = 10;
    extern int     Jarak_stop              = 15;
    extern double  DiMarti                 = 1.5;
    extern int     TP                      = 0;
    extern int     SL                      = 0;
    extern double  Lots                    = 0.1;
    extern int     Magic                   = 69;
    double slb,tpb,sls,tps,pt,lslb,ltpb,slbx,tpbx,slsx,tpsx;
    string  Nama_EA                 = "Jum+SmaRt";

    //+------------------------------------------------------------------+
    //| expert initialization function                                   |
    //+------------------------------------------------------------------+
    int init()
      {
    //----
       if(Digits==3 || Digits==5) pt=10*Point;   else   pt=Point;
    //----
       return(0);
      }
    //+------------------------------------------------------------------+
    //| expert deinitialization function                                 |
    //+------------------------------------------------------------------+
    int deinit()
      {
    //----

    //----
       return(0);
      }
    //+------------------------------------------------------------------+
    //| expert start function                                            |
    //+------------------------------------------------------------------+
    int start()
      {
    label();
    if(Tp_in_Money ){
      if(TP_in_money<= money(0)+money(1)){
       closeall(0);
       closeall(1);
       closeall(4);
       closeall(5);
       }
     }
    if(jumlahorder(0)+ jumlahorder(1)==0){
      if(jumlahorder(4)==1 ||jumlahorder(5)==1){
       closeall(4);
       closeall(5);
       }
     }
     
       if(SL==0)slbx=0;else slbx=Ask-SL*pt;
       if(SL==0)slsx=0;else slsx=Bid+SL*pt;
       if(TP==0)tpbx=0;else tpbx=Ask+TP*pt;
       if(TP==0)tpsx=0;else tpsx=Bid-TP*pt;
     
    if(DayOfWeek()!=1 && Jam_trade()==1 && jumlahorder(0)==0 && jumlahorder(1)==0){
      if(Open[1]<Close[1] ) {OrderSend(Symbol(),0,NR(Lots),Ask,3,slbx, tpbx,Nama_EA,Magic,0,Blue);}
      if(Open[1]>Close[1] ) {OrderSend(Symbol(),1,NR(Lots),Bid,3,slsx, tpsx,Nama_EA,Magic,0,Red);}
     }
       double as=oppric()+Jarak_stop*pt;
       double bi=oppric()-Jarak_stop*pt;
       if(SL==0)slb=0;else slb=as-SL*pt;
       if(SL==0)sls=0;else sls=bi+SL*pt;
       if(TP==0)tpb=0;else tpb=as+TP*pt;
       if(TP==0)tps=0;else tps=bi-TP*pt;

    if(jumlahorder(0)+jumlahorder(1)>0 && jumlahorder(0)+jumlahorder(1)<Max_order){
     if(opakhir()==1 && jumlahorder(4)==0 ) {OrderSend(Symbol(),OP_BUYSTOP,xlot(),as,3,slb, tpb,Nama_EA,Magic,0,Blue);}
     if(opakhir()==0 && jumlahorder(5)==0 ) {OrderSend(Symbol(),OP_SELLSTOP,xlot(),bi,3,sls, tps,Nama_EA,Magic,0,Red);}
     }
       return(0);
      }
    //+------------------------------------------------------------------+

    int jumlahorder( int tipe)
    {
    int total=0;
    for(int i=0; i<OrdersTotal(); i++)
      {
          OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
          if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic || OrderType()!=tipe) continue;
         total++;
      }

    return(total);
    }
    double NR(double thelot)
    {
        double maxlots = MarketInfo(Symbol(), MODE_MAXLOT),
        minilot = MarketInfo(Symbol(), MODE_MINLOT),
        lstep = MarketInfo(Symbol(), MODE_LOTSTEP);
        double lots = lstep * NormalizeDouble(thelot / lstep, 0);
        lots = MathMax(MathMin(maxlots, lots), minilot);
        return (lots);
    }


    void closeall(int m)
    {
     for (int i = OrdersTotal() - 1; i >= 0; i--) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber()!=Magic /*|| m!= OrderType()*/) continue;
      if (OrderType() == m) OrderDelete(OrderTicket());
      if (OrderType() == m) OrderDelete(OrderTicket());
      if (OrderType() == m) OrderClose(OrderTicket(), OrderLots(), Bid, 3, CLR_NONE);
      if (OrderType() == m)OrderClose(OrderTicket(), OrderLots(), Ask, 3, CLR_NONE);
     }
    }
    double money(int m)
    {
     double dp = 0;
     for (int i = 0; i < OrdersTotal(); i++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol()  || OrderMagicNumber()!=Magic || m!=OrderType()) continue;
      dp += OrderProfit();
     }
     return(dp);
    }

    void label()
    {
     Comment("\n ",
       "\n ",
       "\n ------------------------------------------------",
       "\n :: =>+Jum+SmaRt<=",
       "\n :: =>JumForex.blogspot.com<=",
       "\n ------------------------------------------------",
       "\n :: Spread                 : ", MarketInfo(Symbol(), MODE_SPREAD),
       "\n :: Leverage               : 1 : ", AccountLeverage(),
       "\n :: Equity                 : ", AccountEquity(),
       "\n :: Jam Server             :", Hour(), ":", Minute(),
       "\n ------------------------------------------------",
       "\n :: Floting                : ",money(0)+money(1),
       "\n :: Level                  : ",jumlahorder(0)+jumlahorder(1),
       "\n ------------------------------------------------",
       "\n :: >>By: Jum69<<",
       "\n ------------------------------------------------");
    }
    double oppric()
    {
     int type; double op;
      for (int i = 0; i < OrdersTotal(); i++) {
       if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
       if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
         type=OrderType();
       if(type==0 || type==1)op = OrderOpenPrice();
      }
    return(op);
    }
    int opakhir()
    {
      int type; int a;
      for (int i = 0; i < OrdersTotal(); i++) {
       if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
       if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
       type=OrderType();
       if(type==0 )a = 0;
       if(type==1 )a = 1;
      }
    return(a);
    }

    double xlot()
    {
     int m=jumlahorder(0)+jumlahorder(1);
     double ylot=NR(Lots*MathPow(DiMarti,m));
    return(ylot);
    }
    int Jam_trade()
    {
       bool trade = false;
       if(Mulai_Jam > Akhir_Jam){
         if (Hour() >= Mulai_Jam || Hour() < Akhir_Jam) trade = true;
       } else
         if (Hour() >= Mulai_Jam && Hour() < Akhir_Jam) trade = true;

       return (trade);
    }



    Disini tidak saya uraikan secara rinci
    Bila ada yang belum jelas silahkan dikasih comment ya

    Pastikan mengikuti:




  • Belajar Membuat EA sederhana part 1
  • Belajar Membuat EA sederhana part 2
  • Belajar Membuat EA sederhana part 3
  • Belajar Membuat EA sederhana part 4
  • Belajar Membuat EA sederhana part 5
  • Belajar Membuat EA sederhana part 6
  • Belajar Membuat EA sederhana part 7
  • Belajar Membuat EA sederhana part 8
  • Belajar Membuat EA sederhana part 9
  • Belajar Membuat EA sederhana part 10
  • Belajar Membuat EA sederhana part 11
  • Belajar Membuat EA sederhana part 12
  • Belajar Membuat EA sederhana part 13
  • Belajar Membuat EA sederhana part 14
  • Belajar Membuat EA sederhana part 15
  • Belajar Membuat EA sederhana part 16
  • Belajar Membuat EA sederhana part 17
  • Belajar Membuat EA sederhana part 18
  • Belajar Membuat EA sederhana part 19
  • Belajar Membuat EA sederhana part 20
  • Belajar Membuat EA sederhana part 21
  • Belajar Membuat EA sederhana part 22
  • Belajar Membuat EA sederhana part 23
  • Belajar Membuat EA sederhana part 24
  • Belajar Membuat EA sederhana part 25
  • Saturday 9 February 2013

    Two Things Every Forex Trader Ought To Know About MT4 Scripts


    Some things you should know about Metatrader Scripts 
    Running a MT4 script is easy. Simply double click the Metatrader script or drop it on the chart of your choice.

    Confirmation (or lack of it) 
    property show_confirm
    Unless a particular property called show_confirm is set within the MT4 Script's code, after double clicking your script within the MT4 Navigator pane, the script will run immediately. If you want to run your MT4 script immediately, you don't need to do anything special. 

    If you wish to add a confirmation box (example show_confirm picture above) to your MT4 script when it runs so that you don't accidentally undo the work of several months in a single double click, copy the code below into the top section of your MT4 script.  To comment out the line put two double forward slashes // in front of the # sign. The property for adding a confirmation box after double clicking a MT4 script is listed below:
    #property show_confirm  // comment out this line to eliminate the confirmation box

    Editing Inputs 
    property show_inputs
    By default in a MT4 script, there are no editable inputs from the Metatrader terminal. There is an exception that can be added to a MT4 script if you would like to have a box pop up that includes the inputs after you double click before the script runs. It is the show_inputs property and use of this property disables the show_confirm property. You can include this property as follows:
    #property show_inputs // comment out this line to eliminate showing inputs

    Unlike an MT4 indicator or expert advisor where you can edit the inputs by right clicking on your forex chart, with MT4 scripts, you may need to get your hands dirty and edit the code if you aren't using the show_inputs property in your MT4 script.

    If you wish to edit inputs for a particular script (if it has inputs) then you will need to right click on the script from the Navigator window and select Modify.Once the MetaEditor opens up you will see something like the following snippet. The thing to keep in mind is that the editable inputs are placed BEFORE the int start() function. In the code below, editable inputs include Lots, stoploss, takeprofit, Slippage and MagicNumber.
    #property show_confirm  // comment out this line to eliminate the confirmation box
    // #property show_inputs // comment out this line to eliminate showing inputs
    //+------------------------------------------------------------------+
    //| script program start function                                    |
    //+------------------------------------------------------------------+
    // edit these values as desired below:
    extern double Lots =             0.01;
    extern int stoploss =            20;
    extern int takeprofit =          30;
    extern int Slippage =            7;
    extern int MagicNumber =         0;

    int start()
      {
    //----
    Tip:
    To make a confirmation box pop up every time you double click a MT4 script or drop a script on a chart to run, simply comment out the line #property show_confirm and uncomment the line // #property show_inputs and you will be able to see and edit the inputs from within Metatrader! Shown below:
    // #property show_confirm  // comment out this line to eliminate the MT4 confirmation box
    #property show_inputs // comment out this line to eliminate showing inputs


    Variable Type
    One final thing to keep in mind is the variable type. Lots is declared as double: 
    extern double Lots =             0.01;
       

    As a result, you will need to make sure to enter your numbers as a double type. Best practice states that the double type requires a decimal place in MQL4. If you wanted to trade a 1 lot, you would write it as 1.0 and not as simply 1 within the MQL4 code. The int type can't handle decimals, so make sure to leave those out when declaring Slippage, for instance.

    If you enjoyed this MT4 help tutorial, you might also enjoy reading a MQL4 Code Tutorial for Metatrader. Every trader needs to learn at least some MQL4 in order to perform the simple operations of modifying code inputs, commenting out a line of code and understanding how to read the code to know if it is executing your MT4 IndicatorsMetatrader expert advisors and MT4 scripts properly.