avatar
Untitled

Guest 9 24th Jun, 2020

CPP 4.67 KB
                                           
                         //+------------------------------------------------------------------+
//|                                                       baiso1.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
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
// NOI KHAI BAO BIEN


      extern double khoiLuong= 0.01;// 0
      double stoploss = 0;
      double takeprofit = 0;
      extern  string ghichu =  "hello";
      color maucualenh = clrRed;
      extern int loaiLenh = OP_BUY;
      double giavaolenh=0;
      datetime thoigiangiaodich;
      bool chophepGD = true;
      int  magic =999;

//+------------------------------------------------------------------+
int OnInit()
  {
//---
  // checkLisicen();
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
     // if(chophepGD == false){return;}
    //  if(OrdersTotal()>0){return;}  // chi cho vao 1 lenh
      if(demsolenh( Symbol() ) >0 ){return;}

      // cho chạy code ben dưới dòng này khi qua nến mới

      if(thoigiangiaodich == iTime(Symbol(),0,0) ){return;}thoigiangiaodich =iTime(Symbol(),0,0) ;
//=====================================================================
// dieu kien vao lenh--------------

     double maxanh1 = iMA(Symbol(),0,5,0,MODE_SMA,PRICE_CLOSE,1);
     double mado1   = iMA(Symbol(),0,20,0,MODE_SMA,PRICE_CLOSE,1);
     double maxanh2 = iMA(Symbol(),0,5,0,MODE_SMA,PRICE_CLOSE,2);
     double mado2   = iMA(Symbol(),0,20,0,MODE_SMA,PRICE_CLOSE,2);
     Comment(maxanh1+"/"+mado1+"//"+maxanh2+"/"+mado2);
     // truong hop cat len tang gia --> buy
     if(maxanh1 > mado1 && maxanh2 < mado2 ){loaiLenh=OP_BUY;}
     if(maxanh1 < mado1 && maxanh2 > mado2 ){loaiLenh=OP_SELL;}
     else {return;}


       //=====================================================
 //--------------------------------
      if(loaiLenh == OP_SELL)
      {
         giavaolenh = Bid;
         stoploss = giavaolenh + 20*10*Point();
         takeprofit = giavaolenh - 60*10*Point();
      }
      if(loaiLenh ==OP_BUY)
      {
         giavaolenh = Ask;
         stoploss = giavaolenh - 20*10*Point();
         takeprofit = giavaolenh + 60*10*Point();
      }

      khoiLuong = dinhdangLot(khoiLuong);

      OrderSend(  Symbol(),loaiLenh,khoiLuong,giavaolenh,20,stoploss,takeprofit,ghichu,magic,0,maucualenh );
  }
//+------------------------------------------------------------------+


//======================================================
void checkLisicen()
{

   if(AccountNumber() != 22629828 ){Alert("khong dung tai khoan");chophepGD= false;}

   if(AccountEquity()  < 1000 ){ Comment("tai khoan qua nho , rui ro cao"); }

   if(IsTradeAllowed() ==false   ){ Alert("hay click vao trade allow");}

}
//==========================================
int demsolenh(string captiencandem)
{
   int dem;
   for(int i = OrdersTotal()-1 ; i>=0; i--)
   {
    if(OrderSelect(i, SELECT_BY_POS)==False)  {continue;}
    if(OrderSymbol() != captiencandem){continue;}
    if(OrderMagicNumber()!= magic){continue;}
        dem ++;// dem dc 1 lenh
   }

return(dem);
}
//====================================
//====================================
double dinhdangLot(double khoiLuong)
{
   if(khoiLuong==0){ khoiLuong = MarketInfo(Symbol(),MODE_MINLOT)   ; }
   if(khoiLuong> MarketInfo(Symbol(),MODE_MAXLOT)){ khoiLuong = MarketInfo(Symbol(),MODE_MAXLOT)   ; }

    khoiLuong = NormalizeDouble(khoiLuong,2);

     return(khoiLuong);// tra ve khoi da duoc dinh dang

}
//+==================================================================+
                      
                                       
To share this paste please copy this url and send to your friends
RAW Paste Data

Comments

Authentication required

You must log in to post a comment.

Log in
    There are no comments yet.