What is the problem? Declare an array temp[] and copy 30 elements into it and look for the index of the minimum/maximum value. And if at the end there will be less than 30, it will copy how many are left. And in this case, I'd rather use the while() loop.
Why should I control the size of the temp[] array?
You should control the size of the array from where we copy to temp[], I don't argue... But why do I need to control the size of the array where we are looking for the maximum\minimum?
Could you please tell me where this code is not working correctly? It reads records randomly as it wants, doesn't find everything, and gives new results at a new start.
//+------------------------------------------------------------------+//| ProjectName |//| Copyright 2020, CompanyName |//| http://www.companyname.net |//+------------------------------------------------------------------+inputint RULE1 = 0;
inputint RULE2 = 0;
inputint RULE3 = 0;
inputint RULE4 = 0;
inputbool FastComb = 1;
inputint FileLine= 20000;
inputstring InpFileName="Report.csv";
//+------------------------------------------------------------------+//| Structure Positions |//+------------------------------------------------------------------+struct STRUCT_POSITION
{
ENUM_POSITION_TYPE pos_type; // position typebool waiting_transaction; // waiting transaction, "true" -> it's forbidden to trade, we expect a transactionulong waiting_order_ticket; // waiting order ticket, ticket of the expected orderbool transaction_confirmed; // transaction confirmed, "true" -> transaction confirmed//--- Constructor
STRUCT_POSITION()
{
pos_type = WRONG_VALUE;
waiting_transaction = false;
waiting_order_ticket = 0;
transaction_confirmed = false;
}
};
STRUCT_POSITION SPosition[];
///////////////////////////struct Report
{
long Pass;
double Result;
double Profit;
double Payoff;
double ProfitFactor;
double RecoveryFactor;
double SharpeRatio;
long Custom;
double EquityDD;
long Trades;
long Field1;
long Field2;
long Field3;
long Field4;
long Field5;
long Field6;
long Field7;
long Field8;
long Field9;
};
long ProfitComb[20001][10];
/////////////////////////////+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+intOnInit()
{
if(FastComb)
{
ArrayInitialize(ProfitComb,-1);
ReportListComb();
int FindComb=0;
for(int i=0; i<=FileLine; i++)
{
if(RULE1==ProfitComb[i][1] && RULE2==ProfitComb[i][2] && RULE3==ProfitComb[i][3] && RULE4==ProfitComb[i][4])
{
FindComb=1;
break;
}
}
if(FindComb==0 && RULE1!=0)
return(INIT_PARAMETERS_INCORRECT);
}
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+void ReportListComb()
{
Report ReportStr[];
ResetLastError();
ArrayResize(ReportStr,FileLine);
string subfolder="Data";
int file_handle=FileOpen(subfolder+"\\Report.csv",FILE_READ|FILE_WRITE|FILE_CSV|FILE_ANSI|FILE_COMMON,';');
if(file_handle!=INVALID_HANDLE)
{
int i=0;
while(!FileIsEnding(file_handle))
{
i++;
ReportStr[i].Pass=StringToInteger(DoubleToString(FileReadNumber(file_handle),0));
ReportStr[i].Result=StringToDouble(FileReadString(file_handle));
ReportStr[i].Profit=FileReadNumber(file_handle);
ReportStr[i].Payoff=FileReadNumber(file_handle);
ReportStr[i].ProfitFactor=FileReadNumber(file_handle);
ReportStr[i].RecoveryFactor=FileReadNumber(file_handle);
ReportStr[i].SharpeRatio=FileReadNumber(file_handle);
ReportStr[i].Custom=StringToInteger(DoubleToString(FileReadNumber(file_handle),0));
ReportStr[i].EquityDD=FileReadNumber(file_handle);
ReportStr[i].Trades=StringToInteger(DoubleToString(FileReadNumber(file_handle),0));
ReportStr[i].Field1=StringToInteger(DoubleToString(FileReadNumber(file_handle),0));
ReportStr[i].Field2=StringToInteger(DoubleToString(FileReadNumber(file_handle),0));
ReportStr[i].Field3=StringToInteger(DoubleToString(FileReadNumber(file_handle),0));
ReportStr[i].Field4=StringToInteger(DoubleToString(FileReadNumber(file_handle),0));
ReportStr[i].Field5=StringToInteger(DoubleToString(FileReadNumber(file_handle),0));
ReportStr[i].Field6=StringToInteger(DoubleToString(FileReadNumber(file_handle),0));
ReportStr[i].Field7=StringToInteger(DoubleToString(FileReadNumber(file_handle),0));
ReportStr[i].Field8=StringToInteger(DoubleToString(FileReadNumber(file_handle),0));
ReportStr[i].Field9=StringToInteger(DoubleToString(FileReadNumber(file_handle),0));
ProfitComb[i][1]=ReportStr[i].Field1;
ProfitComb[i][2]=ReportStr[i].Field2;
ProfitComb[i][3]=ReportStr[i].Field3;
ProfitComb[i][4]=ReportStr[i].Field4;
ProfitComb[i][5]=ReportStr[i].Field5;
ProfitComb[i][6]=ReportStr[i].Field6;
ProfitComb[i][7]=ReportStr[i].Field7;
ProfitComb[i][8]=ReportStr[i].Field8;
ProfitComb[i][9]=ReportStr[i].Field9;
}
FileClose(file_handle);
}
elsePrintFormat("Не удалось открыть файл %s, Код ошибки = %d",InpFileName,GetLastError());
}
//+------------------------------------------------------------------+
I can't understand what rates_total and prev_calculated mean in the end.
The documentation says: The first parameter rates_total contains the number of bars available to the indicator for calculation, and corresponds to the number of bars available on the chart.
For example MA5, average of 5 bars, set to display 100 bars. Then the indicator will calculate from the 104th to the 100th bar and will start drawing the line from the 100th bar. Then rates_total=5, or 100, or 104?
Of course not, I meant that the array size is always known or can be known. And it can and must be controlled for index overrun.
You can control it, but it is not always necessary...
Controlling is possible, but not always necessary....
Hehe, then start after going beyond)))))
Here's a look...
Forum on trading, automated trading systems and testing trading strategies.
Questions from beginners MQL5 MT5 MetaTrader 5
Alexey Viktorov, 2023.06.27 21:19
What is the problem? Declare an array temp[] and copy 30 elements into it and look for the index of the minimum/maximum value. And if at the end there will be less than 30, it will copy how many are left. And in this case, I'd rather use the while() loop.
Why should I control the size of the temp[] array?
You should control the size of the array from where we copy to temp[], I don't argue... But why do I need to control the size of the array where we are looking for the maximum\minimum?
Yes, the terminal only pokes through the allowed ones explicitly.
Yeah, the terminal is only poking around the authorised ones.
So it's not the terminal that's poking around, it's the DLL.
So it's not the terminal that's going to get involved, it's the DLL.
A dll does not need an authorised host in mt. it is enough to allow the use of a dll in mt. and the dll itself can do absolutely anything.
Could you please tell me where this code is not working correctly? It reads records randomly as it wants, doesn't find everything, and gives new results at a new start.
I can't understand what rates_total and prev_calculated mean in the end.
The documentation says: The first parameter rates_total contains the number of bars available to the indicator for calculation, and corresponds to the number of bars available on the chart.
For example MA5, average of 5 bars, set to display 100 bars. Then the indicator will calculate from the 104th to the 100th bar and will start drawing the line from the 100th bar. Then rates_total=5, or 100, or 104?