Lập trình Robot cho giao dịch thuật toán của riêng bạn - những khái niệm cơ bản

Lập trình Robot cho giao dịch thuật toán của riêng bạn - những khái niệm cơ bản

Lập trình Robot cho giao dịch thuật toán của riêng bạn - những khái niệm cơ bản

namthang

Editor
Trial mod
3,026
16,136
Với thời đại công nghệ hiện nay, nhiều nhà giao dịch đang có xu hướng trở thành các nhà giao dịch thuật toán nhưng lại phải vật lộn với việc lập trình con robot của họ. Qua bài viết này, chúng ta sẽ cùng nhau tìm hiểu xem chức năng của robot và một số tư duy ban đầu trước khi học lập trình robot:

Chức năng của một Robot giao dịch


Ở cấp độ cơ bản nhất, robot giao dịch là chương trình được lập trình có khả năng tạo và thực hiện các tín hiệu mua và bán trên thị trường tài chính. Để lập trình một robot như vậy chúng ta cần các quy tắc vào lệnh để biết rằng khi nào nên mua hoặc bán, quy tắc thoát lệnh cho biết khi nào đóng vị thế hiện tại và quy tắc xác định kích thước giao dịch để biết khối lượng cần mua hoặc bán.

Công cụ giao dịch thuật toán chính


Rõ ràng, bạn sẽ cần một máy tính và kết nối Internet. Sau đó, sẽ cần một hệ điều hành Windows hoặc Mac để chạy MetaTrader 4 (MT4) - một nền tảng giao dịch điện tử sử dụng MetaQuotes Language 4 (MQL4) cho các chiến lược giao dịch tự động. Mặc dù MT4 không phải là phần mềm duy nhất người ta có thể sử dụng để cài đặt robot nhưng nó có một số lợi ích đáng kể.

Screenshot-2019-07-21-16.25.21-1024x741.png


Trong khi lớp tài sản chính của MT4 là ngoại hối ( FX), nền tảng này còn có thể được sử dụng để giao dịch cổ phiếu, chỉ số thị trường, hàng hóa và Bitcoin dưới dạng CFDs. Các lợi ích khác của việc sử dụng MT4 so với các nền tảng khác bao gồm dễ học, có nhiều nguồn dữ liệu có sẵn và miễn phí.

Thật không may, MT4 không cho phép giao dịch trực tiếp trên thị trường chứng khoán và thị trường tương lai cũng như tiến hành phân tích thống kê; tuy nhiên, chúng ta có thể sử dụng MS Excel như một công cụ thống kê bổ sung.

Chiến lược giao dịch thuật toán


Chiến lược nên dựa trên những quan điểm đúng đắn về thị trường và các yếu tố cơ bản. Ngoài ra, thuật toán sử dụng trong việc phát triển chiến lược nên dựa trên các phương pháp thống kê hợp lý.

Điều quan trọng tiếp theo là xác định thông tin nào mà robot của bạn đang nhắm đến. Chiến lược giao dịch thuật toán nên tuân theo một bộ quy tắc cứng nhắc lợi dụng hành vi thiếu hiệu quả của thị trường (giá thị trường không phản ánh giá trị thực). Nếu nguyên nhân của sự thiếu hiệu quả của thị trường là không thể xác định được, thì sẽ không có cách nào để biết liệu rằng chiến lược sẽ thành công hay thất bại.

Với ý tưởng trên, có một số loại chiến lược có thể được sử dụng cho việc lập trình robot của bạn. Chúng bao gồm các chiến lược sử dụng các điều sau (hoặc bất kỳ sự kết hợp nào):
  • Tin tức kinh tế vĩ mô (ví dụ: bảng lương phi nông nghiệp hoặc thay đổi lãi suất)
  • Phân tích cơ bản (ví dụ: sử dụng dữ liệu doanh thu hoặc báo cáo thu nhập)
  • Phân tích thống kê (ví dụ: các mối quan hệ tương quan)
  • Phân tích kỹ thuật (ví dụ: đường trung bình động)
  • Cấu trúc vi mô thị trường (ví dụ: chênh lệch giá hoặc liên thị trường)
  • Thiết kế cho nghiên cứu sơ bộ
