Attach this sample indicator CheckIndicatorCounted.mq4 to any chart and investigate the log (Print() fuction)
//+------------------------------------------------------------------+ //| CheckIndicatorCounted.mq4 | //| Copyright © 2007, MetaQuotes Software Corp. | //| http://www.metaquotes.net/ru/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, MetaQuotes Software Corp." #property link "http://www.metaquotes.net/ru/" #property indicator_chart_window //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); //---- Print(TimeToStr(TimeCurrent())," Bars=",Bars," Indicatorcounted=",counted_bars); //---- return(0); } //+------------------------------------------------------------------+
非常感谢您的指导。
改编如下:
int start()
{ Print("Bars is ",Bars);
if(Bars<=MA_Period) return(0);
ExtCountedBars=IndicatorCounted(); Print("ExtCountedBars",ExtCountedBars);
if (ExtCountedBars<0) return(-1);
if (ExtCountedBars>0) ExtCountedBars--;
sma();
return(0);
}
改编后的EA测试得到下面这个日志:
10:40:39 112: loaded successfully
10:40:39 112 inputs: MA_Period=13; MA_Shift=0; MA_Method=0;
10:40:39 2008.01.15 00:00 112 GBPUSD,M5: Bars is 1001
10:40:39 2008.01.15 00:00 112 GBPUSD,M5: ExtCountedBars-1
我想请教一下IndicatorCounted()函数按说明是返回缓存数的。这个缓存里的是什么数据,为什么在 指标 里这个函数大于0,在EA里却变成-1了呢?
谢谢了。