Trợ giúp đoạn code lợi nhuận của trade sau cùng

Trợ giúp đoạn code lợi nhuận của trade sau cùng

Trợ giúp đoạn code lợi nhuận của trade sau cùng

hoatruong

Member
11
0
Chào các bạn.
Mình đang tập tành viết code và mình đang bi vướng mắc 1 chỗ là. Mình muốn lấy ra lợi nhuận của trade sau cùng xem là âm hay dương. sau đó , nếu dương thì sẽ gán Lot mới bằng như cũ. Nếu âm thì tăng Lot mới lên gấp 1.5 lần của Lot đánh trước đó.

Mong các bạn giúp đỡ !!!

Đoạn code vậy bị sai chỗ nào vậy các bạn ????

double AdvancedMM()
{
double AdvancedMMLots = 0;
int SystemHistoryOrders=0;
for( int x=0;x<OrdersHistoryTotal();x++)
{ OrderSelect(x,SELECT_BY_POS ,MODE_HISTORY);
if (OrderMagicNumber()==MagicNumber) SystemHistoryOrders++;

}
if(SystemHistoryOrders<2) return(Lots);
for(int i=(OrdersHistoryTotal()-1);i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);
if(OrderMagicNumber()== MagicNumber )
{

if(OrderProfit()>0) return(OrderLots());
if(OrderProfit()<0)
return(OrderLots()*1.51);

}
}
return(AdvancedMMLots);
 

Giới thiệu sách Trading hay
Giao Dịch Theo Xu Hướng Để Kiếm Sống

Sách chia sẻ chiến lược giao dịch, tâm lý, phương pháp quản lý vốn thực chiến của Trader 18 năm kinh nghiệm giao dịch theo xu hướng
Bạn nào giải thích giúp mình đoạn code này với : Helpp me
double AdvancedMM()
{
int i;
double AdvancedMMLots = 0;
bool profit1=false;
int SystemHistoryOrders=0;
for( i=0;i<OrdersHistoryTotal();i++)
{ OrderSelect(i,SELECT_BY_POS ,MODE_HISTORY);
if (OrderMagicNumber()==MagicNumber) SystemHistoryOrders++;
}
bool profit2=false;
int LO=0;
if(SystemHistoryOrders<2) return(Lots);
for( i=OrdersHistoryTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS ,MODE_HISTORY))
if (OrderMagicNumber()==MagicNumber)
{
if(OrderProfit()>=0 && profit1) return(Lots);
if( LO==0)
{ if(OrderProfit()>=0) profit1=true;
if(OrderProfit()<0) return(OrderLots());
LO=1;
}
if(OrderProfit()>=0 && profit2) return(AdvancedMMLots);
if(OrderProfit()>=0) profit2=true;
if(OrderProfit()<0 )
{ profit1=false;
profit2=false;
AdvancedMMLots+=OrderLots();
}
}
}
return(AdvancedMMLots);
}
 
Mình ko đi vào nghiên cứu đoạn code của bạn.

Theo mình thường làm thì kiểm tra profit của lệnh đang chạy và gán giá trị của Lot mới (theo cấp số cộng hoặc cấp số nhân) cho lệnh mới ngay trước thời điểm đóng lệnh. Ví dụ:

Khai báo Lots = xxx
Giả sử tăng volumn theo cấp số cộng với LotMore = yyy

Khi đóng lệnh với 1 điều kiện nào đó ta sẽ thêm điều kiện:

Nếu (OrderProfit(() <= 0) thực hiện đóng lệnh ta sẽ thêm 1 câu lệnh gán
Lots = OrderLots() + LotMore vào trước lệnh OrderClose

Nếu (OrderProfit(() > 0) thì gán Lots = xxx về giá trị ban đầu rồi mới thực hiện OrderClose

Bạn thử xem.
 
Mình ko đi vào nghiên cứu đoạn code của bạn.

Theo mình thường làm thì kiểm tra profit của lệnh đang chạy và gán giá trị của Lot mới (theo cấp số cộng hoặc cấp số nhân) cho lệnh mới ngay trước thời điểm đóng lệnh. Ví dụ:

Khai báo Lots = xxx
Giả sử tăng volumn theo cấp số cộng với LotMore = yyy

Khi đóng lệnh với 1 điều kiện nào đó ta sẽ thêm điều kiện:

Nếu (OrderProfit(() <= 0) thực hiện đóng lệnh ta sẽ thêm 1 câu lệnh gán
Lots = OrderLots() + LotMore vào trước lệnh OrderClose

Nếu (OrderProfit(() > 0) thì gán Lots = xxx về giá trị ban đầu rồi mới thực hiện OrderClose

Bạn thử xem.

Cảm ơn bạn nhiều!
Nhưng mình không để yêu cầu đóng lệnh mà lệnh chỉ close khi chạm TP hoặc SL(Có trailing stop). VÌ vậy mình muốn lấy ra lợi nhuận của trade cuối cùng để xem là lời hay lỗ rồi mới gán giá trị mới cho lệnh mới
 
Đoạn code vậy bị sai chỗ nào vậy các bạn ????


double AdvancedMM()
{
double AdvancedMMLots = 0;
int SystemHistoryOrders=0;
for( int x=0;x<OrdersHistoryTotal();x++)
{ OrderSelect(x,SELECT_BY_POS ,MODE_HISTORY);
if (OrderMagicNumber()==MagicNumber) SystemHistoryOrders++;

}
if(SystemHistoryOrders<2) return(Lots);
for(int i=(OrdersHistoryTotal()-1);i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);
if(OrderMagicNumber()== MagicNumber )
{

if(OrderProfit()>0) return(OrderLots());
if(OrderProfit()<0)
return(OrderLots()*1.51);

}
}
return(AdvancedMMLots);

Tôi nghĩ bạn sai tại dòng chữ in đậm.

bool OrderSelect(
int index, // index or order ticket
int select, // flag
int pool=MODE_TRADES // mode
);
It returns true if the function succeeds, otherwise falses.
 
Chỉnh sửa lần cuối:
Đây bạn nhé:

double AdvancedMM()
{
double AdvancedMMLots = 0;
int SystemHistoryOrders=0;
double Lot;
for( int x=1;x<OrdersHistoryTotal();x++)
{
if (OrderSelect(x-1,SELECT_BY_POS ,MODE_HISTORY))
if(OrderMagicNumber()==MagicNumber) //|
{
if(OrderSymbol()==Symbol())
SystemHistoryOrders++;
if(SystemHistoryOrders=1)
{
if(OrderProfit()>0) Lot = OrderLots();
if(OrderProfit()<0) Lot = 1.5* OrderLots();
}
}

}
return Lot;
}
 

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

  • DuongHuy trong Hệ thống giao dịch - Trading system 37,489 Xem / 18 Trả lời
  • Mạc An trong Phân tích Forex - Vàng - Hàng hóa 1,561 Xem / 94 Trả lời
  • DuongHuy trong Phân tích Forex - Vàng - Hàng hóa 367 Xem / 29 Trả lời
  • Quíc Óp trong Phân tích Forex - Vàng - Hàng hóa 345 Xem / 18 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