Bước này tập trung vào phát triển một chiến lược phù hợp với đặc điểm cá nhân của riêng bạn. Các yếu tố như khẩu vị rủi ro, thời gian và vốn giao dịch là điều quan trọng để xây dựng chiến lược. Sau đó, bạn có thể bắt đầu xác định sự thiếu hiệu quả của thị trường được đề cập ở trên. Khi đã xác định được sự kém hiệu quả của thị trường, bạn có thể bắt đầu lập trinh một robot giao dịch phù hợp với đặc điểm cá nhân của riêng bạn.

Backtesting


Bước backtesting này tập trung vào xác nhận robot giao dịch của bạn. Điều này bao gồm kiểm tra mã nguồn để đảm bảo rằng nó đang thực hiện những gì bạn muốn và hiểu cách nó thực hiện trong các khung thời gian khác nhau, các loại tài sản hoặc các điều kiện thị trường khác nhau, đặc biệt là trong các sự kiện loại thiên nga đen như cuộc khủng hoảng tài chính toàn cầu năm 2008.

Tối ưu hóa thiết kế giao dịch thuật toán
Bây giờ bạn đã lập trình một robot có thể hoạt động và ở giai đoạn này, bạn muốn tối đa hóa hiệu suất của nó trong khi giảm thiểu sai lệch quá mức. Để tối đa hóa hiệu suất, trước tiên bạn cần chọn một thước đo hiệu suất tốt để nắm bắt các yếu tố Risk/Reward, cũng như tính nhất quán (ví dụ: tỷ lệ Sharpe). Tuy nhiên, nếu robot của bạn quá bám vào dữ liệu trong quá khứ; có khả năng nó sẽ tạo ra ảo tưởng về hiệu suất giao dịch, nhưng tương lai không bao giờ hoàn toàn giống với quá khứ, nó thực sự có thể thất bại.

Thực chiến


Bây giờ bạn đã sẵn sàng để bắt đầu sử dụng tiền thật. Tuy nhiên, ngoài việc chuẩn bị cho những thăng trầm cảm xúc mà bạn có thể gặp phải, có một vài vấn đề kỹ thuật cần được giải quyết. Những vấn đề này bao gồm lựa chọn một nhà môi giới phù hợp và thực hiện các cơ chế để quản lý cả rủi ro thị trường và rủi ro hoạt động như hacker và vòng thời gian của công nghệ.

pixel-cells-3947912_640.png

Điều quan trọng ở bước này là xác minh rằng hiệu suất Robot tương tự như trong giai đoạn thử nghiệm. Cuối cùng, việc giám sát liên tục là cần thiết để đảm bảo rằng hiệu suất của robot vẫn đảm bảo.

Điểm mấu chốt


Richard Dennis, nhà giao dịch hàng hóa huyền thoại, đã dạy cho một nhóm sinh viên về chiến lược giao dịch của mình, và sau đó có những người đã kiếm được hơn 175 triệu đô la chỉ trong năm năm. Có thể có những nhà giao dịch thiếu kinh nghiệm được dạy những hệ thống giao dịch nghiêm ngặt và thành công. Tuy nhiên, đây là một ví dụ phi thường và người mới nên bắt đầu với những kỳ vọng khiêm tốn.

Để thành công, điều quan trọng là không chỉ tuân theo một bộ hướng dẫn mà còn phải hiểu cách thức các hướng dẫn đó hoạt động. Phần quan trọng nhất của giao dịch thuật toán là sự hiểu biết về các loại điều kiện thị trường mà robot của bạn sẽ hoạt động cũng như khi nào nó sẽ bị phá vỡ, để có sự can thiệp và khắc phục kịp thời. Giao dịch thuật toán có thể bổ ích nhưng chìa khóa thành công là hiểu biết. Bất kỳ khóa học với sự hứa hẹn mang lại lợi nhuận cao nên được cân nhắc kỹ càng.

Trong phần tới, mình sẽ giới thiệu tới các bạn những nguồn miễn phí chất lượng để học code robot phục vụ cho giao dịch thuật toán! Các bạn nhớ theo dõi!
Nguồn: Investopia
 

Giới thiệu sách Trading hay
Bộ sách của Phù Thủy Trader Mark Minervini

Mark Minervini là một huyền thoại của giới trading toàn cầu. Bộ sách này mang đến các kiến thức cơ bản nhất về phương pháp giao dịch của Mark Minervini
Vâng, cỡ như bạn chắc mới còn ẵm ngửa, mình biết đi rồi kakaka

Mà thôi, kg tranh luận với kẻ ngu làm gì, kg thiên hạ lại bảo mình ngu giống họ. Mình chấm dứt mọi tranh luận vớ vẩn ngoài chuyên môn ở đây. Ai nói gì tức là họ đang nói chính họ. Thực sự cũng chẳng có gì để nói với loại chỉ biết đi nói xấu người khác, chẳng làm đc gì lợi ích cho cộng đồng, thậm chí họ cũng chưa chắc đã biết làm lợi ích gì lợi ích cho chính họ. Loại vô dụng, chấp làm gì

Hết
 
Chỉnh sửa lần cuối:
Tôi mất hơn 1 năm để vừa học vừa code một EA bằng MQL5 mà chưa xong.
Học những cái cơ bản để hỗ trợ việc canh vào lệnh, xử lý SL TP tự động thôi bác, việc thiết lập điều kiện theo chu kỳ (hàng giờ/hàng ngày/hàng tuần...) như thế nào vẫn là thủ công bởi trader.
 
Tối muốn có một EA tự động 100% luôn. Rồi cấp vốn cho EA tự giao dịch. Cuối tuần vào rút lãi hoặc nạp tiền khi cháy TK. Tuyệt đối ko bơm tiền gồng lỗ. Tham vọng là vậy mà viết mãi ko xong. Đang còn loay hoay các chỉ báo.
còn viết ko anh
 
Bác cần viết thì hú em. Bên e chuyên code. Đơn giản hay phức tạp đều ok nhé bác
Con này thêm phần tính lost theo 1% TK và chuyển code sang mt5 thì như thế nào bạn?

//+------------------------------------------------------------------+
extern int MagicNumber = 10000;
extern double Lots = 0.01;
extern double StopLoss = 12;
extern double TakeProfit1 = 0;
extern double TakeProfit2 = 15;
extern double TakeProfit3 = 18;
extern double TakeProfit4 = 21;
extern double TakeProfit5 = 24;
extern double TakeProfit6 = 27;
extern double TakeProfit7 = 30;
extern double TakeProfit8 = 33;
extern double TakeProfit9 = 36;
extern int TrailingStop = 12;
extern int Slippage = 3;
//+------------------------------------------------------------------+
// expert start function
//+------------------------------------------------------------------+
int start()
{double MyPoint=Point;
if(Digits==1 || Digits==2|| Digits==3|| Digits==4|| Digits==5|| Digits==6|| Digits==7|| Digits==8|| Digits==9) {MyPoint=Point*10;}
double TheStopLoss=0;
double TheTakeProfit1=0;double TheTakeProfit2=0;double TheTakeProfit3=0;double TheTakeProfit4=0;double TheTakeProfit5=0;
double TheTakeProfit6=0;double TheTakeProfit7=0;double TheTakeProfit8=0;double TheTakeProfit9=0;
if(TotalOrdersCount()==0)
{int result1=0; int result2=0;int result3=0;int result4=0;int result5=0; int result6=0;int result7=0;int result8=0;int result9=0;
if((iRSI(NULL,PERIOD_M1,14,PRICE_WEIGHTED,0)>iRSI(NULL,PERIOD_M1,18, PRICE_WEIGHTED,0))
&&(iRSI(NULL,PERIOD_M5,14,PRICE_WEIGHTED,0)>iRSI(NULL,PERIOD_M5,18, PRICE_WEIGHTED,0)))
{{result1= OrderSend(Symbol(),0,Lots,Ask,Slippage,0,0,"EA1",MagicNumber,0,Blue);
if(TakeProfit1>0) TheTakeProfit1=Ask+TakeProfit1*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result1,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit1,Digits),0,Green);

result2= OrderSend(Symbol(),0,Lots,Ask,Slippage,0,0,"EA2",MagicNumber,0,Blue);
if(TakeProfit2>0) TheTakeProfit2=Ask+TakeProfit2*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result2,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit2,Digits),0,Green);

