need help with iCustom

 
Hello,
I need a small help. I have written a simple weekly open, high low indicator that is working properly. Here is the code. However when i try to access this indicator from an expert advisor, it does not display the correct weekly open values. Appreciate if someone can help. the code for the expert advisor is below the indicator code.

Thanks a lot in advance,
Arooba

Indicator-----------------------------------------------------------------------------------


#property copyright "Copyright © 2010, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

#property indicator_buffers 3
#property indicator_color1 DarkOrange
#property indicator_color2 Chartreuse
#property indicator_color3 Blue

//---- buffers
double WeeklyOpen[];
double WeeklyHigh[];
double WeeklyLow[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+

int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(0,WeeklyOpen);
SetIndexStyle(1,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(1,WeeklyHigh);
SetIndexStyle(2,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(2,WeeklyLow);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int limit;
double weeklyOpen, weeklyHigh, weeklyLow;
bool weeklyOpenSet;
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- the last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int i=limit; i>=0; i--)
{
//if sunday and first tick of sunday
if (TimeDayOfWeek(iTime(NULL,0,i))==0 && weeklyOpenSet==false)
{
weeklyOpen=iOpen(NULL,0,i);
weeklyHigh=0;
weeklyLow=100000;
weeklyOpenSet=true;
}
if (TimeDayOfWeek(iTime(NULL,0,i))==1)
weeklyOpenSet=false;
weeklyHigh=MathMax(weeklyHigh,iHigh(NULL,0,i));
weeklyLow=MathMin(weeklyLow,iLow(NULL,0,i));
WeeklyOpen[i]=weeklyOpen;
WeeklyHigh[i]=weeklyHigh;
WeeklyLow[i]=weeklyLow;
}
return(0);
}


Expert---------------------------------------------------------
#property copyright "Copyright © 2010, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#define LONG 1
#define SHORT 2
#define MAGIC 1012
int MA_Period=24;
int bars, bias;
bool validInsideBar, seekEntry, seekLongEntry, seekShortEntry;
double setupInvalidatePrice;

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()

{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
if(bars<Bars)
{
bias=NULL;
seekLongEntry=NULL;
seekShortEntry=NULL;
double weeklyOpen=iCustom(NULL,0,"WeeklyOHL","",0,1);
Print(weeklyOpen); bars=Bars;
}
return(0);
}
 
Put a comment in the indicator so you can see the value of weeklyOpen on the chart and check it is correct. At a glance looking at your expert the value in the buffer should be read correctly except that you are asking the indicator for the closed bar "1,);" not the current value "0,);"
 
Hi Ruptor,

Thanks for the reply. I found out the issue. In my indicator code my variables were declared in the start function. So when a new tick arrived, the variables were repopulated with fresh values and hence weekly open got set to zero and it messed up the entire code. Upon declaring the variables in the beginning of the indicator, the indicator is now working fine. The expert is also working fine now.

Thanks again for looking at this...
Reason: