E dân cơ khí cần Cao nhân sửa code MT4 giúp e với !!!

E dân cơ khí cần Cao nhân sửa code MT4 giúp e với !!!

E dân cơ khí cần Cao nhân sửa code MT4 giúp e với !!!

bachviet

New Member
1
1
e có tập tành học và copy được đoạn code như dưới. Compile thì không thấy lỗi nhưng khi đưa vào MT4 thì im lìm không thấy chạy gì. Pro nào giúp e sửa lỗi này với ạ. E cảm ơn mọi người nhiều nhiều.



double takeProfit = 50 * Point;
double openPrice[5];
int ticketLimit[5], ticketStop[5];
void OnStart()
{
double prices[] = {1982, 1984, 1985, 1987, 1988};
for(int i=0; i<ArraySize(prices); i++)
{
// Đặt lệnh buy limit
ticketLimit = OrderSend(Symbol(), OP_BUYLIMIT, 0.1, prices, 3, prices-10*Point, prices+10*Point, "Buy Limit", 0, 0, Green);
openPrice = prices;

if(ticketLimit < 0)
{
Print("Error ", GetLastError());
}
else
{
Print("Buy Limit order placed at price ", prices);
}

// Đặt lệnh buy stop
ticketStop = OrderSend(Symbol(), OP_BUYSTOP, 0.1, prices, 3, prices+10*Point, prices-10*Point, "Buy Stop", 0, 0, Blue);

if(ticketStop < 0)
{
Print("Error ", GetLastError());
}
else
{
Print("Buy Stop order placed at price ", prices);
}
}
}
void OnTick()
{
for(int i=0; i<5; i++)
{
if(ticketLimit > 0)
{
// Kiểm tra nếu giá đạt take profit
if(Bid - openPrice >= takeProfit)
{
// Đóng vị thế buy limit
int closeResult1 = OrderClose(ticketLimit, 0.1, Bid, 3, Blue);
if(closeResult1 < 0)
{
Print("Error closing limit order: ", GetLastError());
}
else
{
Print("Limit order closed successfully");
}
// Đóng vị thế buy stop
int closeResult2 = OrderClose(ticketStop, 0.1, Bid, 3, Blue);
if(closeResult2 < 0)
{
Print("Error closing stop order: ", GetLastError());
}
else
{
Print("Stop order closed successfully");
}
// Đặt lại lệnh buy limit
ticketLimit = OrderSend(Symbol(), OP_BUYLIMIT, 0.1, openPrice, 3, openPrice-10*Point, openPrice+10*Point, "Buy Limit", 0, 0, Green);
openPrice = Bid;

if(ticketLimit < 0)
{
Print("Error ", GetLastError());
}
else
{
Print("Buy Limit order placed at price ", openPrice);
}

// Đặt lại lệnh buy stop
ticketStop = OrderSend(Symbol(), OP_BUYSTOP, 0.1, openPrice, 3, openPrice+10*Point, openPrice-10*Point, "Buy Stop", 0, 0, Blue);
if(ticketStop < 0)
{
Print("Error ", GetLastError());
}
else
{
Print("Buy Stop order placed at price ", openPrice);
}
}
}
}
}
 

Đính kèm

  • demo.mq4
    5.5 KB · Xem: 1

Giới thiệu sách Trading hay
Phương Pháp VPA - Kỹ Thuật Nhận Diện Dòng Tiền Thông Minh bằng Hành Động Giá kết hợp Khối Lượng Giao Dịch

Phương pháp VPA - Volume Price Analysis - là phương pháp Price Action hướng dẫn ĐỌC GIÁ / NẾN kết hợp với KHỐI LƯỢNG GIAO DỊCH để tìm ra hướng đi của DÒNG TIỀN THÔNG MINH
Chào bạn, mình chuyên về MT5.
Nhưng mình có thể góp ý như sau:
1. không biết bạn sử dụng cho cặp tiền nào.
2. Là giá vùng giá vào lệnh không nên sử dụng mặc định giới hạn trong mảng Price,
Cách bạn dùng toán tử OpenPrice=Price mình đã thấy bị sai rồi vì đó là mảng không phải là biến thông thường. Nên sử dụng hàm CopyBuffer để sao chép mảng này sang mảng kia
3. Nếu bạn đặt Buystop thì giá phải cao hơn giá Ask hiện tại thì nó mới vào lệnh.
SellStop thì giá nhỏ hơn giá Bid hiện tại thì nó mới vào lệnh
Nên không biết điều kiện nó có thỏa mãn hay không.
Đó là góp ý của mình bạn xem lại nhé.
 

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