result3= OrderSend(Symbol(),0,Lots,Ask,Slippage,0,0,"EA3",MagicNumber,0,Blue);
if(TakeProfit3>0) TheTakeProfit3=Ask+TakeProfit3*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result3,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit3,Digits),0,Green);

result4= OrderSend(Symbol(),0,Lots,Ask,Slippage,0,0,"EA4",MagicNumber,0,Blue);
if(TakeProfit4>0) TheTakeProfit4=Ask+TakeProfit4*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result4,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit4,Digits),0,Green);

result5= OrderSend(Symbol(),0,Lots,Ask,Slippage,0,0,"EA5",MagicNumber,0,Blue);
if(TakeProfit5>0) TheTakeProfit5=Ask+TakeProfit5*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result5,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit5,Digits),0,Green);

result6= OrderSend(Symbol(),0,Lots,Ask,Slippage,0,0,"EA6",MagicNumber,0,Blue);
if(TakeProfit6>0) TheTakeProfit6=Ask+TakeProfit6*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result6,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit6,Digits),0,Green);

result7= OrderSend(Symbol(),0,Lots,Ask,Slippage,0,0,"EA7",MagicNumber,0,Blue);
if(TakeProfit7>0) TheTakeProfit7=Ask+TakeProfit7*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result7,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit7,Digits),0,Green);

result8= OrderSend(Symbol(),0,Lots,Ask,Slippage,0,0,"EA8",MagicNumber,0,Blue);
if(TakeProfit8>0) TheTakeProfit8=Ask+TakeProfit8*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result8,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit8,Digits),0,Green);

result9= OrderSend(Symbol(),0,Lots,Ask,Slippage,0,0,"EA9",MagicNumber,0,Blue);
if(TakeProfit9>0) TheTakeProfit9=Ask+TakeProfit9*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result9,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit9,Digits),0,Green);}
return(0);}

//======================================================================================================

if((iRSI(NULL,PERIOD_M1,14,PRICE_WEIGHTED,0)<iRSI(NULL,PERIOD_M1,18, PRICE_WEIGHTED,0))
&&(iRSI(NULL,PERIOD_M5,14,PRICE_WEIGHTED,0)<iRSI(NULL,PERIOD_M5,18, PRICE_WEIGHTED,0)))
{{result1= OrderSend(Symbol(),1,Lots,Bid,Slippage,0,0,"EA1",MagicNumber,0,Blue);
if(TakeProfit1>0) TheTakeProfit1=Bid-TakeProfit1*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result1,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit1,Digits),0,Green);

result2= OrderSend(Symbol(),1,Lots,Bid,Slippage,0,0,"EA2",MagicNumber,0,Blue);
if(TakeProfit2>0) TheTakeProfit2=Bid-TakeProfit2*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result2,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit2,Digits),0,Green);

result3= OrderSend(Symbol(),1,Lots,Bid,Slippage,0,0,"EA3",MagicNumber,0,Blue);
if(TakeProfit3>0) TheTakeProfit3=Bid-TakeProfit3*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result3,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit3,Digits),0,Green);

