Open Forex4you Account

Server รัน EA 1000 / ปี

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

Author Topic: ขอให้ช่วยแก้ทีครับ  (Read 7916 times)

BenooB

  • Newbie
  • *
  • Posts: 26
ขอให้ช่วยแก้ทีครับ
« on: มิถุนายน 04, 2011, 12:59:01 am »
จากที่ถามไปคราวก่อนลองไปทำ EA fxdoublelots ของตัวเอง พบว่ามีปัญหาคือราคาที่ได้ะค่อนข้าง vary แล้วผมไม่สามารถแก้การซื้อเป็น buylimit ได้ เลยมาขอ admin ช่วยแก้ครับ


int start()
  {
double startlot = 0.1;
double lot;
double lastprice;
double type; //buy =0 , sell = 1 //
double total = OrdersTotal();
double pc = iClose(NULL,0,1);
int ticket;
//----
   {
   OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES);
   lot = OrderLots();
   lastprice = OrderOpenPrice();
   type = OrderType();
   }
if ((total == 0) && (iRSI(NULL,0,14,PRICE_CLOSE,1)>50))
            {
            ticket=OrderSend(Symbol(),OP_BUY,startlot,Ask,3,0,0,"buy start",0,0,Green);
            OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
            }
if ((total == 0) && (iRSI(NULL,0,14,PRICE_CLOSE,1)<50))
            {
            ticket=OrderSend(Symbol(),OP_SELL,startlot,Bid,3,0,0,"sell start",0,0,Red);
            OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
            }
if (total > 0)
   {
//// doublelot ///  
   if ((type == 0) && ((lastprice - pc) > (25 * Point)) && (lot <= 0.8))
      {
            ticket=OrderSend(Symbol(),OP_BUY,lot*2,Ask,3,0,0,"buy",0,0,Green);
            OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);     
      }
   if ((type == 1) && ((pc - lastprice) > (25 * Point)) && (lot <= 0.8))
      {
            ticket=OrderSend(Symbol(),OP_SELL,lot*2,Bid,3,0,0,"sell",0,0,Red);
            OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);     
      }

ส่วนนี้อยากแก้เป็น ซื้อแล้ววาง buylimit รอถ้าไม่มี buylimit ให้วางอันต่อ แต่ผม check buylimit อันล่าสุดไม่เป็น (lot , size , ....)
//// close all take profit ///      
   if ((type == 0) && ((pc - lastprice) > (25 * Point)) )
      {
      CloseAll();
      }
   if ((type == 1) && ((lastprice - pc) > (25 * Point)) )
      {
      CloseAll();
      }
//// close all stop lose ////
   if ((type == 0) && ((lastprice - pc) > (25 * Point)) && (lot >= 0.8))
      {
      CloseAll();
      }
   if ((type == 1) && ((pc - lastprice) > (25 * Point)) && (lot >= 0.8))
      {
      CloseAll();

      }      
   }                                    
//----
   return(0);
  }
void CloseAll()
{     while(OrdersTotal()>0)
     {
        for(int i=0;i<OrdersTotal();i++)
          {  
            OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
            int type   = OrderType();
            bool result = false;
        switch(type)
          {
        
          case OP_BUY  : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),3,Pink);
                         break;    
          case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Pink);
                         break;
          case OP_BUYSTOP  : result = OrderDelete(OrderTicket());
                         break;    
          case OP_SELLSTOP : result = OrderDelete(OrderTicket());
                        break;
          case OP_BUYLIMIT  : result = OrderDelete(OrderTicket());
                         break;    
          case OP_SELLLIMIT : result = OrderDelete(OrderTicket());
          }
      }
   }
}  
« Last Edit: มิถุนายน 04, 2011, 01:09:11 am by BenooB »

BenooB

  • Newbie
  • *
  • Posts: 26
Re: ขอให้ช่วยแก้ทีครับ
« Reply #1 on: มิถุนายน 04, 2011, 08:34:05 am »
   {
   OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES);
   lot = OrderLots();
   lastprice = OrderOpenPrice();
   type = OrderType();
   }


ที่ไม่สามารถเขียนได้เท่าที่ดูน่าจะเพราะค่าที่ได้ทั้งงหมดเป็นของ OP_Buy

คิดว่าถ้าเขียนคำสั่งเพื่อตรวจสอบค่าจำนวน lots ล่าสุดของ OP_BUYLIMIT ว่าเปลี่ยนเป็น  OP_BUY หรือยัง
ถ้าไม่มี buylimit ก็เปิดเพิ่ม
ขอให้ admin ช่วยเขียนคำสั่ในการตรวจ buylimit ทีครับ


ขอบคุณครับ

BenooB

  • Newbie
  • *
  • Posts: 26
Re: ขอให้ช่วยแก้ทีครับ
« Reply #2 on: มิถุนายน 04, 2011, 09:28:41 pm »
ขออีกข้อครับ ไม่มีคนตอบซะที อันนีเขียนแบบ ukhunter ทำไมไม่ซื้อขายเลยครับ

int start()
  {
//----
double startlot = 0.1;
double lot;
double profit;
double type; //buy =0 , sell = 1 //
double total = OrdersTotal();
double pc = iClose(NULL,0,1);
double range = (40 * Point);
int ticket;
//----
   {
   OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);
   lot = OrderLots();
   type = OrderType();
   profit = OrderProfit();
   }
//---   
//if () && ()////////// lot = 0 sleep /////
  //{
  //}
//---
if ((total == 0) && (profit > 0) && (iRSI(NULL,0,14,PRICE_CLOSE,1)>50))
            {
            ticket=OrderSend(Symbol(),OP_BUY,startlot,Ask,3,Ask - range,Ask + range,"buy start",0,0,Green);
            OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
            }
if ((total == 0) && (profit > 0)  && (iRSI(NULL,0,14,PRICE_CLOSE,1)<50))
            {
            ticket=OrderSend(Symbol(),OP_SELL,startlot,Bid,3,Bid + range,Bid - range,"sell start",0,0,Red);
            OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
            }   
//----
//// ble dis way ///
if ((total == 0) && (profit < 0))
            {
            if (type == 0)       /// last = buy change to sell ///
                  {
                  ticket=OrderSend(Symbol(),OP_SELL,(lot * 2),Bid,3,Bid + range,Bid - range,"sell",0,0,Red);
                  OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
                  }
            if (type == 1)       /// last = sell change to buy ///
                  {
                  ticket=OrderSend(Symbol(),OP_BUY,(lot * 2),Ask,3,Ask - range,Ask + range,"buy",0,0,Green);
                  OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);                 
                  }
            }
/////           
   return(0);
  }

admin

  • Administrator
  • Hero Member
  • *****
  • Posts: 2386
Re: ขอให้ช่วยแก้ทีครับ
« Reply #3 on: มิถุนายน 04, 2011, 09:56:43 pm »
   {
   OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES);
 if(OrderType()==OP_BUY)
{
   lot = OrderLots();
   lastprice = OrderOpenPrice();
   type = OrderType();
}
   }

ใส่เงื่อนไขตรวจสอบชนิด order เข้าไปก็จะได้ค่าที่ต้องการของ OP_BUY แล้วครับ

ถ้าเป้นเรื่องการตรวจสอบว่า pending เปลี่ยนเป็น buy หรือ sell ลองดูกระทู้นี้ครับ http://www.thaiforexea.com/index.php/topic,1065.msg5267  เป็นแนวทางได้ครับ
« Last Edit: มิถุนายน 04, 2011, 10:08:29 pm by admin »