IndicatorCounted() and Dollar Index

 

I´ve developed a Dollar Index Indicator. I´m newbie to MT4 and I´ve been stealing code from expert/indicators in my MT4 installation folder...

What is "IndicatorCounted()"???

I have read the documentation. So what is "new bars". This value has to be equal with "bars" while running? Or if I restart my computer and MT4 there will be a differens?

Next question:

I made this indicator, so I could get the high or low value (through the period) from another script/EA (in the same chart).

lMaxRowArr=iCustom(NULL,PERIOD_M1,"DI",5,30,5,1);
// I get the highest period
lMaxValArr=iCustom(NULL,PERIOD_M1,"DI",5,30,1,lMaxRowArr);
// I use the period to get the highest value

Is this right?????

If anyone could do this better please, do and publish!

See below script for "iCustom" output values:

//+-----------------------------------------------------------------+
//|                            DI.mq4                               |
//|                            Copyright © 2011, IntraTrade         |
//+-----------------------------------------------------------------+
#property copyright "Copyright © 2011, IntraTrade"
#property link      ""
//#property indicator_chart_window
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 SandyBrown
#property indicator_color4 Thistle
#property indicator_color5 Lime
#property indicator_color6 Blue
#property indicator_color7 SandyBrown
//----- input parameters
extern int DIFrom = 5;
extern int DITo = 30;
//----- Buffers -------
double Open_Buffer[];
double High_Buffer[];
double Low_Buffer[];
double Close_Buffer[];
double Volume_Buffer[];
double HighPer_Buffer[];
double LowPer_Buffer[];
//---------------------
//+-------------------------BEGIN PROCEDURE-------------------------+
//+-----------------------------------------------------------------+
//| Custom indicator initialization function                        |
//+-----------------------------------------------------------------+
int init(){
   //----
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Open_Buffer);
   SetIndexDrawBegin(0,2);
   SetIndexLabel(0,"DI Open");
   //----
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,High_Buffer);
   SetIndexDrawBegin(1,2);
   SetIndexLabel(1,"DI High");
   //----
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,Low_Buffer);
   SetIndexDrawBegin(2,2);
   SetIndexLabel(2,"DI Low");
   //----
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,Close_Buffer);
   SetIndexDrawBegin(3,2);
   SetIndexLabel(3,"DI Close");
   //----
   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(4,Volume_Buffer);
   SetIndexDrawBegin(4,2);
   SetIndexLabel(4,"DI Volume");
   //---- Tweak 1
   SetIndexStyle(5,DRAW_LINE);
   SetIndexBuffer(5,Close_Buffer);
   SetIndexDrawBegin(5,2);
   SetIndexLabel(5,"DI HiPeriod");
   //---- Tweak 2
   SetIndexStyle(6,DRAW_LINE);
   SetIndexBuffer(6,Close_Buffer);
   SetIndexDrawBegin(6,2);
   SetIndexLabel(6,"DI LowPeriod");
   //----
   return(0);
}
//+--------------------------END PROCEDURE--------------------------+
//+-------------------------BEGIN PROCEDURE-------------------------+
//+-----------------------------------------------------------------+
//| DOLLAR INDEX                                                    |
//+-----------------------------------------------------------------+
int start(){
   int counted_bars=IndicatorCounted();
   int i,j;
   double highPer,highVal,LowPer,LowVal;
   string SymbolArray[7]={"","EURUSD","USDJPY","GBPUSD","USDCAD","USDSEK","USDCHF"};
   if(counted_bars<1){
      for(i=1;i<=2;i++){
         Open_Buffer[Bars-i]=0;
         High_Buffer[Bars-i]=0;
         Low_Buffer[Bars-i]=0;
         Close_Buffer[Bars-i]=0;
         Volume_Buffer[Bars-i]=0;
         HighPer_Buffer[Bars-i]=0;
         LowPer_Buffer[Bars-i]=0;
      }
   }
   if(Bars<=(DITo+DIFrom)) return(0);
   i=Bars-(DITo+DIFrom);
   if(counted_bars>(DITo+DIFrom)) i=Bars-counted_bars-1;
   while(i>=0){
      Open_Buffer[i] = 50.14348112 * MathPow(iOpen(SymbolArray[1],NULL,i),-0.576) * MathPow(iOpen(SymbolArray[2],NULL,i),0.136) * MathPow(iOpen(SymbolArray[3],NULL,i),-0.119) * MathPow(iOpen(SymbolArray[4],NULL,i),0.019) * MathPow(iOpen(SymbolArray[5],NULL,i),0.042) * MathPow(iOpen(SymbolArray[6],NULL,i),0.036);
      High_Buffer[i] = 50.14348112 * MathPow(iHigh(SymbolArray[1],NULL,i),-0.576) * MathPow(iHigh(SymbolArray[2],NULL,i),0.136) * MathPow(iHigh(SymbolArray[3],NULL,i),-0.119) * MathPow(iHigh(SymbolArray[4],NULL,i),0.019) * MathPow(iHigh(SymbolArray[5],NULL,i),0.042) * MathPow(iHigh(SymbolArray[6],NULL,i),0.036);
      Low_Buffer[i] = 50.14348112 * MathPow(iLow(SymbolArray[1],NULL,i),-0.576) * MathPow(iLow(SymbolArray[2],NULL,i),0.136) * MathPow(iLow(SymbolArray[3],NULL,i),-0.119) * MathPow(iLow(SymbolArray[4],NULL,i),0.019) * MathPow(iLow(SymbolArray[5],NULL,i),0.042) * MathPow(iLow(SymbolArray[6],NULL,i),0.036);
      Close_Buffer[i] = 50.14348112 * MathPow(iClose(SymbolArray[1],NULL,i),-0.576) * MathPow(iClose(SymbolArray[2],NULL,i),0.136) * MathPow(iClose(SymbolArray[3],NULL,i),-0.119) * MathPow(iClose(SymbolArray[4],NULL,i),0.019) * MathPow(iClose(SymbolArray[5],NULL,i),0.042) * MathPow(iClose(SymbolArray[6],NULL,i),0.036);
      Volume_Buffer[i] = 50.14348112 * MathPow(iVolume(SymbolArray[1],NULL,i),-0.576) * MathPow(iVolume(SymbolArray[2],NULL,i),0.136) * MathPow(iVolume(SymbolArray[3],NULL,i),-0.119) * MathPow(iVolume(SymbolArray[4],NULL,i),0.019) * MathPow(iVolume(SymbolArray[5],NULL,i),0.042) * MathPow(iVolume(SymbolArray[6],NULL,i),0.036);
      for(j=DIFrom;j<=(DITo+DIFrom);j++){
         if(j==DIFrom){
            highVal=High_Buffer[i-j];
            highPer=DIFrom;
            LowVal=Low_Buffer[i-j];
            LowPer=DIFrom;
         }
         if(highVal<High_Buffer[i-j]){
            highVal=High_Buffer[i-j];
            highPer=i-j;
         }
         if(LowVal>Low_Buffer[i-j]){
            LowVal=Low_Buffer[i-j];
            LowPer=i-j;
         }
      }
      HighPer_Buffer[i]=highPer;
      LowPer_Buffer[i]=LowPer;
      i--;
   }
   //----
   return(0);
}
//+--------------------------END PROCEDURE--------------------------+