result4= OrderSend(Symbol(),1,Lots,Bid,Slippage,0,0,"EA4",MagicNumber,0,Blue);
if(TakeProfit4>0) TheTakeProfit4=Bid-TakeProfit4*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result4,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit4,Digits),0,Green);

result5= OrderSend(Symbol(),1,Lots,Bid,Slippage,0,0,"EA5",MagicNumber,0,Blue);
if(TakeProfit5>0) TheTakeProfit5=Bid-TakeProfit5*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result5,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit5,Digits),0,Green);

result6= OrderSend(Symbol(),1,Lots,Bid,Slippage,0,0,"EA6",MagicNumber,0,Blue);
if(TakeProfit6>0) TheTakeProfit6=Bid-TakeProfit6*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result6,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit6,Digits),0,Green);

result7= OrderSend(Symbol(),1,Lots,Bid,Slippage,0,0,"EA7",MagicNumber,0,Blue);
if(TakeProfit7>0) TheTakeProfit7=Bid-TakeProfit7*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result7,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit7,Digits),0,Green);

result8= OrderSend(Symbol(),1,Lots,Bid,Slippage,0,0,"EA8",MagicNumber,0,Blue);
if(TakeProfit8>0) TheTakeProfit8=Bid-TakeProfit8*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result8,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit8,Digits),0,Green);

result9= OrderSend(Symbol(),1,Lots,Bid,Slippage,0,0,"EA9",MagicNumber,0,Blue);
if(TakeProfit9>0) TheTakeProfit9=Bid-TakeProfit9*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result9,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit9,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);}
//======================================================================================================
 
Con này thêm phần tính lost theo 1% TK và chuyển code sang mt5 thì như thế nào bạn?

//+------------------------------------------------------------------+
extern int MagicNumber = 10000;
extern double Lots = 0.01;
extern double StopLoss = 12;
extern double TakeProfit1 = 0;
extern double TakeProfit2 = 15;
extern double TakeProfit3 = 18;
extern double TakeProfit4 = 21;
extern double TakeProfit5 = 24;
extern double TakeProfit6 = 27;
extern double TakeProfit7 = 30;
extern double TakeProfit8 = 33;
extern double TakeProfit9 = 36;
extern int TrailingStop = 12;
extern int Slippage = 3;
//+------------------------------------------------------------------+
// expert start function
//+------------------------------------------------------------------+
int start()
{double MyPoint=Point;
if(Digits==1 || Digits==2|| Digits==3|| Digits==4|| Digits==5|| Digits==6|| Digits==7|| Digits==8|| Digits==9) {MyPoint=Point*10;}
double TheStopLoss=0;
double TheTakeProfit1=0;double TheTakeProfit2=0;double TheTakeProfit3=0;double TheTakeProfit4=0;double TheTakeProfit5=0;
double TheTakeProfit6=0;double TheTakeProfit7=0;double TheTakeProfit8=0;double TheTakeProfit9=0;
if(TotalOrdersCount()==0)
{int result1=0; int result2=0;int result3=0;int result4=0;int result5=0; int result6=0;int result7=0;int result8=0;int result9=0;
if((iRSI(NULL,PERIOD_M1,14,PRICE_WEIGHTED,0)>iRSI(NULL,PERIOD_M1,18, PRICE_WEIGHTED,0))
&&(iRSI(NULL,PERIOD_M5,14,PRICE_WEIGHTED,0)>iRSI(NULL,PERIOD_M5,18, PRICE_WEIGHTED,0)))
{{result1= OrderSend(Symbol(),0,Lots,Ask,Slippage,0,0,"EA1",MagicNumber,0,Blue);
if(TakeProfit1>0) TheTakeProfit1=Ask+TakeProfit1*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result1,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit1,Digits),0,Green);

result2= OrderSend(Symbol(),0,Lots,Ask,Slippage,0,0,"EA2",MagicNumber,0,Blue);
if(TakeProfit2>0) TheTakeProfit2=Ask+TakeProfit2*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result2,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit2,Digits),0,Green);

