Open Forex4you Account

Server รัน EA 1000 / ปี

สั่งชื้อคู่มือการโปรแรกม MQL4

Author Topic: อยากใ้ห้มันเบิ้ลล็อตครับ  (Read 9954 times)

be

  • Newbie
  • *
  • Posts: 32
อยากใ้ห้มันเบิ้ลล็อตครับ
« on: เมษายน 28, 2013, 04:42:11 am »
คือ ผมอยากได้ ea แบบนี้อะครับ
1.ให้มันเทรดแค่วันละครั้ง
2.ถ้าขาดทุนในวันแรก ให้เบิ้ลล็อตใันวันที่ 2 ไปเรื่อยๆ จนครบ 6 วัน ให้หยุด ถ้ายังไม่ได้กำไรให้ไปเริ่มต้นใหม่

ผมพยายามหา code เบิ้ลล็อต ก็ไปเจอกระทู้นี้ http://www.thaiforexea.com/index.php/topic,880.0.html

ผมเลยลองเอามาเขียนดู ปรากฏว่าผมทำไงก็ทำไม่ได้ รบกวนช่วยดูให้หน่อยครับ ว่ามันผิดตรงไหน แล้วถ้าผมต้องการแบบเงื่อนไขด้านบน ผมต้องเขียนยังไงครับ

code ที่เขียนเป็นแบบนี้ครับ


ขอบคุณครับ



extern double Lots=0.1;
extern double StartHours = 7;
extern double EndHours = 9;

int start()
{     
int type;
int count=0;

   int  total2 = OrdersHistoryTotal();
      for (int po = total2-1; po >=0; po--)
      {
         OrderSelect( po, SELECT_BY_POS, MODE_HISTORY );
         
               if ( OrderType()== OP_BUY )
               {
                  if ( iBarShift(Symbol(),0,OrderCloseTime()) == 0 )
                  {
                   
                     count++;
                  }
             
               }
             
               else if ( OrderType()== OP_SELL )
               {
                  if ( iBarShift(Symbol(),0,OrderCloseTime()) == 0 )
                  {
                   
                     count++;
                  }
               }
             
         
            }
       
     
if (count>0) return(0);



 
if ((Hour()>StartHours)&&(Hour()<EndHours))
 
  {
 
   
   
 
 
  OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);
   double lastlots=OrderLots();
   double lastprofit=OrderProfit();
   }
   
   double martingale=2;
   {
   if (lastprofit>0||lastprofit==0)
    {double lots = 0.01
     }

if (lastprofit<0)
    {double lots  = lastlots * martingale
     }
if(OrdersTotal()< 1)
     
  {
 
  OrderSend(Symbol(),OP_BUY,lots,Ask,3,Ask-200*Point,Ask+200*Point,"My order",123,0,Green);
   
  }
 
}
 
     
}
 }
return(0);




veronika

  • Newbie
  • *
  • Posts: 44
Re: อยากใ้ห้มันเบิ้ลล็อตครับ
« Reply #1 on: เมษายน 28, 2013, 05:59:45 pm »
Code: [Select]
     for(i=0;i<OrdersTotal();i++){
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA){
            if(OrderType()==OP_SELL){  <<< เบิ้ลฝั่งไหน Buy หรือ sell
            LS =OrderLots();
            }
         }
      }
      Lot1 = NormalizeDouble(LS*2,3); <<<<<<<<< เบิ่ลกี่เท่า ใส่ไป 2 หรือ 3 เท่า
      Lot2 = MathCeil(Lot1*100); <<<<<<<<< ปัดเศษขึ้น ถ้าไม่ปัดก็เอาตรงนี้ออก
      Lot = Lot2*0.01;
   }                
   return(Lot);
ใช้ประมาณนี้ครับ

be

  • Newbie
  • *
  • Posts: 32
Re: อยากใ้ห้มันเบิ้ลล็อตครับ
« Reply #2 on: เมษายน 28, 2013, 06:17:16 pm »
Code: [Select]
     for(i=0;i<OrdersTotal();i++){
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA){
            if(OrderType()==OP_SELL){  <<< เบิ้ลฝั่งไหน Buy หรือ sell
            LS =OrderLots();
            }
         }
      }
      Lot1 = NormalizeDouble(LS*2,3); <<<<<<<<< เบิ่ลกี่เท่า ใส่ไป 2 หรือ 3 เท่า
      Lot2 = MathCeil(Lot1*100); <<<<<<<<< ปัดเศษขึ้น ถ้าไม่ปัดก็เอาตรงนี้ออก
      Lot = Lot2*0.01;
   }                
   return(Lot);
ใช้ประมาณนี้ครับ

ขอบคุณครับ แต่ผมยังมึนอยู่เลยครับ
รบกวนเขียนเป็นตัวอย่างแบบง่ายๆ เช่น เล่น buy ฝั่งเดียวให้ผมดูหน่อยได้ไหมครับ เอาแบบที่ compile ผ่าน แบบตั้งแต่ต้นจนจบ
ผมจะลองเอาไปศึกษาดูก่อนอะครับ

ขอบคุณครับ

veronika

  • Newbie
  • *
  • Posts: 44
Re: อยากใ้ห้มันเบิ้ลล็อตครับ
« Reply #3 on: เมษายน 29, 2013, 03:58:29 am »
เอาแบบนี้เลยมั้ยครับ? เอา code ผมไปดูบางส่วน ** ผมให้ทั้งหมดไม่ได้หรอกครับ ^^

Code: [Select]
extern int MAGICMA = 0;
extern bool UseLotsOptimized = true;
extern double Risk = 0.1;
extern double MinLots = 0.01;
extern double MaxLots = 10000.00;

