市场解说员 发表于 2019-11-23 18:54:06

MQL4自编指标学习3

MQL4自编指标学习3-Close[] Open[] High[] Low[] IndicatorCounted()学习1 预定义数组Close[]Open[] High[] Low[]学习

四个数据是预定义数据,保存当前图表每个柱子的开盘、收盘、最高、最低的价格,本文仅以Close[]数组进行学习,其他三个原理相同。

Series array that contains close prices for each bar of the current chart.

Series array elements are indexed in the reverse order, i.e., from the last one to the first one. The current bar which is the last in the array is indexed as 0. The oldest bar, the first in the chart, is indexed as Bars-1.


int handle = FileOpen("file.csv", FILE_CSV|FILE_WRITE, ";");
if(handle>0)
    {
   // table column headers recording
   FileWrite(handle, "Time;Open;High;Low;Close;Volume");
   // data recording
   for(int i=0; i<Bars; i++)
   {
       FileWrite(handle, Time, Open, High, Low, Close, Volume);
      }
FileClose(handle);
}

2 函数IndicatorCounted()学习

Returned value

The amount of bars not changed after the indicator had been launched last.

Note

The most calculated bars do not need any recalculation. In most cases, same count of index values do not need for recalculation. The function is used to optimize calculating.
int limit;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0)
         return(-1);
//---- the last counted bar will be recounted
   if(counted_bars>0)
   {
         Print(counted_bars);//2018.11.28 13:32:22.843        柱体标号索引学习 EURUSD,Monthly: 269

         counted_bars--;
   }
   limit=Bars-counted_bars;
//---- main loop
   for(int i=0; i<limit; i++)
       {
      //---- ma_shift set to 0 because SetIndexShift called abowe
      ExtBlueBuffer=iMA(NULL,0,5,0,MODE_SMMA,PRICE_MEDIAN,i);

       }








页: [1]
查看完整版本: MQL4自编指标学习3