result3= OrderSend(Symbol(),0,Lots,Ask,Slippage,0,0,"EA3",MagicNumber,0,Blue);
if(TakeProfit3>0) TheTakeProfit3=Ask+TakeProfit3*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result3,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit3,Digits),0,Green);

result4= OrderSend(Symbol(),0,Lots,Ask,Slippage,0,0,"EA4",MagicNumber,0,Blue);
if(TakeProfit4>0) TheTakeProfit4=Ask+TakeProfit4*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result4,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit4,Digits),0,Green);

result5= OrderSend(Symbol(),0,Lots,Ask,Slippage,0,0,"EA5",MagicNumber,0,Blue);
if(TakeProfit5>0) TheTakeProfit5=Ask+TakeProfit5*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result5,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit5,Digits),0,Green);

result6= OrderSend(Symbol(),0,Lots,Ask,Slippage,0,0,"EA6",MagicNumber,0,Blue);
if(TakeProfit6>0) TheTakeProfit6=Ask+TakeProfit6*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result6,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit6,Digits),0,Green);

result7= OrderSend(Symbol(),0,Lots,Ask,Slippage,0,0,"EA7",MagicNumber,0,Blue);
if(TakeProfit7>0) TheTakeProfit7=Ask+TakeProfit7*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result7,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit7,Digits),0,Green);

result8= OrderSend(Symbol(),0,Lots,Ask,Slippage,0,0,"EA8",MagicNumber,0,Blue);
if(TakeProfit8>0) TheTakeProfit8=Ask+TakeProfit8*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result8,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit8,Digits),0,Green);

result9= OrderSend(Symbol(),0,Lots,Ask,Slippage,0,0,"EA9",MagicNumber,0,Blue);
if(TakeProfit9>0) TheTakeProfit9=Ask+TakeProfit9*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result9,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit9,Digits),0,Green);}
return(0);}

//======================================================================================================

if((iRSI(NULL,PERIOD_M1,14,PRICE_WEIGHTED,0)<iRSI(NULL,PERIOD_M1,18, PRICE_WEIGHTED,0))
&&(iRSI(NULL,PERIOD_M5,14,PRICE_WEIGHTED,0)<iRSI(NULL,PERIOD_M5,18, PRICE_WEIGHTED,0)))
{{result1= OrderSend(Symbol(),1,Lots,Bid,Slippage,0,0,"EA1",MagicNumber,0,Blue);
if(TakeProfit1>0) TheTakeProfit1=Bid-TakeProfit1*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result1,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit1,Digits),0,Green);

result2= OrderSend(Symbol(),1,Lots,Bid,Slippage,0,0,"EA2",MagicNumber,0,Blue);
if(TakeProfit2>0) TheTakeProfit2=Bid-TakeProfit2*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result2,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit2,Digits),0,Green);

result3= OrderSend(Symbol(),1,Lots,Bid,Slippage,0,0,"EA3",MagicNumber,0,Blue);
if(TakeProfit3>0) TheTakeProfit3=Bid-TakeProfit3*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result3,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit3,Digits),0,Green);

result4= OrderSend(Symbol(),1,Lots,Bid,Slippage,0,0,"EA4",MagicNumber,0,Blue);
if(TakeProfit4>0) TheTakeProfit4=Bid-TakeProfit4*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result4,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit4,Digits),0,Green);

result5= OrderSend(Symbol(),1,Lots,Bid,Slippage,0,0,"EA5",MagicNumber,0,Blue);
if(TakeProfit5>0) TheTakeProfit5=Bid-TakeProfit5*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result5,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit5,Digits),0,Green);

result6= OrderSend(Symbol(),1,Lots,Bid,Slippage,0,0,"EA6",MagicNumber,0,Blue);
if(TakeProfit6>0) TheTakeProfit6=Bid-TakeProfit6*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result6,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit6,Digits),0,Green);

