首页 > 解决方案 > 有没有一种方法可以在数组中找到彼此最近的数字

问题描述

我现在代码中的逻辑是这样的

步骤1。扫描过去的 100 个或更多烛台

第2步。收集并存储所有 100 个烛台的日期,以找出每个烛台的最高点

第三步。浏览所有烛台高数据并找到彼此靠近的数据(仍然不知道我会怎么做)

第4步。绘制 H 线

现在我遇到的第一个问题是我将如何对其进行编码,以便我能够找到哪些烛台数字彼此接近以绘制 HLine。

extern int candleCount = 100;
int totalHigh;
int FinishingTotalHigh;

int totalLow;
int FinishingTotalLow;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  totalHigh = 0;
  totalLow = 0;
  
// Initializing the variables.
   double Highest = High[0];
   double Lowest = Low[0];
      Alert("");
      Alert("");
      Alert("");
      Alert("");
      Alert("");
   // Scan the 100 candles and update the values of the highest and lowest.
   for (int i = 0; i <= candleCount; i++)
   {
     
      //Alert(i+"Index Data: "+High[i]);
      totalHigh = High[i] + totalHigh;
       totalLow = Low[i] + totalLow;
      
      if (High[i] > Highest) Highest = High[i];
      if (Low[i] < Lowest) Lowest = Low[i];
   }
   FinishingTotalHigh = totalHigh/candleCount;
   FinishingTotalLow = totalLow/candleCount;
   // Print the result.

   Alert("Highest price found is "+Highest);
   Alert("Lowest price found is "+Lowest);
   Alert("TotalHigh: "+FinishingTotalHigh);
   Alert("TotalLow: "+FinishingTotalLow);
   
   

  }
//+------------------------------------------------------------------+

标签: mql4mql

解决方案


推荐阅读