Làm sao để vào 1 lệnh duy nhất khi giá vượt qua đường band của BB

Làm sao để vào 1 lệnh duy nhất khi giá vượt qua đường band của BB

Làm sao để vào 1 lệnh duy nhất khi giá vượt qua đường band của BB

KhiemOne

Member
19
11
Chào các bác
Em chưa biết tí gì về lập trình thấy trang https://www.forexeadvisor.com/hỗ trợ tạo EA đơn giản
Em muốn tự động chỉ vào 1 lệnh khi giá vượt qua đường band trên hoặc dưới mà không biết làm sao
Tự tạo thì giá vượt qua là nó ào ào vào lệnh,

Thêm nữa em muốn lệnh đóng khi giá quay trở lại đường band mà nó vượt qua khi nó vào lệnh thì làm như nào
Nhờ các bác chỉ dùm

int start()
{
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;

double TheStopLoss=0;
double TheTakeProfit=0;
if( TotalOrdersCount()==0 )
{
int result=0;
if((Bid<iBands(NULL,0,21,1,0,PRICE_CLOSE,MODE_LOWER,0))) // Here is your open buy rule
{
result=OrderSend(Symbol(),OP_BUY,Lots,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);
}
}

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);
}
 

Đính kèm

  • Bid_BANDS_EA.mq4
    4.3 KB · Xem: 4

Giới thiệu sách Trading hay
Nhật Ký Giao Dịch Thực Chiến của Phù Thủy Thị trường Tài Chính

Sách chia sẻ 05 tháng giao dịch thực tế trên thị trường tài chính, sử dụng Price Action và Mô hình Biểu đồ của Phù thủy trader Peter Brandt, người có gần 50 năm kinh nghiệm trading và đạt lợi nhuận bình quân 68% lợi nhuận mỗi năm
làm cái hàm đếm lệnh cùng symbol
bool IsOrderExist(int order_type)
{
int total = OrdersTotal();
int i = 0;
while (i<total)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if ((OrderSymbol()==_Symbol)&&(OrderType()==order_type)) return(true);
i++;
}
return(false);
}

Khi nào mở lệnh thì làm như sau:
if (!IsOrderExist(OP_BUY)) Buy();
hoặc
if (!IsOrderExist(OP_SELL)) Sell();
 
làm cái hàm đếm lệnh cùng symbol
bool IsOrderExist(int order_type)
{
int total = OrdersTotal();
int i = 0;
while (i<total)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if ((OrderSymbol()==_Symbol)&&(OrderType()==order_type)) return(true);
i++;
}
return(false);
}

Khi nào mở lệnh thì làm như sau:
if (!IsOrderExist(OP_BUY)) Buy();
hoặc
if (!IsOrderExist(OP_SELL)) Sell();
Em không biết chèn vào đâu nữa. Bác có thể giúp em chèn vào file đính kèm rồi gửi lại em không
 
code của bác nó chưa có gì cả nên k ghép vào dc.
Bác chịu khó thuê mấy ae code cho dc việc.
 
Short Solution:
bạn chèn thêm điều kiện này vào như bên dưới thì nó sẽ đếm số lệnh đã mở (tính cả SELL và BUY) vậy nên EA sẽ chỉ mở lệnh tiếp theo khi mà lệnh này được close.


if((Bid<iBands(NULL,0,21,1,0,PRICE_CLOSE,MODE_LOWER,0)) && OrdersTotal()==0)
 

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

  • Nhật Hoài trong Lập trình MQL - Expert Advisor - Indicator 160,817 Xem / 1,108 Trả lời
  • Mạc An trong Phân tích Forex - Vàng - Hàng hóa 945 Xem / 40 Trả lời
  • DuongHuy trong Phân tích Forex - Vàng - Hàng hóa 387 Xem / 23 Trả lời
  • haruking trong Kiến thức Trading - Kinh nghiệm Trading 31,577 Xem / 112 Trả lời
  • captainfx trong Chuyện bên lề 663 Xem / 3 Trả lời
  • DuongHuy trong Phân tích Bitcoin - Altcoins - Cryptocurrency 68,934 Xem / 107 Trả lời
  • 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