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);
}
}
}
}
}
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
Giới thiệu sách Trading hay
Mô Hình Biểu Đồ - Phương Pháp Hiệu Quả Để Tìm Kiếm Lợi Nhuận
Được xem là cẩm nang về mô hình biểu đồ của các nhà đầu tư, giao dich tài chính toàn cầu và là kiến thức bắt buộc phải nắm về Phân Tích Kỹ Thuật
Bài viết liên quan