ผมลองไปอ่านหลายๆ กระทู้ ใน บอร์ด ดูแล้วลองเขียนตามแนวทางที่เคยมีคนโฟส ถามเอาไว้ แล้วลองเขียนๆ ดู
แต่มันเปิดเกินที่กำหนด หรือว่าผมเขียนตรงไหน ผิดก็ไม่รู้
count_1 = 0
count_2 = 0
count_M = 0
3 ตัวนี้ค่าเป็น 0 ตลอดเลยอ่าครับ
//==========================
extern double Stop = 5000;
extern double Profit = 100;
extern double Profit_A = 50;
extern double Order_M = 3;
extern double Order_1 = 1;
extern double Order_2 = 1;
extern double Maxlots = 2;
extern double ADX =20;
extern double Ma_F =20;
extern double MagicNumber_1 = 123;
extern double MagicNumber_2 = 345;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
if(DayOfWeek()<=1 || DayOfWeek()>=5) return(0);
int ticket;
double lots;
double lots_A;
double a,ADX_M,OrdType,iSAR_1;
double count_1, count_2, count_M;
OrdType = iCustom(NULL,0,"iFisher",0,0);
a = 0-0.2;
ADX_M =iADX(NULL,0,ADX,PRICE_HIGH,MODE_MAIN,0);
lots = (AccountBalance()/ 2000.0);
if(lots>Maxlots) lots =Maxlots;
lots_A= lots/Order_1;
if(lots_A<0.01) lots_A =0.01;
Comment(
"count_1 = ",count_1,
"count_2 = ",count_2,
"count_M= ",count_M);
//---------------------------------
เพิ่มตรงนี้เข้าไป int total=OrdersTotal();
for(int S=0;S<total;S++)
{
OrderSelect(S,SELECT_BY_POS,MODE_TRADES);
if( OrderSymbol()==Symbol() && (OrderMagicNumber() == MagicNumber_1 || OrderMagicNumber() == MagicNumber_2) )
{
count_M++;
if ( OrderMagicNumber() == MagicNumber_1 ) count_1++;
if ( OrderMagicNumber() == MagicNumber_2 ) count_2++;
}
}
//=======================================
if(count_M < Order_M )
{if(count_1<Order_1&&ADX_M>25)
{
if( OrdType>0)
{
ticket=OrderSend(Symbol(),OP_SELL,lots_A,Bid,3,Ask+Point*Stop,Bid-Point*Profit,"Down_Ex",123,0,Red);
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
}
if( OrdType<0)
{
ticket=OrderSend(Symbol(),OP_BUY,lots_A,Ask,3,Bid-Point*Stop,Ask+Point*Profit,"Up_Ex",123,0,Green);
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
}
}
if(count_2<Order_2&&ADX_M>25)
{
if( OrdType<0)
{
ticket=OrderSend(Symbol(),OP_SELL,lots_A*0.5,Bid,3,Ask+Point*Stop,Bid-Point*Profit_A,"Down_Ex",345,0,Yellow);
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
}
if( OrdType>0)
{
ticket=OrderSend(Symbol(),OP_BUY,lots_A*0.5,Ask,3,Bid-Point*Stop,Ask+Point*Profit_A,"Up_Ex",345,0,Blue);
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
}
}
}
return(0);
}
//+------------------------------------------------------------------+