MQL4自编指标学习3

0
回复
6151
查看
[复制链接]

360

主题

15

回帖

2467

积分

超级版主

积分
2467
来源: 2019-11-23 18:54:06 显示全部楼层 |阅读模式
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.


  1. int handle = FileOpen("file.csv", FILE_CSV|FILE_WRITE, ";");
  2.   if(handle>0)
  3.     {
  4.      // table column headers recording
  5.      FileWrite(handle, "Time;Open;High;Low;Close;Volume");
  6.      // data recording
  7.      for(int i=0; i<Bars; i++)
  8.      {
  9.        FileWrite(handle, Time[i], Open[i], High[i], Low[i], Close[i], Volume[i]);
  10.       }
  11. FileClose(handle);
  12. }

复制代码
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.
  1. int limit;
  2.      int counted_bars=IndicatorCounted();
  3.   //---- check for possible errors
  4.      if(counted_bars<0)
  5.          return(-1);
  6.   //---- the last counted bar will be recounted
  7.      if(counted_bars>0)
  8.      {
  9.          Print(counted_bars);  //2018.11.28 13:32:22.843        柱体标号索引学习 EURUSD,Monthly: 269

  10.          counted_bars--;
  11.      }
  12.      limit=Bars-counted_bars;
  13.   //---- main loop
  14.      for(int i=0; i<limit; i++)
  15.        {
  16.         //---- ma_shift set to 0 because SetIndexShift called abowe
  17.         ExtBlueBuffer[i]=iMA(NULL,0,5,0,MODE_SMMA,PRICE_MEDIAN,i);

  18.        }
复制代码



04_1.jpg




回复

使用道具 举报

您需要登录后才可以回帖 登录 | 免费注册
关注微信