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
Bộ sách Giao Dịch Thực Chiến của Trader Chuyên Nghiệp

Bộ sách tổng hợp những phương pháp giao dịch hiệu quả cao của những Trader chuyên nghiệp
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

  • Nhật Hoài trong Lập trình MQL - Expert Advisor - Indicator 163,013 Xem / 1,109 Trả lời
  • Mạc An trong Phân tích Forex - Vàng - Hàng hóa 1,431 Xem / 58 Trả lời
  • Quíc Óp trong Phân tích Forex - Vàng - Hàng hóa 603 Xem / 12 Trả lời
  • Quíc Óp trong Phân tích Forex - Vàng - Hàng hóa 852 Xem / 16 Trả lời
  • Bianas trong Phân tích Forex - Vàng - Hàng hóa 2,396 Xem / 1 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