result7= OrderSend(Symbol(),1,Lots,Bid,Slippage,0,0,"EA7",MagicNumber,0,Blue);
if(TakeProfit7>0) TheTakeProfit7=Bid-TakeProfit7*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result7,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit7,Digits),0,Green);

result8= OrderSend(Symbol(),1,Lots,Bid,Slippage,0,0,"EA8",MagicNumber,0,Blue);
if(TakeProfit8>0) TheTakeProfit8=Bid-TakeProfit8*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result8,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit8,Digits),0,Green);

result9= OrderSend(Symbol(),1,Lots,Bid,Slippage,0,0,"EA9",MagicNumber,0,Blue);
if(TakeProfit9>0) TheTakeProfit9=Bid-TakeProfit9*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result9,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit9,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);}
//======================================================================================================
Chuyển sang ngôn ngữ MQL5 thì là code lại từ đầu luôn nhé bác. Chiến thuật này bác mô tả lại cho e đầy đủ e sẽ có báo giá cụ thể nhé
 
Các bạn mới muốn tạo ea đừng có theo đuổi ngôn ngữ mql, vì nó yếu, cơ bản không có tương lai. MQ luôn có các API để sàn thao túng, trên terminal có plugin "chăm sóc" khách hàng nhỏ, trên server có plugin "chăm sóc" khách hàng lớn, nhẹ nhàng nhất là giãn spread, delay lệnh.

Các bạn nên học thẳng c++, c#, nó mạnh mẽ hơn nhiều, bớt bị sàn chơi đểu. Bản thân mình chỉ còn sài ngôn ngữ mql ở giai đoạn đầu của việc phát triển bot để dễ debug, dự án tạm ổn là chuyển qua c++. Nếu cần giao diện người dùng thì sài c# cho dễ làm.

Mình đã rất vất vả với mql, nhưng khi mình thấy code mình viết chạy ở mode debug thì đúng, chạy thật thì sai nên quyết tâm từ bỏ nó. Nó không có sai 100%, lúc đúng lúc sai nên mình kg tin tưởng. Mọi người luôn đổ thừa test khác, real khác mà kg biết lý do sâu xa ở đàng sau: kg phải tại logic hay dữ liệu mà lý do chính tạo sự khác biệt là khi test kg bị thao túng, khi chạy thiệt bị thao túng. Lúc thua họ cho bot chạy, lúc ăn họ đá bot ra, thường mọi người đâu có biết bot bị đá lúc nào. Mình biết vì mình chạy bot viết bằng c++, kết nối với terminal bằng 1 con bot nhỏ nên bị đá lúc nào là mình biết liền

Hiện tại mình đang theo đuổi 1 dự án bỏ qua luôn terminal, kết nối thẳng với máy chủ của sàn, mục đích chính là giảm % thao túng của sàn, cũng sắp xong rồi.

upload_2022-1-30_7-52-9.png


Giao diện này viết bằng c#, lõi c++
upload_2022-1-30_7-55-0.png


Sau khi hoàn thành việc kết nối thẳng với máy chủ của sàn, bước tiếp theo của dự án này là display trực tiếp các chỉ báo, mục đích là dễ kiểm tra chiến lược, dễ phát triển các chiến lược mới kg cần thông qua mql.
Đích cuối cùng của dự án này là Trí tuệ nhân tạo, xong bước cuối cùng này là mình có thể nghỉ hưu đc rồi, kaka
 
Chỉnh sửa lần cuối:
Các bạn mới muốn tạo ea đừng có theo đuổi ngôn ngữ mql, vì nó yếu, cơ bản không có tương lai. MQ luôn có các API để sàn thao túng, trên terminal có plugin "chăm sóc" khách hàng nhỏ, trên server có plugin "chăm sóc" khách hàng lớn, nhẹ nhàng nhất là giãn spread, delay lệnh.

