指定
//+------------------------------------------------------------------+
//| Semafor_Ultimate_Pro_V4_6.mq4 |
//+------------------------------------------------------------------+
#Bản quyền thuộc về "Vỹ tuyến 17"
#phiên bản thuộc tính "4.60"
#property strict
enum ENUM_STRATEGY { SINGLE_ORDER = 0, DCA_ORDER = 1 };
#define NEWS_URL " http://ec.forexprostools.com "
//--- CÀI ĐẶT - SỐ LƯNG LÔ HÀNG
Chuỗi đầu vào _S_MAR = "====== QUAN LY VON ======";
input double Lot_Step1 = 0.01; // SO LOT KHOI DIEM
input double Lot_Mult = 1.2;
input int Max_Orders = 10;
input int DCA_Step = 200;
input int Magic = 999777;
input ENUM_STRATEGY Trade_Mode = DCA_ORDER;
//--- SETTINGS - CHỢT LỢI & CÁT LỘ AN (STEALTH)
đầu vào chuỗi _S_ST = "====== CHOT LOI / CAT LO (STEALTH) ======";
input int Stealth_TP_Points = 300;
input int Stealth_SL_Points = 600;
//--- CÀI ĐẶT - DỪNG CUỐI CÙNG
đầu vào chuỗi _S_TR = "====== DẤU DỪNG CUỐI ======";
input boolean Use_Trail = true;
input int Trail_Start = 100;
input int Trail_Step = 50;
//--- SETTINGS - NÉ TÍN (ĐỒNG BỘ GMT Chart)
Chuỗi đầu vào _S_NEWS = "====== CAI DAT NE TIN (GMT CHART) ======";
input boolean Use_News = true;
input int Minutes_Before_News = 30;
input int Minutes_After_News = 60;
input bool Avoid_Medium_Impact = true; // Tin 2 sao
input bool Avoid_High_Impact = true; // Tin 3 sao
//--- SETTINGS - GIO GIAO DICH (LOCAL)
đầu vào chuỗi _S_TIME = "====== QUÂN LY GIO (LOCAL) ======";
input bool Use_Weekly_Time = true;
Chuỗi đầu vào Weekly_Start_Time = "00:05";
Chuỗi đầu vào Weekly_End_Time = "23:55";
input bool Use_Daily_Time = true;
Chuỗi đầu vào Daily_Start_Time = "09:00";
Chuỗi đầu vào Daily_End_Time = "23:00";
//--- SETTINGS - PHÁNH AN TOÀN KÉP
Chuỗi đầu vào _S_BRAKE = "====== PHÁT AN TOÀN (USD + %) ======";
input double Stop_Loss_USD = 1.0;
input double Stop_Neg_Ratio = 0.5;
//--- TIN HIEU & RSI
Chuỗi đầu vào _S_SIG = "====== TIN HIEU & RSI ======";
đầu vào int Semafor_P2 = 13; nhập int Semafor_D2 = 8; // Cấp độ 2
đầu vào int Semafor_P3 = 34; đầu vào int Semafor_D3 = 21; // Cấp độ 3
input ENUM_TIMEFRAMES Filter_TF = PERIOD_H1;
input int RSI_Period = 14;
input int RSI_H1_Buy = 45;
input int RSI_H1_Sell = 55;
// Biến nội bộ
bool Web_OK = false;
datetime Last_Bar_Time = 0;
double Total_Floating_P_L = 0;
int Total_Current_Orders = 0, Total_Negative_Orders = 0;
string Brake_Reason = "";
Time_Status_Msg = "";
string News_Status_Msg = "SAN SANG";
//+------------------------------------------------------------------+
int OnInit() {
ObjectsDeleteAll(0, -1, -1);
Bình luận("");
CheckWebPermissions();
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason) {
ObjectsDeleteAll(0, "EA_");
Bình luận("");
}
void OnTick() {
if(!IsConnected() || Bars < 100) return;
CheckWebPermissions();
bool is_margin = (AccountInfoDouble(ACCOUNT_MARGIN_LEVEL) >= 2.5 * AccountInfoDouble(ACCOUNT_EQUITY) || AccountInfoDouble(ACCOUNT_MARGIN_LEVEL) == 0);
bool is_news = CheckNewsLogic();
bool is_brake = CheckSafetyBrake();
int time_state = CheckTimeState();
DrawDashboard(is_margin, is_news, is_brake, time_state);
HandleStealthExit();
if(Use_Trail) ApplyTrailingStop();
// --- DỪNG CỨNG: Phanh an toàn cam tuyet đời lênh mới và DCA ---
if(!is_brake) return;
if(Total_Current_Orders == 0) {
if(time_state == 0 || time_state == 2 || !is_margin || !is_news) return;
if(Thời gian[0] != Thời gian thanh cuối) {
int sig_level = 0;
int sema_sig = GetSemaforSignal(1, sig_level);
double rsi_big = iRSI(Symbol(), Filter_TF, RSI_Period, PRICE_CLOSE, 1);
double rsi_now = iRSI(Symbol(), 0, RSI_Period, PRICE_CLOSE, 1);
if(sema_sig == 1 && rsi_big <= RSI_H1_Buy && rsi_now <= 35) {
chuỗi order_cmt = "Vy Tuyên 17_LV" + IntegerToString(sig_level);
if(SendMarketOrder(OP_BUY, Lot_Step1, order_cmt)) Last_Bar_Time = Time[0];
}
if(sema_sig == -1 && rsi_big >= RSI_H1_Sell && rsi_now >= 65) {
chuỗi order_cmt = "Vy Tuyên 17_LV" + IntegerToString(sig_level);
if(SendMarketOrder(OP_SELL, Lot_Step1, order_cmt)) Last_Bar_Time = Time[0];
}
}
} else if(Trade_Mode == DCA_ORDER && Total_Current_Orders < Max_Orders) {
Thực thi DCA();
}
}
// --- BỘ LỘC LÊ ĐỐC QUYỀN (CHÍ XU LÝ LV2, LV3, DCA) ---
bool IsValidEAOrder() {
if(OrderMagicNumber() != Magic || OrderSymbol() != Symbol()) return false;
cmt = OrderComment();
// Su dung StringFind de chong lai viec san tu dong them [sl], [tp] vao comment
if(StringFind(cmt, "LV2") >= 0 || StringFind(cmt, "LV3") >= 0 || StringFind(cmt, "DCA") >= 0) return true;
Trả lời về sai;
}
// --- HÀM VAO LỀNH: TRUYỀN BÌNH ---
bool SendMarketOrder(int type, double lot, string cmt = "Vy Tuyen 17") {
double min_lot = SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MIN);
double step_lot = SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_STEP);
double final_lot = MathFloor(lot / step_lot) * step_lot;
if(final_lot < min_lot) final_lot = min_lot;
int ticket = OrderSend(Symbol(), type, final_lot, (type == OP_BUY ? Ask : Bid), 3, 0, 0, cmt, Magic, 0, (type == OP_BUY ? clrBlue : clrRed));
trả về (vé > 0);
}
// --- CAC LOGIC CHOT/TRAIL ---
void HandleStealthExit() {
double tl = 0, ap = 0; int t = -1, c = 0;
for(int i = OrdersTotal()-1; i >= 0; i--) {
if(OrderSelect(i, SELECT_BY_POS) && IsValidEAOrder()) {
tl += OrderLots(); ap += OrderOpenPrice() * OrderLots(); t = OrderType(); c++;
}
}
if(c == 0) return;
double avg = ap / tl;
if(t == OP_BUY && (Bid >= avg + Stealth_TP_Points*Point || Bid <= avg - Stealth_SL_Points*Point)) CloseAll();
if(t == OP_SELL && (Ask <= avg - Stealth_TP_Points*Point || Ask >= avg + Stealth_SL_Points*Point)) CloseAll();
}
void ApplyTrailingStop() {
if (Total_Negative_Orders > 0) return;
for(int i = OrdersTotal()-1; i >= 0; i--) {
if(OrderSelect(i, SELECT_BY_POS) && IsValidEAOrder()) {
if(OrderType() == OP_BUY && Bid - OrderOpenPrice() > Trail_Start * Point) {
double sl = NormalizeDouble(Bid - Trail_Step * Point, Digits);
if(OrderStopLoss() < sl) OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0, clrBlue);
}
if(OrderType() == OP_SELL && OrderOpenPrice() - Ask > Trail_Start * Point) {
double sl = NormalizeDouble(Ask + Trail_Step * Point, Digits);
if(OrderStopLoss() > sl || OrderStopLoss() == 0) OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0, clrRed);
}
}
}
}
// --- PHANH AN TOAN ---
bool CheckSafetyBrake() {
Tổng_lợi_phạt_biến_dư = 0; Tổng_lệnh_hiện_tại = 0; Tổng_lệnh_âm = 0;
for(int i = 0; i < OrdersTotal(); i++) {
if(OrderSelect(i, SELECT_BY_POS) && IsValidEAOrder()) {
Tổng số đơn hàng hiện tại++;
double p = OrderProfit() + OrderSwap() + OrderCommission();
Total_Floating_P_L += p;
if(p < 0) Total_Negative_Orders++;
}
}
if(Total_Current_Orders == 0) return true;
bool is_over_usd = (Total_Floating_P_L <= -Stop_Loss_USD);
bool is_over_ratio = (Total_Negative_Orders >= (Total_Current_Orders * Stop_Neg_Ratio));
if(is_over_usd && is_over_ratio) { Brake_Reason = "AM " + DoubleToString(Stop_Loss_USD,1) + "$"; return false; }
Trả lời về giá trị đúng;
}
// --- BẢNG ĐIỀU KHIỂN ---
void DrawDashboard(bool m, bool n, bool b, int t_s) {
int x = 30, y = 30; int r_h = 32;
DrawText("EA_Title", x, y, ">>> SEMAFOR PRO V4.6 FULL <<<", clrCyan, 14);
DrawText("EA_T", x, y+r_h, "TRANG THAI : " + Time_Status_Msg, (t_s==1?clrWhite:clrOrange), 11);
DrawText("EA_N", x, y+r_h*2, "TIN TUC (GMT): " + News_Status_Msg, (n?clrLime:clrRed), 11);
DrawText("EA_B", x, y+r_h*3, "PHANH (PHANH): " + (b?"OK:"KHOA: "+Lý_tưởng_phanh), (b?clrLime:clrRed), 11);
DrawText("EA_L", x, y+r_h*4, "LOT KHOI DIEM: " + DoubleToString(Lot_Step1, 2), clrWhite, 11);
DrawText("EA_P", x, y+r_h*5+10, "LAI LO TONG : " + DoubleToString(Total_Floating_P_L, 2) + " USD", (Total_Floating_P_L>=0?clrLime:clrYellow), 13);
}
void DrawText(string name, int x, int y, string txt, color c, int s) {
if(ObjectFind(0, name) < 0) ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
ObjectSetString(0, name, OBJPROP_TEXT, txt);
ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x);
ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y);
ObjectSetInteger(0, name, OBJPROP_COLOR, c);
ObjectSetInteger(0, name, OBJPROP_FONTSIZE, s);
ObjectSetString(0, name, OBJPROP_FONT, "Consolas");
}
// --- CAC HAM PHU ---
void ExecuteDCAManager() {
double lp=0, ll=0; int t=-1;
for(int i=OrdersTotal()-1; i>=0; i--) {
if(OrderSelect(i,SELECT_BY_POS) && IsValidEAOrder()){
lp=OrderOpenPrice(); ll=OrderLots(); t=OrderType(); break;
}
}
if(t == OP_BUY && (lp - Ask) >= DCA_Step*Point) SendMarketOrder(OP_BUY, ll*Lot_Mult, "Vy Tuyen 17_DCA");
if(t == OP_SELL && (Ask - lp) >= DCA_Step*Point) SendMarketOrder(OP_SELL, ll*Lot_Mult, "Vy Tuyen 17_DCA");
}
int CheckTimeState() {
datetime now = TimeLocal(); int m = TimeHour(now)*60 + TimeMinute(now); int d = TimeDayOfWeek(now);
if(Use_Weekly_Time && (d==0 || d==6)) { Time_Status_Msg="NGHI CUOI TUAN"; return 0; }
nếu (Use_Daily_Time) {
int s = GetMins(Daily_Start_Time), e = GetMins(Daily_End_Time);
if(m < s || m >= e) { Time_Status_Msg="NGOAI GIO (LOCAL)"; return 0; }
}
Time_Status_Msg="DANG HOAT DONG"; return 1;
}
int GetMins(string t) { string s[]; StringSplit(t,':',s); return (ArraySize(s)==2)?(int)StringToInteger(s[0])*60+(int)StringToInteger(s[1]):0; }
void CheckWebPermissions() { uchar d[], r[]; string h; Web_OK = (WebRequest("GET", NEWS_URL, "", 1500, d, r, h) != -1); }
bool CheckNewsLogic() { if(!Use_News || !Web_OK) return Web_OK; News_Status_Msg="SAN SANG"; return true; }
int GetSemaforSignal(int shift, int &level) {
double z2 = iCustom(Symbol(), 0, "ZigZag", Semafor_P2, Semafor_D2, 3, 0, shift);
double z3 = iCustom(Symbol(), 0, "ZigZag", Semafor_P3, Semafor_D3, 3, 0, shift);
mức = 0;
nếu(z3 > 0) {
cấp độ = 3;
return (MathAbs(z3 - Low[shift]) < Point) ? 1 : -1;
}
nếu(z2 > 0) {
Cấp độ = 2;
return (MathAbs(z2 - Low[shift]) < Point) ? 1 : -1;
}
trả về 0;
}
void CloseAll() {
for(int i=OrdersTotal()-1; i>=0; i--) {
if(OrderSelect(i,SELECT_BY_POS) && IsValidEAOrder())
OrderClose(OrderTicket(), OrderLots(), (OrderType()==OP_BUY?Bid:Ask), 3, clrWhite);
}
}
"Với đoạn mã trên, tôi cần cải thiện các điểm vào lệnh và tối ưu hóa lợi nhuận."
SẢN PHẨM SAU KHI HOÀN THÀNH: ✅ Mã nguồn đầy đủ (.mq4) + các tệp đã biên dịch (.ex4). ✅ Mã nguồn sạch, có cấu trúc tốt và được chú thích đầy đủ. ✅ Hướng dẫn cài đặt và thiết lập. ✅ Không phụ thuộc vào bên thứ ba. ✅ Quyền sở hữu hoàn toàn mã nguồn sau khi hoàn thành. ✅ Bảo hành hoạt động (sửa lỗi) tối thiểu từ 3 đến 6 tháng. ✅ Hỗ trợ liên tục (phản hồi nhanh) trong trường hợp có sự cố với EA mà không mất thêm phí. ✅ Giá cả và điều khoản đã thỏa thuận (thanh toán một lần). ✅ Giao tiếp qua Telegram. ✅ Phiên bản dùng thử 5 ngày trên tài khoản đã được xác minh trước khi thanh toán/chuyển khoản cuối cùng.
-
Phạm vi kiểm thử ngược: ✅ Thời gian kiểm thử chiến lược là 5 năm (1 tháng 1 năm 2022 – 20 tháng 12 năm 2025). Phải cung cấp thông tin chi tiết về quy trình kiểm thử ngược, bao gồm nguồn dữ liệu và chất lượng dữ liệu/dữ liệu tick.
Bộ mã hóa trên tôi cần cải thiện điểm lợi nhuận và mức độ tối ưu.
BÀN GIAO SAU KHI HOÀN THÀNH:
✅ Đầy đủ nguồn mã hóa (.mq4) + các tệp đã được biên dịch
✅ Mã nguồn sạch sẽ, có cấu trúc và được chú thích đầy đủ.
✅ Hướng dẫn cài đặt và cài đặt
✅ Không phụ thuộc vào thứ ba
✅ Sở hữu toàn bộ mã nguồn sau khi hoàn thành
✅ Bảo vệ hoạt động ở mức tối thiểu từ 3 đến 6 tháng
✅ Hỗ trợ liên tục (phản hồi nhanh) trong các trường hợp có vấn đề với EA mà không tính thêm phí.
✅ Giá cả và điều khoản được phép (mua một lần)
✅ Trao đổi qua Telegram
✅ Có bản thử nghiệm trên tài khoản được xác thực 5 ngày trước khi thanh toán/chuyển khoản cuối cùng
* Phạm vi kỹ thuật đảo ngược:
✅ Có thời hạn kiểm tra chiến lược trong vòng 5 năm (1 tháng 1 năm 2022 – 20 tháng 12 năm 2025) Cần cung cấp thông tin chi tiết về quá trình phân tích ngược, bao gồm nguồn dữ liệu và chất lượng/dấu vết dữ liệu.