ลองเอาคำแนะนำท่าน D_Daimond ไปลองเขียนดูแต่ EA ไม่เปิดออร์เดอร์เลยคับ รบกวนช่วยตรวจให้หน่อยครับว่าผิดตรงไหน ขอบคุณครับท่าน
extern double MagicNumber1 = 12345;
extern double MagicNumber2 = 56789;
extern double MaximumOrder = 4;
extern double TimePeriod = 1;
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
double s1count, s2count, count;
double GetRSI = iRSI(NULL,PERIOD_H1,14,PRICE_CLOSE,0);
double PreRSI = iRSI(NULL,PERIOD_H1,14,PRICE_CLOSE,1);
//----- Clear Value -----//
s1count = 0;
s2count = 0;
count = 0;
for(int i = 0; i < MaximumOrder; i++)
{
if(OrderMagicNumber()==MagicNumber1) s1count++;
if(OrderMagicNumber()==MagicNumber2) s2count++;
count++;
}
//----- Close Order -----//
if(s1count>0 )
{
//----- Close Order with Condition1 -----//
if(OrderMagicNumber()==MagicNumber1)
{
double OBid = MarketInfo("EURUSD",MODE_BID);
double OAsk = MarketInfo("EURUSD",MODE_ASK);
if(PreRSI > 70.0000 && (OrderOpenPrice()+(10*Point)) < OBid)
{
OrderClose(OrderTicket(),OrderLots(),Bid,4,Green);
s1count--;
}
if(PreRSI < 30.0000 && (OrderOpenPrice()-(20*Point)) > OAsk)
{
OrderClose(OrderTicket(),OrderLots(),Ask,4,Red);
s1count--;
}
}
}
if(s2count>0 )
{
if(OrderMagicNumber()==MagicNumber2)
{
double CurMA5 = iMA(NULL,TimePeriod,5,0,MODE_EMA,PRICE_CLOSE,0);
double PreMA5 = iMA(NULL,TimePeriod,5,0,MODE_EMA,PRICE_CLOSE,1);
double CurMA34 = iMA(NULL,TimePeriod,34,0,MODE_EMA,PRICE_CLOSE,0);
double PreMA34 = iMA(NULL,TimePeriod,34,0,MODE_EMA,PRICE_CLOSE,1);
double CurMA50 = iMA(NULL,TimePeriod,50,0,MODE_EMA,PRICE_CLOSE,0);
double PreMA50 = iMA(NULL,TimePeriod,50,0,MODE_EMA,PRICE_CLOSE,1);
if(CurMA5 < CurMA34 && PreMA5 > PreMA34)
{
OrderClose(OrderTicket(),OrderLots(),Bid,4,Green); // close position
s2count--;
}
if(CurMA5 > CurMA34 && PreMA5 < PreMA34)
{
OrderClose(OrderTicket(),OrderLots(),Ask,4,Red);
s2count--;
}
}
}
//----- Open Order -----//
if(count < MaximumOrder )
{
if(GetRSI < 30.0000 && PreRSI < 30.0000 && s1count < 2) OrderSend(Symbol(),OP_BUY,0.1,Ask,4,0,0,"Buy",12345,0,Green);
if(GetRSI > 70.0000 && PreRSI > 70.0000 && s1count < 2) OrderSend(Symbol(),OP_SELL,0.1,Bid,4,0,0,"Sell",12345,0,Red);
if(CurMA5 > CurMA50 && PreMA5 < PreMA50 && MarketInfo(TimePeriod,MODE_ASK) < PreMA34 && s2count < 2) OrderSend(Symbol(),OP_BUY,0.1,Ask,4,0,0,"Buy",56789,0,Green);
if(CurMA5 < CurMA50 && PreMA5 > PreMA50 && MarketInfo(TimePeriod,MODE_BID) > PreMA34 && s2count < 2) OrderSend(Symbol(),OP_SELL,0.1,Bid,4,0,0,"Sell",56789,0,Red);
}
return(0);
}