Open Forex4you Account

Server รัน EA 1000 / ปี

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

Author Topic: รบกวนแอดมินเช็คโค๊ดให้หน่อยครับ  (Read 6291 times)

kiiyoo

  • Newbie
  • *
  • Posts: 49
ผมได้ให้พี่คนหนึ่งเขียนอีเอให้แล้วผมเอามาโมใหม่
แต่แบคเทสแล้วมีบางช่วงที่อีเอปิดออเดอร์เองทั้งๆที่ไม่โดน SL
อยากให้แอดมินช่วยดูให้ทีครับ
extern int TP = 25;
extern double Lots = 0.1;
extern int SL = 20;


int  OpenOrders=0, cnt=0;
int  slippage=2;
double sl=0;
double BuyPrice=0, SellPrice=0;
double lotsi=0, mylotsi=0;
int mode=0;

double M1,M2,cci46,cci42,RSi;
double M11, M21;
double PClose,POpen;

int ticket, order_Type;
datetime openTime, closeTime;
double orderSize, openPrice, closePrice, sf, tf, comm, swap, profit;
string order_Symbol, order_TypeToStr;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   if(MarketInfo("EURUSD",MODE_DIGITS)==5)
   {
      TP =  TP*10;
      SL = SL*10;   
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   int handle;
   
   for(int i=0;i<OrdersHistoryTotal();i++)
     {
         GetHistoryOrder(i,MODE_HISTORY);
         if(order_Type==0)
            order_TypeToStr="buy";
         if(order_Type==1)   
            order_TypeToStr="sell";
         handle=FileOpen("getOrderHistory.csv", FILE_CSV|FILE_READ|FILE_WRITE, ';');
         if(handle>0)
           {
            if(FileSeek(handle,0,SEEK_SET)==true)
               FileWrite(handle, "Order","Open Time","Type","Size","Symbol","Open Price","S/L","T/F","Close Time","Close Price","Comission","Swap","Profit");
            FileSeek(handle, 0, SEEK_END);
            //---- add data to the end of file
            FileWrite(handle, ticket,TimeToStr(openTime,TIME_DATE|TIME_SECONDS),order_TypeToStr, orderSize, order_Symbol, openPrice, sf, tf, TimeToStr(closeTime,TIME_DATE|TIME_SECONDS), comm, swap, profit);
            FileClose(handle);
            handle=0;
           }       
     }


   OpenOrders=0;
   for(cnt=0;cnt<OrdersTotal();cnt++)   
   {
     OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
     if (OrderSymbol()==Symbol())
     {            
          OpenOrders++;
     }
   }     

   M1    =  iMACD(NULL,0,18,39,4,PRICE_CLOSE,MODE_MAIN,0);
 
   M2    =  iMACD(NULL,0,18,39,4,PRICE_CLOSE,MODE_SIGNAL,0);
   
   cci46 =  iCCI(NULL,0,42,PRICE_CLOSE,1);
   
   cci42 =  iCCI(NULL,0,30,PRICE_CLOSE,1);
   
   RSi    =  iRSI(NULL,0,14,PRICE_CLOSE,0);
   

   PClose   = iClose(NULL,0,1);
   POpen    = OrderOpenPrice();
/*   
   Comment  (
             "\nLots = ",Lots,
             "\norderSize = ",orderSize,
             "\nprofit = ",profit);
*/
if (OpenOrders<1)
   {
     if ((M1>M2)&&(M2>0.0003)&&(M2<0.001)&&((RSi>65)||((cci42>150)&&(cci46>150))))
      {   
          SellPrice=Bid;            
          if (SL==0) { sl=0; }
          else { sl=SellPrice+SL*Point;  }
          if (profit>=0) {mylotsi = Lots;}
          else {mylotsi = NormalizeDouble(orderSize*2,1);}
          OrderSend(Symbol(),OP_SELL,mylotsi,SellPrice,slippage,sl,0,NULL,0,0,Red);                   
          return(0);
      }
     
     if ((M1<M2)&&(M2<-0.0003)&&(M2>-0.001)&&((RSi<35)||((cci42<-150)&&(cci46<-150))))
      {
          BuyPrice=Ask;
          if (SL==0)  { sl=0; }
          else { sl=BuyPrice-SL*Point; }
          if (profit>=0) {mylotsi = Lots;}
          else {mylotsi = NormalizeDouble(orderSize*2,1);}
          OrderSend(Symbol(),OP_BUY,mylotsi,BuyPrice,slippage,sl,0,NULL,0,0,Blue);         
          return(0);
      }   
   
   }
//-------------------------------------Cut OrderClose-----------------------------

if(OpenOrders!=0 && PClose-POpen>=TP*Point)
  {
     for(cnt=OrdersTotal();cnt>=0;cnt--)
     {
        OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
          mode=OrderType();
        if (OrderSymbol()==Symbol())
        {
         if (mode==OP_BUY) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Blue); }
        }
     }
  }

if(OpenOrders!=0 && POpen-PClose>=TP*Point)
  {
     for(cnt=OrdersTotal();cnt>=0;cnt--)
     {
        OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
          mode=OrderType();
        if (OrderSymbol()==Symbol())
        {
         if (mode==OP_SELL) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Red); }
        }
     }
  }
//----
   return(0);
  }
//+------------------------------------------------------------------+
void GetHistoryOrder(int count,int mode)
  {
    if(OrderSelect(count, SELECT_BY_POS, mode)==true)
    {
      ticket=OrderTicket();
      order_Type=OrderType();
      openTime=OrderOpenTime();
      closeTime=OrderCloseTime();
      orderSize=OrderLots();
      openPrice=OrderOpenPrice();
      closePrice=OrderClosePrice();
      sf=OrderStopLoss();
      tf=OrderTakeProfit();
      comm=OrderCommission();
      swap=OrderSwap();
      profit=OrderProfit();
      order_Symbol=OrderSymbol();   
    }
    else
      Print("OrderSelect returned the error of ",GetLastError());
  }

admin

  • Administrator
  • Hero Member
  • *****
  • Posts: 2386
Re: รบกวนแอดมินเช็คโค๊ดให้หน่อยครับ
« Reply #1 on: สิงหาคม 18, 2011, 11:50:44 am »
ปิด order เองแบบไม่โดน sl หรือ tp ใช่ไหมครับ ลองดูว่าช่วงที่เราทดสอบถึงบริเวณนั่น magin เราต่ำกว่าที่ทางโบรเกอร์กำหนดหรือเปล่าก่อนนะครับ เพราะโบรเกอน์มันจะตัดเองเลยครับถ้า magin เราต่ำกว่าที่มันกำหนดครับ จาก code ไม่น่าจะมีปัญหาอะไรนะครับลองเช็กส่วนที่ผมบอกไปก่อนครับ

kiiyoo

  • Newbie
  • *
  • Posts: 49
Re: รบกวนแอดมินเช็คโค๊ดให้หน่อยครับ
« Reply #2 on: สิงหาคม 18, 2011, 04:08:08 pm »
ผมเช็คแล้วไม่เกี่ยวกับมาจิ้นครับ
รบกวนแอดมินช่วยเปลี่ยนเงื่อนการปิดออเดอให้หน่อยได้มั้ยครับ
ตอนนี้มันปิดที่SL และปิดเมื่อราคาปิดแท่งมากกว่าที่เรากำหนด
ตอนนี้อยากให้เปลี่ยนท่ปิดที่TPและSL ช่วยแก้ไขให้ด้วยครับ ผมไม่รู้จะแก้โค๊ดยังไง