How to use indicator's buffer in same indicator for another buffer in multi buffer indicator?

 

hello guys,

wish you are well and prosper.

i would like to use a calculated buffer values to calculate another buffer in same indicator how should i do that, i try iCustom function but it didn't work. it would be great if anyone has an idea.

 

Just use the buffer values. FirstBuffer[index]=value; SecondBuffer[index]=FirstBuffer[index]*2;

Show us your code.

 
William Roeder #:

Just use the buffer values. FirstBuffer[index]=value; SecondBuffer[index]=FirstBuffer[index]*2;

Show us your code.

thanks william for your response

here it is

***

 
ArmanSol #:

thanks william for your response

here it is

***

Please, insert the code correctly: when editing a message, press the button  Codeand paste your code into the pop-up window 

You can always attach a code using the button  Attach file

 
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
//---
 if(rates_total<2) return(0);
        
 int start;
      //--- clean up arrays
 if(prev_calculated<3)

  {
    start=1;
    ArrayInitialize(highsBuffer,EMPTY_VALUE);
    ArrayInitialize(HhighsBuffer,EMPTY_VALUE);
    ArrayInitialize(exbuffer,EMPTY_VALUE);
  }

 else
     start=rates_total-1;
                  
 for(int i=start ; i<rates_total-1 && !IsStopped(); i++)

  {
   if    (high[i]>high[i+1] && high[i]>=high[i-1]) 
         highsBuffer[i]=high[i];
       
   else
         highsBuffer[i]=EMPTY_VALUE;
  }



      for(int m=start,j=m,g=m ; m<rates_total-1 && !IsStopped(); ++m)

      {      
                  while (highsBuffer[m]!=EMPTY_VALUE)
                  m++;
                  if (m>rates_total)
                  break;
             
                        return(m);
                  j=m+1;
                  while (highsBuffer[j]!=EMPTY_VALUE)
           
                  j++;
                        return(j);
                  g=j+1;
                  while (highsBuffer[g]!=EMPTY_VALUE)
                  g++;
                        return(g);
      
      
      
       if(highsBuffer[j]>highsBuffer[m] && highsBuffer[j]>=highsBuffer[m])
         //{
         HhighsBuffer[j]=highsBuffer[j];
         
          
            else
            HhighsBuffer[j]=EMPTY_VALUE;
      }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
Vladimir Karputov #:

Please, insert the code correctly: when editing a message, press the button  and paste your code into the pop-up window 

You can always attach a code using the button 

 
ArmanSol #:

thanks william for your response

it didn't work


i shared it

 
ArmanSol # :

i shared it

You can attach your file using button   Attach file?

 
how about using copybuffer, but i used rates_total and prev_calculated as first prameter (handle) for copybuffer function but its not working neither.
 
William Roeder #:

Just use the buffer values. FirstBuffer[index]=value; SecondBuffer[index]=FirstBuffer[index]*2;

Show us your code.

any idea? i rea in mql reference that you can not use indicator buffer right away and you shold call it via iCustom function should it be in another code file or in same file its possible.
 

maybe it would work with 2 dimension array. i give it a try meanwhile any worthy comment would be appreciated.


LIVE LONG AND PROSPER V

 
  1.          highsBuffer[i]=high[i];

    You never set your arrays to as-series to match your buffers. ArraySetAsSeries

    1. Arrays must be manually sized. They have no direction. You must move elements if you want a stack/as-series (set non-series, enlarge the array, set as-series).

    2. Buffers are automatically size, are as-series, and elements are moved for you, new elements are set to EMPTY_VALUE (or your designated. They can also draw on the chart automatically.

    3. In MT4, buffers and the predefined arrays are all ordered AsSeries. There is a difference between the arrays passed to OnCalculate (e.g. low[]) and the MT4 predefined variables (e.g. Low[].) The passed arrays have no default direction, just like MT5.

      To determine the indexing direction of time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[], call ArrayGetAsSeries(). In order not to depend on default values, you should unconditionally call the ArraySetAsSeries() function for those arrays, which are expected to work with.predefined variables (e.g. Low[].) The passed arrays have no default direction, just like MT5.
                Event Handling Functions - Functions - Language Basics - MQL4 Reference

    4. In MT5, you must set the direction.

      To define the indexing direction in the time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[] arrays, call the ArrayGetAsSeries() function. In order not to depend on defaults, call the ArraySetAsSeries() function for the arrays to work with.
                Event Handling / OnCalculate - Reference on algorithmic/automated trading language for MetaTrader 5
  2.       for(int m=start,j=m,g=m ; m<rates_total-1 && !IsStopped(); ++m)
    
          {      
                      while (highsBuffer[m]!=EMPTY_VALUE)

    You are accessing your buffer as non-series, just don't set that.

  3.       for(int m=start,j=m,g=m ; m<rates_total-1 && !IsStopped(); ++m)
          {      
                      while (highsBuffer[m]!=EMPTY_VALUE) m++;
                      if (m>rates_total)                  break;
                 
                            return(m);
                      j=m+1;
                      while (highsBuffer[j]!=EMPTY_VALUE) j++;
                            return(j);
                      g=j+1;
                      while (highsBuffer[g]!=EMPTY_VALUE) g++;
                            return(g);
          
          
           if(highsBuffer[j]>highsBuffer[m] && highsBuffer[j]>=highsBuffer[m])
             //{
             HhighsBuffer[j]=highsBuffer[j];
           else
             HhighsBuffer[j]=EMPTY_VALUE;
          }
    //--- return value of prev_calculated for next call
       return(rates_total);

    everything after the first return are irrelevant.

Reason: