ผมสงสัยอีกนิดครับตอนนี้ผมเขียนตามหลักการที่ท่านสอนได้แล้ว โดยการเปืด Order Pending ทั้ง buystop และ buylimit SellStop SellLimit
ได้ออร์เดอร์ตามต้องการแล้วครับ แต่ว่าทำอย่างไรผมจะ close ออร์เดอร์ที่กำไรไป 5 ออร์เดอร์ และ ขาดทุนเยอะสุด 1ออร์เดอร์ได้ครับ
ผมส่งโค๊ดที่ผมเขียนมาบ้างแล้วมาด้วยครับ
ท่านช่วยชี้แนะผมด้วยนะครับ
ขอบคุณมากมากครับท่าน
//+------------------------------------------------------------------+
//| |
//| Copyright 2018 MetaQuotes Software Corp. |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright ฉ 2017, MetaQuotes Software Corp."
#property link ""
extern string EA_Name = "";
extern int Pip_pendig = 100;
extern double Lots = 0.1;
extern int Pips = 100;
int slippage = 0;
int OpenOrders=0, cnt=0;
int mode=0, myOrderType=0;
double sl=0, tp=0;
double BuyPrice=0, SellPrice=0;
double mylotsi=0;
int OrderBuy, OrderSell;
double Order_Profit,DD;
double LastPriceBuy=0, LastPriceSell=0;
int result, ticket;
bool res, tic;
int order_total;
int cs = 0;
int cbl = 0, cbs = 0;
int csl = 0, css = 0;
double op_sl, op_ss, op_bl, op_bs;
int ticket_sl, ticket_ss;
int ticket_bl, ticket_bs;
double TicketBuy[200];
double TicketSell[200];
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
//------------------------------------------------------------------------------------------------------------------------------
OrderSell=0;
OrderBuy=0;
Order_Profit = 0;
OpenOrders=0;
for(cnt=0;cnt<OrdersTotal();cnt++)
{
int result1 = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()==Symbol())
{
OpenOrders++;
Order_Profit = Order_Profit+OrderProfit();
}
if (OrderSymbol()==Symbol() && OrderType()==OP_SELL)
{
OrderSell++;
LastPriceSell= OrderOpenPrice();
TicketSell[OrderSell] = OrderOpenPrice();
//Print("Ticket Sell #"+OrderSell+" : "+TicketSell[OrderSell]);
}
if (OrderSymbol()==Symbol() && OrderType()==OP_BUY)
{
OrderBuy++;
LastPriceBuy=OrderOpenPrice();
TicketBuy[OrderBuy] = OrderOpenPrice();
//Print("Ticket Buy #"+OrderBuy+" : "+TicketBuy[OrderBuy]);
}
}
//--------------------------------------------------------------------Setting SellLimit Pending-----------------------------------------------
order_total = OrdersTotal();
cs = false;
csl = false;
css = false;
cbl = false;
cbs = false;
for(int i = order_total; i >= 0; i--)
{
if(OrderSelect(i,SELECT_BY_POS) == true && OrderSymbol() == Symbol())
{
if(OrderType() == OP_SELL)
{
cs = true;
}
if(OrderType() == OP_SELLLIMIT)
{
op_sl = NormalizeDouble(OrderOpenPrice(), Digits);
ticket_sl = OrderTicket();
csl = true;
}
if(OrderType() == OP_SELLSTOP)
{
op_ss = NormalizeDouble(OrderOpenPrice(), Digits);
ticket_ss = OrderTicket();
css = true;
}
if(OrderType() == OP_BUYLIMIT)
{
op_bl = NormalizeDouble(OrderOpenPrice(), Digits);
ticket_bl = OrderTicket();
cbl = true;
}
if(OrderType() == OP_BUYSTOP)
{
op_bs = NormalizeDouble(OrderOpenPrice(), Digits);
ticket_bs = OrderTicket();
cbs = true;
}
}
}
//-------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------
//----
Open_order();
return(0);
}
void Open_order()
{
if(cs==false)
{
ticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,2,0,0,"",0,0,clrRed);
ticket = OrderSend(Symbol(),OP_BUY,Lots,Bid,2,0,0,"",0,0,clrBlue);
}
if(csl==false)
{
ticket = OrderSend(Symbol(),OP_SELLLIMIT,Lots,LastPriceSell+Pip_pendig*Point,2,0,0,"",0,0,clrRed);
}
if(css==false)
{
ticket = OrderSend(Symbol(),OP_SELLSTOP,Lots,LastPriceSell-Pip_pendig*Point,2,0,0,"",0,0,clrRed);
}
if(cbl==false)
{
ticket = OrderSend(Symbol(),OP_BUYLIMIT,Lots,LastPriceSell-Pip_pendig*Point,2,0,0,"",0,0,clrBlue);
}
if(cbs==false)
{
ticket = OrderSend(Symbol(),OP_BUYSTOP,Lots,LastPriceSell+Pip_pendig*Point,2,0,0,"",0,0,clrBlue);
}
}
//+------------------------------------------------------------------+//