No. Last uncompleted bar is not included into IndicatorsCounted(). See such simple indicator:
Compile it as indicator and attach, for example, to EURUSD 5min chart. You will see how it works.
//+------------------------------------------------------------------+ //| CheckIndicatorCounted.mq4 | //| Copyright © 2007, MetaQuotes Software Corp. | //| https://www.metaquotes.net/ru/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, MetaQuotes Software Corp." #property link "https://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); } //+------------------------------------------------------------------+
Compile it as indicator and attach, for example, to EURUSD 5min chart. You will see how it works.
谢谢 Rosh 老师
还有一个问题,我执行另一个指标时,如果要将指标的一部分消除(就象把一张纸上的一条线用橡皮擦擦去其中的一部分一样),如何操作?谢谢!
I don't understand your question. Explain it with more details, please.
一般是 赋值 EMPTY_VALUE
Rosh:
I don't understand your question. Explain it with more details, please.
I don't understand your question. Explain it with more details, please.
Roch 老師,幫我看一下這個指標哪裏出錯了?指標窗口可以顯示 bb 這條線,但是 aa
這條就顯示不出,鬱悶啊!
#property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Yellow #property indicator_color2 Red //---- buffers double aa[],bb[],cc[2]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { IndicatorBuffers(3); SetIndexBuffer(1,bb); SetIndexBuffer(0,aa); SetIndexBuffer(2,cc); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int i; double p,q; //---- for (i=Bars-2;i>=0;i--) { p=iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,i); q=iMA(NULL,0,60,8,MODE_SMMA,PRICE_MEDIAN,i); cc[0]=p; cc[1]=q; aa[i]=cc[ArrayMaximum(cc)]; bb[i]=cc[ArrayMinimum(cc)]; } return(0); } //+------------------------------------------------------------------+
I think you want a something like this:
#property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Yellow #property indicator_color2 Red //---- buffers double aa[],bb[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { SetIndexBuffer(1,bb); SetIndexBuffer(0,aa); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int i; double p,q; //---- for (i=Bars-60;i>=0;i--) { p=iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,i); q=iMA(NULL,0,60,8,MODE_SMMA,PRICE_MEDIAN,i); aa[i]=MathMax(p,q); bb[i]=MathMin(p,q); } return(0); }
谢谢 Rosh 老师!
用 MathMin( ) 的方法我已经试过,是个有效的办法,但是如果我需要在 5 个或以上的数值中取最大或最小值,用 MathMax( ) 似乎很麻烦,如果用 ArrayMaximum( ),会出现以上的问题(只能显示ArrayMinimum( ) 的结果)。请问有什么解决的办法呢?
谢谢!
Rosh 老师,您好
软件语句中,Bars 给出的数目,包括最新的 Bar 嗎?(最新的 Bar 是指正在实时变动的 Bar 。比如:小时图的最右边的那个)
Indicatorcounted( ) 在程式运行中,最新给出的数目是否也包括最新的 Bar ?