İş Gereklilikleri
Link of the article: https://www.mql5.com/en/articles/197
As in the article, I want to create a multithreaded calculation system. Basically, I want to calculate an array as quickly as possible (using multithreads). Below is the code snippet that takes to calculate:
if (MODULE == 0 || (MODULE == 1 && !isSessionCalculated)) {
string progressBar = "";
int progressLength = 100;
for(int i = 0; i < total_combinations; ++i) {
CombinationResults result;
for(int j = 0; j < 13; ++j) {
weights[j] = combinations[i][j];
result.weights[j] = weights[j];
}
ArrayResize(signals, 0);
GetAndFilterSignals(weights, currentDateTimeStr);
double total_profit = 0;
int qtd_wins = 0;
for(int k = 0; k < ArraySize(signals); ++k) {
double trade_result = SimulateTrade(signals[k].date, signals[k].strength);
if (trade_result > 0) {qtd_wins++;}
total_profit += trade_result;
}
int T = ArraySize(signals);
double P = T > 0 ? total_profit / (double)T : 0;
double W = T > 0 ? qtd_wins / (double)T : 0;
double R = TAKE_RATIO;
double K = T > 0 ? W - ((1 - W) / R) : 0;
result.T = T;
result.W = W;
result.P = NormalizeDouble(P*100000, 2);
result.K = K;
results[i] = result;
int currentProgress = (i + 1) * progressLength / total_combinations;
progressBar = "[";
for(int j = 1; j <= progressLength; j++) {
if(j <= currentProgress) {
progressBar += "|";
} else {
progressBar += " ";
}
}
progressBar += "] " + IntegerToString(currentProgress) + "/100 (" + total_combinations + ")";
Comment(progressBar);
QuickSort(results, 0, ArraySize(results)-1);
isSessionCalculated = true;
}