Các bạn nên học thẳng c++, c#, nó mạnh mẽ hơn nhiều, bớt bị sàn chơi đểu. Bản thân mình chỉ còn sài ngôn ngữ mql ở giai đoạn đầu của việc phát triển bot để dễ debug, dự án tạm ổn là chuyển qua c++. Nếu cần giao diện người dùng thì sài c# cho dễ làm.

Mình đã rất vất vả với mql, nhưng khi mình thấy code mình viết chạy ở mode debug thì đúng, chạy thật thì sai nên quyết tâm từ bỏ nó. Nó không có sai 100%, lúc đúng lúc sai nên mình kg tin tưởng. Mọi người luôn đổ thừa test khác, real khác mà kg biết lý do sâu xa ở đàng sau: kg phải tại logic hay dữ liệu mà lý do chính tạo sự khác biệt là khi test kg bị thao túng, khi chạy thiệt bị thao túng. Lúc thua họ cho bot chạy, lúc ăn họ đá bot ra, thường mọi người đâu có biết bot bị đá lúc nào. Mình biết vì mình chạy bot viết bằng c++, kết nối với terminal bằng 1 con bot nhỏ nên bị đá lúc nào là mình biết liền

Hiện tại mình đang theo đuổi 1 dự án bỏ qua luôn terminal, kết nối thẳng với máy chủ của sàn, mục đích chính là giảm % thao túng của sàn, cũng sắp xong rồi.

View attachment 258966

Giao diện này viết bằng c#, lõi c++
View attachment 258967

Sau khi hoàn thành việc kết nối thẳng với máy chủ của sàn, bước tiếp theo của dự án này là display trực tiếp các chỉ báo, mục đích là dễ kiểm tra chiến lược, dễ phát triển các chiến lược mới kg cần thông qua mql.
Đích cuối cùng của dự án này là Trí tuệ nhân tạo, xong bước cuối cùng này là mình có thể nghỉ hưu đc rồi, kaka
Sàn nào cũng kết nối thẳng k qua terminal dc hả bác. Bác chỉ tôi chút với nhá. Cảm ơn trc nhá
 
Cảm ơn bác nhưng dùng api mà k bị sàn chọc ngoáy thì tôi k tin . Sàn nào ngu thế. Phải thử xem thế nào
Chú tải example về mà thử, đc 15 ngày đấy

Chẳng phải sàn nó ngu, biết cũng chẳng làm gì đc nhau. Chẳng lẽ lại bảo phải dùng terminal để chúng tôi thao túng mới đc phép à? Không thể nào, hơn nữa cũng chưa thoát khỏi bàn tay của họ mà, họ còn plugin trên máy chủ nữa, chỉ bớt bị thao túng hơn thôi.

Thiên hạ họ sài rầm trời, chỉ tại ae mình lạc hậu quá thôi, kaka.

Sàn FXCM có FIX API miễn phí đấy, nhưng có điều kiện là số dư tk phải trên 5k

upload_2022-1-30_10-40-19.png


upload_2022-1-30_10-38-26.png
 
Chỉnh sửa lần cuối:

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

  • Mạc An trong Phân tích Forex - Vàng - Hàng hóa 1,067 Xem / 65 Trả lời
  • DuongHuy trong Phân tích Forex - Vàng - Hàng hóa 277 Xem / 20 Trả lời
  • ngoi_sao_co_doc trong Phân tích Forex - Vàng - Hàng hóa 23,983 Xem / 82 Trả lời
  • Quíc Óp trong Phân tích Forex - Vàng - Hàng hóa 173 Xem / 3 Trả lời
  • Berkeley trong Phân tích Forex - Vàng - Hàng hóa 100 Xem / 2 Trả lời
  • LuTienSinh trong Phân tích Forex - Vàng - Hàng hóa 113 Xem / 3 Trả lời
  • DuongHuy trong Phân tích Forex - Vàng - Hàng hóa 233 Xem / 9 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