Code: [Select]
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                            |
//+------------------------------------------------------------------+
double LotsOptimized()
  {
   int i;
   double Lot,Lot1,Lot2,LB,LS;             
//---- select lot size
   if(UseLotsOptimized==false) Lot=MinLots;
//----
   if(UseLotsOptimized==true){ 
         if(Digits==2 || Digits==3){
            Lot1=NormalizeDouble(((AccountEquity()*Risk)/850)*0.01,3);
            Lot2 = MathFloor(Lot1*100);
            Lot = Lot2*0.01;
         }
         if(Digits==4 || Digits==5){
            Lot1=NormalizeDouble(((AccountEquity()*Risk)/850)*0.01,3);
            Lot2 = MathFloor(Lot1*100);
            Lot = Lot2*0.01;
         }     
   }
//---- return lot size
   if(Lot<MinLots) Lot=MinLots;
   return(Lot);
  }

Code: [Select]
//+------------------------------------------------------------------+
//| Calculate optimal lotdynamic Buy size                        |
//+------------------------------------------------------------------+
double LotsDynamicBuy()
  {
   int i;
   double Lot,LB,Lot1,Lot2;
   double Ml,Mlx,Mly,Mlz; 
 
      if(Digits==2 || Digits==3){
         Ml = CountBuy();
         Mlx = NormalizeDouble((Ml-1)*0.1,3);
         Mly = MathCeil(Mlx*100);
         Mlz = 1.25+Mly*0.01;
      }
      if(Digits==4 || Digits==5){
         Ml = CountBuy();
         Mlx = NormalizeDouble((Ml-1)*0.1,3);
         Mly = MathCeil(Mlx*100);
         Mlz = 1.25+Mly*0.01;
      }
   
//----
   if(CountBuy()>=1){
      for(i=0;i<OrdersTotal();i++){
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA){
            if(OrderType()==OP_BUY){
            LB =OrderLots();
            }
      }
   }
      Lot1 = NormalizeDouble(LB*Mlz,3);
      Lot2 = MathCeil(Lot1*100);
      Lot = Lot2*0.01;
   }               
//---- return lot size
   if(Lot>MaxLots)Lot=MaxLots;
   return(Lot);
  }

Code: [Select]
//+------------------------------------------------------------------+
//| Count Buy Order                                                         |
//+------------------------------------------------------------------+
int CountBuy()
  {
   int buys=0;
//----
   if(OrdersTotal()==0) buys=0;
   else {
      for(int i=0;i<OrdersTotal();i++){
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
           {
            if(OrderType()==OP_BUY)  buys++;
           }
      }
   }
//----
   if(buys>0) return(buys);
  }

Code: [Select]
void CheckForOpen()
  {
   int i,res;
   int countbuy;
   
   countbuy = CountBuy()+1;     

         if(OrdersTotal()==0 || CountBuy()==0){
               res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,CommentEA+"-Buy-:"+countbuy,MAGICMA,0,Lime);
               return;
         }
   }

Code: [Select]
int start()
  {
      if(CountBuy()==0 || CountSell()==0){
      CheckForOpen();
      }
//----
  }

อันนี้ก็มีคำอธิบายอยู่ในตัวของมันแล้ว ถ้าคุณยังไม่เข้าใจ ผมแนะนำให้คุณไปศึกษา พื้นฐานการเขียนโปรแกรมให้แน่นกว่านี้อีกซักหน่อยจะดีกว่านะครับ ^^
ผมคงช่วยได้แค่นี้

veronika

  • Newbie
  • *
  • Posts: 44
Re: อยากใ้ห้มันเบิ้ลล็อตครับ
« Reply #4 on: เมษายน 29, 2013, 04:03:26 am »
อ่อ ลืมๆ อีกอัน อันนี้เอา Lots ที่คูณเข้ามาใช้งาน ตัวอย่างประมาณนี้

Code: [Select]
//+------------------------------------------------------------------+
//| Check for open Buy Order Level Conditions                        |
//+------------------------------------------------------------------+
void CheckForOpenLimitLevelBuy()
  {
   int i,res;
   double PBuy,OBuy;
   int countbuy,CountBuy2;

   countbuy = CountBuy()+1;
     
   CountBuy2=0;
   if(CountBuy()<=1) CountBuy2=0;
//--------------
   if(CountBuyLimit()==0 && CountBuy()<=MaxOrder-1){
      for(i=0;i<=OrdersTotal();i++){
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA){
            if(OrderType()==OP_BUY){
            PBuy = OrderOpenPrice();
            }
         }
      }
   //----
      OBuy = PBuy-0.002; <<<< ตรงนี้ให้ใส่ตำแหน่งที่ต้องการเปิด panding order   
      res=OrderSend(Symbol(),OP_BUYLIMIT,LotsDynamicBuy(),OBuy,3,0,0,CommentEA+"-Buy-:"+countbuy,MAGICMA,0,Lime);
      return;
   }         
}

เช็คตำแหน่งจาก order ล่าสุด และตั้ง limit ไว้ ถ้าไม่ใช้ limit ก็ให้ใส่เงื่อนไขอื่นเอา
เช่น

if(Ask == OBuy ){
res=OrderSend(Symbol(),OP_BUY,LotsDynamicBuy(),OBuy,3,0,0,CommentEA+"-Buy-:"+countbuy,MAGICMA,0,Lime);
      return;
}

ประมาณนี้ครับ ^^ น่าจะเข้าใจนะ

be

  • Newbie
  • *
  • Posts: 32
Re: อยากใ้ห้มันเบิ้ลล็อตครับ
« Reply #5 on: เมษายน 29, 2013, 07:54:10 am »
ขอบคุณครับ ผมจะลองเอาไปศึกษาดูครับ