0=Open
1=High
2=Low
3=Close
4=Volume
5=High period (see external input)
6=Low period (see external input)

 

Please anyone...

 
IntraTrade:

I´ve developed a Dollar Index Indicator. I´m newbie to MT4 and I´ve been stealing code from expert/indicators in my MT4 installation folder...

What is "IndicatorCounted()"???

I have read the documentation. So what is "new bars". This value has to be equal with "bars" while running? Or if I restart my computer and MT4 there will be a differens?

https://docs.mql4.com/customind/IndicatorCounted gives the number of bars that the Indicator hasn't yet processed. When an Indicator is first put on a chart it has to calculate for all bars (unless limited) then for the next bar it only has to process the most recent bars as it has already processed all the others in the history . . .
 
IntraTrade:

Please anyone...

What is "IndicatorCounted()"???

lMaxRowArr=iCustom(NULL,PERIOD_M1,"DI",5,30,5,1);
// I get the highest period
lMaxValArr=iCustom(NULL,PERIOD_M1,"DI",5,30,1,lMaxRowArr);
// I use the period to get the highest value

Is this right?????

  1. This isn't a help desk or customer service. Don't expect an answer within two hours.
  2. IndicatorCounted returns the number of bars, the indicator has already processed. First time it will be zero (none processed.) After that it will usually be Bars-1 (You've processed all bars except the changing bar zero.) On a temporary disconnect, it'll be smaller than Bars-1 so the missing bars get processed.
    // If you access Buf[iBar+x] then DRAW_BEGIN == x
    // If you call iMA or other indicators DRAW_BEGIN = largest period
    
    // In your case you have TWO begins. 
    // The first for H,LO,C,V is zero
    // The second begin is for the DITO
    // You need TWO loops
    // Drop the DrawSetIndexDrawBegin(2,2); for the first 5
    // In init change the last two:
    DrawSetIndexDrawBegin(5,DITO)
    DrawSetIndexDrawBegin(6,DITO)
    :
    // In start:
    int counted    = IndicatorCounted();
    for(int iBar = Bars - 1 - counted; iBar >= 0; iBar--){
        Open_Buffer[iBar] = ...
    }
    
    if (counted < DITO) counted = DITO;
    for(int iBar = Bars - 1 - counted; iBar >= 0; iBar--){
        :
        HighPer_Buffer[iBar]= ...;
    }

  3.   for(j=DIFrom;j<=(DITo+DIFrom);j++){
             if(j==DIFrom){
                highVal=High_Buffer[i-j];
    i is the current bar being calculated, array[i-j] is in the FUTURE. Array[i+j] is looking back. You want to look back 5 through 30 bars
     for(j=DIFrom;j<=(DITo+DIFrom);j++){
    Remove the +DIFrom or you'll be looking 5 through 35 bars.
          highVal=High_Buffer[i+DIFrom];
          highPer=DIFrom;
          LowVal=Low_Buffer[i+DIFrom];
          LowPer=DIFrom;
          for(j=DIFrom+1;j<=DITo;j++){
             if(highVal<High_Buffer[i+j]){
                :

  4. From your indicator
    extern int DIFrom = 5;
    extern int DITo = 30;
    //----- Buffers -------
    double Open_Buffer[];
    double High_Buffer[];
    double Low_Buffer[];
    double Close_Buffer[];
    double Volume_Buffer[];
    double HighPer_Buffer[];
    double LowPer_Buffer[];
    In your EA you'd use
    #define DTNAME "DI"
    int DI1From = 5;
    int DI2To = 30;
    #define DTO 0
    #define DTH 1
    #define DTL 2
    #define DTC 3
    #define DTV 4
    #define DTHP 5
    #define DTLP 6
    double value = iCustom(NULL,PERIOD_M1,DTNAME,DT1From,DT2to,DTH,aShift); 

  5.       Volume_Buffer[i] = 50.14348112 * MathPow(iVolume(SymbolArray[1],NULL,i),-0.576) * 
    The calls is iVolume( string symbol, int period, int shift) NULL is not a period. you meant iVolume(SymbolArray[x], 0, i)
 

Thanks for your pedagogical answer! I´m very grateful!

I´m sorry for my approach. I´m like a child who wants candy, right away... I know this is a forum where nobody gets payed for the time they put in other peoples problem. My intention was not to upset anyone!

Do I have to:

#define DTNAME "DI"
int DIFrom = 5;
int DITo = 30;
#define DTO 0
#define DTH 1
#define DTL 2
#define DTC 3
#define DTV 4
#define DTHP 5
#define DTLP 6
double value = iCustom(NULL,PERIOD_M1,DTNAME,DTFrom,DTto,DTH,aShift);

Or could I?

double value = iCustom(NULL,PERIOD_M1,"DI",5,30,1,1);

I also see that I look into the future. Where 1 is last bar and 2 is the bar before last... This is unlogical but logical :-)

I will publish a new indicator, when I´m finished...

 
WHRoeder:
  1. This isn't a help desk or customer service. Don't expect an answer within two hours.
  2. IndicatorCounted returns the number of bars, the indicator has already processed. First time it will be zero (none processed.) After that it will usually be Bars-1 (You've processed all bars except the changing bar zero.) On a temporary disconnect, it'll be smaller than Bars-1 so the missing bars get processed.
  3. i is the current bar being calculated, array[i-j] is in the FUTURE. Array[i+j] is looking back. You want to look back 5 through 30 bars Remove the +DIFrom or you'll be looking 5 through 35 bars.
  4. From your indicator In your EA you'd use
  5. The calls is iVolume( string symbol, int period, int shift) NULL is not a period. you meant iVolume(SymbolArray[x], 0, i)


Well: If using "NULL", according to documentation, is the current timeperiod. If you use the indicator on a 5 min chart it will be 5 min, and on a 15 min chart it will be 15min and so on?!?
- I could be wrong...

The only thing I know I´m right about is that I want 5 - 35 bars (when I use 5 - 30 in iCustom), this is my intention. Because my external algo use this way to calculate High/Low values :-)

 

New indicator with changes:

//+-----------------------------------------------------------------+
//|                            DI.mq4                               |
//|                            Copyright © 2011, IntraTrade         |
//+-----------------------------------------------------------------+
#property copyright "Copyright © 2011, IntraTrade"
#property link      ""
//#property indicator_chart_window
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 SandyBrown
#property indicator_color4 Thistle
#property indicator_color5 Lime
#property indicator_color6 Blue
#property indicator_color7 SandyBrown
//----- input parameters
extern int DIFrom = 5;
extern int DITo = 30;
//----- Buffers -------
double Open_Buffer[];
double High_Buffer[];
double Low_Buffer[];
double Close_Buffer[];
double Volume_Buffer[];
double HighPer_Buffer[];
double LowPer_Buffer[];
//---------------------
//+-------------------------BEGIN PROCEDURE-------------------------+
//+-----------------------------------------------------------------+
//| Custom indicator initialization function                        |
//+-----------------------------------------------------------------+
int init(){
   //----
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Open_Buffer);
   SetIndexDrawBegin(0,2);
   SetIndexLabel(0,"DI Open");
   //----
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,High_Buffer);
   SetIndexDrawBegin(1,2);
   SetIndexLabel(1,"DI High");
   //----
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,Low_Buffer);
   SetIndexDrawBegin(2,2);
   SetIndexLabel(2,"DI Low");
   //----
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,Close_Buffer);
   SetIndexDrawBegin(3,2);
   SetIndexLabel(3,"DI Close");
   //----
   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(4,Volume_Buffer);
   SetIndexDrawBegin(4,2);
   SetIndexLabel(4,"DI Volume");
   //---- Tweak 1
   SetIndexStyle(5,DRAW_LINE);
   SetIndexBuffer(5,HighPer_Buffer);
   SetIndexDrawBegin(5,2);
   SetIndexLabel(5,"DI HiPeriod");
   //---- Tweak 2
   SetIndexStyle(6,DRAW_LINE);
   SetIndexBuffer(6,LowPer_Buffer);
   SetIndexDrawBegin(6,2);
   SetIndexLabel(6,"DI LowPeriod");
   //----
   return(0);
}
//+--------------------------END PROCEDURE--------------------------+
//+-------------------------BEGIN PROCEDURE-------------------------+
//+-----------------------------------------------------------------+
//| DOLLAR INDEX                                                    |
//+-----------------------------------------------------------------+
int start(){
   int counted_bars=IndicatorCounted();
   int i,j;
   double highPer,highVal,LowPer,LowVal;
   string SymbolArray[7]={"","EURUSD","USDJPY","GBPUSD","USDCAD","USDSEK","USDCHF"};
   if(counted_bars<1){
      for(i=1;i<=2;i++){
         Open_Buffer[Bars-i]=0;
         High_Buffer[Bars-i]=0;
         Low_Buffer[Bars-i]=0;
         Close_Buffer[Bars-i]=0;
         Volume_Buffer[Bars-i]=0;
         HighPer_Buffer[Bars-i]=0;
         LowPer_Buffer[Bars-i]=0;
      }
   }
   if(Bars<=(DITo+DIFrom)) return(0);
   i=Bars-(DITo+DIFrom);
   if(counted_bars>(DITo+DIFrom)) i=Bars-counted_bars-1;
   while(i>=0){
      Open_Buffer[i] = 50.14348112 * MathPow(iOpen(SymbolArray[1],0,i),-0.576) * MathPow(iOpen(SymbolArray[2],0,i),0.136) * MathPow(iOpen(SymbolArray[3],0,i),-0.119) * MathPow(iOpen(SymbolArray[4],0,i),0.019) * MathPow(iOpen(SymbolArray[5],0,i),0.042) * MathPow(iOpen(SymbolArray[6],0,i),0.036);
      High_Buffer[i] = 50.14348112 * MathPow(iHigh(SymbolArray[1],0,i),-0.576) * MathPow(iHigh(SymbolArray[2],0,i),0.136) * MathPow(iHigh(SymbolArray[3],0,i),-0.119) * MathPow(iHigh(SymbolArray[4],0,i),0.019) * MathPow(iHigh(SymbolArray[5],0,i),0.042) * MathPow(iHigh(SymbolArray[6],0,i),0.036);
      Low_Buffer[i] = 50.14348112 * MathPow(iLow(SymbolArray[1],0,i),-0.576) * MathPow(iLow(SymbolArray[2],0,i),0.136) * MathPow(iLow(SymbolArray[3],0,i),-0.119) * MathPow(iLow(SymbolArray[4],0,i),0.019) * MathPow(iLow(SymbolArray[5],0,i),0.042) * MathPow(iLow(SymbolArray[6],0,i),0.036);
      Close_Buffer[i] = 50.14348112 * MathPow(iClose(SymbolArray[1],0,i),-0.576) * MathPow(iClose(SymbolArray[2],0,i),0.136) * MathPow(iClose(SymbolArray[3],0,i),-0.119) * MathPow(iClose(SymbolArray[4],0,i),0.019) * MathPow(iClose(SymbolArray[5],0,i),0.042) * MathPow(iClose(SymbolArray[6],0,i),0.036);
      Volume_Buffer[i] = 50.14348112 * MathPow(iVolume(SymbolArray[1],0,i),-0.576) * MathPow(iVolume(SymbolArray[2],0,i),0.136) * MathPow(iVolume(SymbolArray[3],0,i),-0.119) * MathPow(iVolume(SymbolArray[4],0,i),0.019) * MathPow(iVolume(SymbolArray[5],0,i),0.042) * MathPow(iVolume(SymbolArray[6],0,i),0.036);
      for(j=DIFrom;j<=(DITo+DIFrom);j++){
         if(j==DIFrom){
            highVal=High_Buffer[i+j];
            highPer=DIFrom;
            LowVal=Low_Buffer[i+j];
            LowPer=DIFrom;
         }
         if(highVal<High_Buffer[i+j]){
            highVal=High_Buffer[i+j];
            highPer=i+j;
         }
         if(LowVal>Low_Buffer[i+j]){
            LowVal=Low_Buffer[i+j];
            LowPer=i+j;
         }
      }
      HighPer_Buffer[i]=highPer;
      LowPer_Buffer[i]=LowPer;
      i--;
   }
   //----
   return(0);
}
//+--------------------------END PROCEDURE--------------------------+
 

IntraTrade:

Do I have to:

double value = iCustom(NULL,PERIOD_M1,DTNAME,DTFrom,DTto,DTH,aShift);

Or could I?

double value = iCustom(NULL,PERIOD_M1,"DI",5,30,1,1);

Have to, no. But 3 month down the line you'll be scratching your head on what the 5,30,1,1 mean. Self document your code now or be confused later. You choice.
 
IntraTrade:


Well: If using "NULL", according to documentation, is the current timeperiod. If you use the indicator on a 5 min chart it will be 5 min, and on a 15 min chart it will be 15min and so on?!?
- I could be wrong...

iClose - MQL4 Documentation says:

symbol - Symbol the data of which should be used to calculate indicator. NULL means the current symbol.
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.
shift - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Now show me where it says you can use NULL for the timeframe?
 
WHRoeder:

iClose - MQL4 Documentation says:

symbol - Symbol the data of which should be used to calculate indicator. NULL means the current symbol.
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.
shift - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Now show me where it says you can use NULL for the timeframe?


You are right... I hope you sholdn´t notice :-)

Well I read that too, so before I published, I changed all to "0" (se indicator above). I also changed all to "defined", variables in case off (before you answered), in my EA. I´m in the phase of learning and my previous experience with different programs there are sometimes unlogical "must do", that is why I had to ask you.

Thank you very mutch!

Reason: