初学者的问题 MQL5 MT5 MetaTrader 5 - 页 1467

 
Alexey Viktorov #:

是什么意思?你是否认为,为了从一个数组向另一个数组(某个 temp[])复制一定数量的元素,应该在复制之前设置数组的大小 ArrayResize(temp, new_size); ?????

当然不是,我的意思是数组的大小总是已知的,或者是可以知道的。而且可以也应该对索引超限进行控制。

 
Valeriy Yastremskiy #:

当然不是,我的意思是数组的大小总是已知的,或者是可以知道的。而且可以也必须对索引超限进行控制。

你可以控制它,但并不总是必要的...

 
Alexey Viktorov #:

控制是可能的,但并非总是必要的....

嘿嘿,那就超越极限后再开始吧))))
 
Valeriy Yastremskiy #:
Hehe, then start after going beyond)))))

看看这里...

关于交易、自动交易系统和测试交易策略的论坛。

来自初学者的问题 MQL5 MT5 MetaTrader 5

Alexey Viktorov, 2023.06.27 21:19

问题出在哪里?声明一个数组temp[],将30 个元素 复制到数组中,然后查找 最小值/最大值的索引如果最后少于 30 个元素,就会复制剩下的元素。在这种情况下,我宁愿使用 while() 循环。


为什么要控制 temp[] 数组的大小?

你应该控制从我们复制到 temp[] 的数组的大小,我不反对......但为什么我需要控制我们正在寻找最大/最小值的数组的大小呢?

 
请提醒我,如果从 EA 调用的 DLL 中调用网络套接字连接,是否需要在终端设置 中允许主机地址?
 
leonerd 终端设置 中允许主机地址?

是的,终端只会明确访问允许的地址。

 
Valeriy Yastremskiy #:

是的,终端机只在授权的地方进行探测。

所以,不是终端在窥探,而是 DLL 在窥探。

 
leonerd #:

因此,参与其中的不是终端,而是 DLL。

在 mt 中,dll 不需要授权主机,只要允许在 mt 中使用 dll 即可。

 
除了通过 dll 导入 ShellExecuteW 之外,您能告诉我如何打开文件 吗?winapi.mqh 中是否有类似函数?
 

能否请您告诉我这段代码在哪里运行不正常?它随心所欲地随机读取记录,并没有找到所有记录,而且在重新开始时会给出新的结果。

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2020, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
input int                  RULE1  = 0;
input int                  RULE2  = 0;
input int                  RULE3  = 0;
input int                  RULE4  = 0;
input bool                 FastComb  = 1;
input int                  FileLine= 20000;
input string               InpFileName="Report.csv";
//+------------------------------------------------------------------+
//| Structure Positions                                              |
//+------------------------------------------------------------------+
struct STRUCT_POSITION
  {
   ENUM_POSITION_TYPE pos_type;              // position type
   bool              waiting_transaction;    // waiting transaction, "true" -> it's forbidden to trade, we expect a transaction
   ulong             waiting_order_ticket;   // waiting order ticket, ticket of the expected order
   bool              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];
///////////////////////////
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   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);
     }
   else
      PrintFormat("Не удалось открыть файл %s, Код ошибки = %d",InpFileName,GetLastError());
  }
//+------------------------------------------------------------------+