Thank you so much for sharing this article, and the insight. Great idea. I Implemented some independent position handling and got it working on hedging account (my broker)
Dear author, I reread the TargetFunction() code several times and it seems you made some mistakes.
1. When calculating profit on a position, you make a double summation of the profit.
if (!truTradeTime [h]) {
if (posType != 0) { // If there is an open position
posClPrice = rates [h].open; // Close at the bar opening price
profit = (posClPrice - posOpPrice) * signal - 0.00003; // Commissionif (profit > 0.0) allProfit += profit;
else allLoss += -profit;
if (posType == 1) buys++;
else sells++;
allProfit += profit;
posType = 0; // Reset position
}
continue; // Skip non-trading time
}
if ((posType == 1 && signal == -1) || (posType == -1 && signal == 1)) {
posClPrice = rates [h].open; // Close at the opening price of the current bar
profit = (posClPrice - posOpPrice) * signal - 0.00003; // Calculation of profit// Profit/loss accountingif (profit > 0.0) allProfit += profit;
else allLoss += -profit;
// Statistics on transactionsif (posType == 1) buys++;
else sells++;
allProfit += profit;
posType = 0; // Position closed
}
2. The ko coefficient is not used when calculating the adaptability index.
double ko = 1.0;
if (sells == 0 || buys == 0) return -DBL_MAX;
if (sells / buys > 1.5 || buys / sells > 1.5) ko = 0.001;
return (allProfit / (allLoss + DBL_EPSILON)) * dealsNumb;
Dear author, I reread the TargetFunction() code several times and it seems you made some mistakes.
1. When calculating profit on a position, you make a double summation of the profit.
2. You do not use the ko coefficient when calculating the adaptability index.
1. Yes, you are right, remove the lines at the end of both code blocks
allProfit += profit;
to make it look like this:
f (!truTradeTime [h]) {
if (posType != 0) { // If there is an open position
posClPrice = rates [h].open; // Close at the bar opening price
profit = (posClPrice - posOpPrice) * signal - 0.00003; // Commissionif (profit > 0.0) allProfit += profit;
else allLoss += -profit;
if (posType == 1) buys++;
else sells++;
//allProfit += profit;
posType = 0; // Reset position
}
continue; // Skip non-trading time
}
if ((posType == 1 && signal == -1) || (posType == -1 && signal == 1)) {
posClPrice = rates [h].open; // Close at the opening price of the current bar
profit = (posClPrice - posOpPrice) * signal - 0.00003; // Calculation of profit// Profit/loss accountingif (profit > 0.0) allProfit += profit;
else allLoss += -profit;
// Statistics on transactionsif (posType == 1) buys++;
else sells++;
//allProfit += profit;
posType = 0; // Position closed
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Thank you so much for sharing this article, and the insight. Great idea. I Implemented some independent position handling and got it working on hedging account (my broker)
You are the best.
Super!
Dear author, I reread the TargetFunction() code several times and it seems you made some mistakes.
1. When calculating profit on a position, you make a double summation of the profit.
2. The ko coefficient is not used when calculating the adaptability index.Dear author, I reread the TargetFunction() code several times and it seems you made some mistakes.
1. When calculating profit on a position, you make a double summation of the profit.
2. You do not use the ko coefficient when calculating the adaptability index.