what parameters to pass to icustom() function ?

 

in the above linear regression indicator,i want to access LRLBuffer array values viz LRLBuffer[1] and LRLBuffer[2] from an EA.can anyone tell me how and what parameters to pass to the icustom() function from inside an EA?

 
//+------------------------------------------------------------------+
//|                                       Linear Regression Line.mq4 |
//|                                                      MQL Service |
//|                                           scripts@mqlservice.com |
//+------------------------------------------------------------------+
#property copyright "MQL Service"
#property link      "www.mqlservice.com"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Yellow
#property indicator_width1 2
//---- input parameters
extern int LRLPeriod=14;
//---- buffers
double LRLBuffer[];

int shift=0;
int n=0;
double sumx=0, sumy=0, sumxy=0, sumx2=0, sumy2=0;
double m=0, yint=0, r=0;
//+------------------------------------------------------------------+
//|                    INITIALIZATION FUNCTION                       |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,LRLBuffer);
   IndicatorDigits(Digits);
   if(LRLPeriod < 2) LRLPeriod = 2;
   IndicatorShortName("Linear Regression Line ("+LRLPeriod+")");
   SetIndexDrawBegin(0,LRLPeriod+2);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+4);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                   DEINITIALIZATION FUNCTION                      |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//|                      ITERATION FUNCTION                          |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) counted_bars=0;
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

   for(int shift=limit-1; shift>=0; shift--)
      {
         sumx = 0;
         sumy = 0;
         sumxy = 0;
         sumx2 = 0;
         sumy2 = 0;
         for(n = 0; n <= LRLPeriod-1; n++)
             {
               sumx = sumx + n;
               sumy = sumy + Close[shift + n];
               sumxy = sumxy + n * Close[shift + n];
               sumx2 = sumx2 + n * n;
               sumy2 = sumy2 + Close[shift + n] * Close[shift + n]; 
             }                      
         m=(LRLPeriod*sumxy-sumx*sumy)/(LRLPeriod*sumx2-sumx*sumx); 
         yint=(sumy+m*sumx)/LRLPeriod;
         r=(LRLPeriod*sumxy-sumx*sumy)/MathSqrt((LRLPeriod*sumx2-sumx*sumx)*(LRLPeriod*sumy2-sumy*sumy));//this value actually not needed!
         LRLBuffer[shift]=yint-m*LRLPeriod;
         //Print (" "+shift+" "+LRLBuffer[shift]);
      }
      //return(LRLBuffer);
   //return(0);
  }
//+------------------------------------------------------------------+
 

https://www.mql5.com/en/forum/138577

Read that topic and then Show your attempt

 

I have gone through the link..Tnx.As you may have seen in the code above there is only one extern variable viz LRLPeriod=14.

So I input the parameters to icustom() like this below.Is this correct?

LRLBuffer[1]=iCustom(NULL,0,"Linear Regression Line",LRLPeriod,0,0);
            //LRLBuffer[2]=iCustom(NULL,0,"Linear Regression Line",LRLPeriod,0,0);// but I need this value of LRLBuffer also.How do I do it?Should I use loop?
 
MirTD:

I have gone through the link..Tnx.As you may have seen in the code above there is only one extern variable viz LRLPeriod=14.

So I input the parameters to icustom() like this below.Is this correct?

LRLBuffer[1]=iCustom(NULL,0,"Linear Regression Line",LRLPeriod,0,0);        //?????
  //LRLBuffer[2]=iCustom(NULL,0,"Linear Regression Line",LRLPeriod,0,0);
  // but I need this value of LRLBuffer also.How do I do it?Should I use loop?     NO, first check out what that last input is used for


//LRLBuffer[2]=iCustom(NULL,0,"Linear Regression Line",LRLPeriod,0,0);

// but I need this value of LRLBuffer also.How do I do it?Should I use loop?

NO, first check out what that last input in iCuystom is used for


 
deVries:
 

//LRLBuffer[2]=iCustom(NULL,0,"Linear Regression Line",LRLPeriod,0,0);

// but I need this value of LRLBuffer also.How do I do it?Should I use loop?

NO, first check out what that last input in iCuystom is used for

LRLBuffer[1]=iCustom(NULL,0,"Linear Regression Line",LRLPeriod,0,1);
 LRLBuffer[2]=iCustom(NULL,0,"Linear Regression Line",LRLPeriod,0,2);

//Okay shift.How about this?

 
MirTD:/Okay shift.How about this?

You can check with View (ing) Data Window Ctrl+D use your mouse pointing to the bars
 

i go through the link given by you.But i think the case is different here because iam not using two buffers but only one,LRLBuffer with SetIndexBuffer equal 0.And i want to access the contents of LRLBuffer[1] and LRLBuffer[2] i.e. the previous and second previous values from the above indicator.Can you please provide an example.that will be better.tnx

 

MirTD you have an indicator the buffervalues you wanna find are values of the buffer(s) from your indicator

LRLBuffer[1]=iCustom(NULL,0,"Linear Regression Line",LRLPeriod,0,1);
 LRLBuffer[2]=iCustom(NULL,0,"Linear Regression Line",LRLPeriod,0,2);

with using your indicator you have the buffers inside the indicator you call the values of each buffer and each bar with iCustom

you only have called the names wrong it can give only one value each call of iCustom

LRLBuffer_1 = iCustom(NULL,0,"Linear Regression Line",LRLPeriod,0,1); // value at bar1 Linear Regression Line with LRLPeriod

LRLBuffer_2 = iCustom(NULL,0,"Linear Regression Line",LRLPeriod,0,2); // value at bar2 Linear Regression Line with LRLPeriod

.....or call

 for(int i=4-1;i>=0;i--) //or   (int i=0;i<4;i++)
     {
     LRLBuffer[i]=iCustom(NULL,0,"Linear Regression Line",LRLPeriod,0,i);
     }

for getting result of few bars but still it is one buffer

your indicator gives you the buffervalues you can find with iCustom....

and this indicator #property indicator_buffers 1 gives with this line number of buffers

but there are indicators where it can be more to maximum of 8

guess what is this input colored blue ???

LRLBuffer_1=iCustom(NULL,0,"Linear Regression Line",LRLPeriod,0,1);
 
MirTD: i want to access the contents of LRLBuffer[1] and LRLBuffer[2] Can you please provide an example.
Why? You already did
 

I use the upper options and the lower options to check whether both works.i find the lower option works.the upper one gives data unmatch error in the journal and the 2nd one do not show error messages but the EA does not open order.Let me see my code further where the new problems arise.Tnx deVries

WHRoeder.do you give me a circular link?:D

Reason: