官网2006年的这篇老文《Multiple Null Bar Re-Count in Some Indicators》看得头晕,不过很多指标确实使用这种方法,能有效解决占用计算机资源的问题。
作者最后总结道:
1. The most difficult is to determine all variables that have values accumulated on previous ticks. It must be taken into consideration that it is sometimes necessary to memorize some variables and bar numbers, the bar can change on the next ticks and these saved values will not have any sense then. In such a case, the time of bar opening must be memorized (MEMORY_bar_time = Time[lastlowBar]). Then the current state of the bar can be restored using this memorized time (iBarShift(NULL,0,MEMORY_bar_time, TRUE)). It can happen that there are several loops of indicator calculation and every loop contains variables to be memorized, the same variable in different loops having to be memorized separately at the end on the second and the first bar or at the beginning of the loop on the first and null bar.
在先前的价位上确定所有的变量是最难的。我们必须考虑到,有时需要记录一些变量和柱数,此柱可在下一个价位变化,但保存的值却没有任何改变。在这个案例中,柱体开始的时间必须被记录(MEMORY_bar_time = Time[lastlowBar])。然后该柱的当前状态可以通过被记录的时间(iBarShift(NULL,0,MEMORY_bar_time,TRUE))恢复。指标计算了几个循环后,每个循环都有变量要储存,同样的变量在不同的循环里必须被分开储存,如在第二柱或第一柱循环运算结束时,或在第一柱或现柱开始循环的时候。
2. It is desirable to introduce variables with the names that correspond with the initial variables. It is better to declare these variables as non-local at the beginning of the indicator code. These variables can often be declared as static ones in the indicator code itself immediately after the start() operator.
初始化的变量要与申明的变量名字一致。最好在指标代码的开始处申明全局变量。在 start() 运行后,在指标代码里,这些变量经常被立即申明作为静态全局变量。
3. The code of restoring of variables must be introduced before all loops of the indicator calculation.
在所有指标计算的循环(main loop)前,必须有变量恢复的代码。
4. In every loop containing actual variables, the code of memorizing these variables should be added.
在每一个包含当前变量的循环里,应该添加存储这些变量的代码。
微信公众号:天泓评测
发表评论