Xin giúp đỡ mã code giới hạn MM và 1 order / 1 nến

Xin giúp đỡ mã code giới hạn MM và 1 order / 1 nến

Xin giúp đỡ mã code giới hạn MM và 1 order / 1 nến
21
3
Xin chào anh chị coder
em tạo 1 ea trên ForexEAdvisor , em cài đã cài thêmMM

Em sử dụng nến H1 (1) làm tín hiệu và nến H1 (0) vào lệnh . nhưng lúc thị trường biến động mạnh thì khoảng 10 phút sau là đã đạt lợi nhuận . sau đó Ea tự động vào lệnh lại ( vì vẫn thỏa điều kiện ) . và làm cho vị trí vào lệnh cực xấu ( ngay chỗ xa ) .
Ngoài ra em đang cố code AdvancedMM cho nó giới hạn số lần thực hiện :
ví dụ : lottsize mặc định là : 0.1
=> thua MM * 2 = 0.2 ( lần 1)
=> thua MM * 2 = 0.4 ( lần 2)
=> thua MM tự động retturn lottsize mặc định là 0.1
Xin anh chị hướng dẫn giúp em với ạ .

Em xin gửi mã trực tiếp lên để đỡ tải về ạ :

extern int MagicNumber=10009;
extern double Lots =0.1;
extern double StopLoss=0;
extern double TakeProfit=0;
extern int TrailingStop=0;
extern int Slippage=3;
double lot=0;
//+------------------------------------------------------------------+
// expert start function
//+------------------------------------------------------------------+
int start()
{
double MyPoint=Point;
if(Digits==3 || Digits==5)
MyPoint=Point*10;
double TheStopLoss=0;
double TheTakeProfit=0;
if(AdvancedMM()>0)
lot=AdvancedMM();
else
lot=Lots;
if(TotalOrdersCount()==0)


{
int result=0;
if

(iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,1 ) > iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,1 ) )

// Here is your open buy rule
{
result=OrderSend(Symbol(),OP_BUY,lot,Ask,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Blue);
if(result>0)
{
TheStopLoss=0;
TheTakeProfit=0;
if(TakeProfit>0)
TheTakeProfit=Ask+TakeProfit*MyPoint;
if(StopLoss>0)
TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
}

return(0);
}
if

(iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,1 ) > iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,1 ) )

// Here is your open Sell rule
{
result=OrderSend(Symbol(),OP_SELL,lot,Bid,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Red);
if(result>0)
{
TheStopLoss=0;
TheTakeProfit=0;
if(TakeProfit>0)
TheTakeProfit=Bid-TakeProfit*MyPoint;
if(StopLoss>0)
TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
}
return(0);
}
}
for(int cnt=0; cnt<OrdersTotal(); cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL &&
OrderSymbol()==Symbol() &&
OrderMagicNumber()==MagicNumber
)
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)
{
if(OrderStopLoss()<Bid-MyPoint*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else
{
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))
{
if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int TotalOrdersCount()
{
int result=0;
for(int i=0; i<OrdersTotal(); i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderMagicNumber()==MagicNumber)
result++;
}
return (result);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double AdvancedMM()
{
double AdvancedMMLots = 0;
int SystemHistoryOrders=OrdersHistoryTotal();
for(int i=SystemHistoryOrders-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
if(OrderMagicNumber()==MagicNumber) //|
{
if(OrderSymbol()==Symbol())
{
if(OrderProfit()>=0)
{
AdvancedMMLots = Lots;
break;
}
if(OrderProfit()<0)
{
AdvancedMMLots = NormalizeDouble(2* OrderLots(),2);
break;
}
}
}
}
return (AdvancedMMLots);
}
//+------------------------------------------------------------------+

XIN CÁM ƠN ANH CHỊ TRƯỚC Ạ .
 
 

Đính kèm

  • eaTEST.mq4
    4.8 KB · Xem: 1

Giới thiệu sách Trading hay
Khám phá Nghệ thuật Giao dịch Tiền tệ Chuyên nghiệp

Sách được viết bởi FX Trader chuyên nghiệp, có gần 30 năm giao dịch Forex cho các ngân hàng lớn thế giới như Citi, Nomura hay HSBC, đồng thời từng trading cho quỹ đầu cơ có vốn hàng chục triệu đô la
Bạn thêm đoạn code này vào cuối cùng của EA
Mã:
bool NewBar()
   {
      static datetime oldtime = 0;
      if(oldtime < Time[0])
         {
            oldtime = Time[0];
            return(true);
         }
      else
         {return(false);}
   }

Tại các dòng điều kiện mở Buy hoặc Sell thì chèn nó vào :
Mã:
&& ( NewBar() == true)
 
 
Bạn thêm đoạn code này vào cuối cùng của EA
Mã:
bool NewBar()
   {
      static datetime oldtime = 0;
      if(oldtime < Time[0])
         {
            oldtime = Time[0];
            return(true);
         }
      else
         {return(false);}
   }

Tại các dòng điều kiện mở Buy hoặc Sell thì chèn nó vào :
Mã:
&& ( NewBar() == true)

quá tuyệt vời luôn ạ , Ea đã nhận 1 lệnh / 1 nến ròi . cám ơn anh nhé
 
 

Đính kèm

  • eaTEST.mq4
    5.2 KB · Xem: 2

BÌNH LUẬN MỚI NHẤT

AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features of our website. For the best site experience please disable your AdBlocker.

Back
Bên trên

Miễn trừ trách nhiệm

Tất cả nội dung trên website này đều vì mục đích cung cấp thông tin và không phải lời khuyên đầu tư.

Tại Việt Nam, giao dịch CFD forex có các rủi ro nhất định, trong đó bao gồm rủi ro về pháp lý. Độc giả nên tìm hiểu kỹ trước khi đưa ra quyết định tham gia.