Buffer problems or something like that

 

Hello,

I have written this simple indicator Joe DiNapoli uses to determine Over Bought and Over Sold called DOSC for Detrended oscilator. It is just he diference between Close and Moving Average. The indicator works good and the only buffer that is used is full and does what it needs to do. Then I decided to calculate the price of OB/OS for current candle on the basis of previous peaks/lows of DOSC. I have calculated both prices and have displayed them on screen using Comment(). Everything still working, prices are correct and the indicator works as I really need it. But then I went a bit further and wanted to make a version of DiNapoli's so called Oscilator Preditctor, just using the above solution to determine the price of OB/OS for each candle and plot that on the chart. I have used copy/paste to get the basics and just added two more buffers to store numbers for OB/OS so they can be displayed on screen. I have also removed original buffer to be displayed, I just have it since i first need to calculate those values to make the second calculation. When I did that, nothing worked. I went to seacrh where the problem is and found out that the buffer for the first calculation is empty i.e. everything is on 0. When I run calculations of the same procedure in Alert() just for a couple of candles it works fine, just the buffer does not get filled. Can there be a problem with defining the buffers? I dont know about that stuff since this was actually my first indicator created, before I have only programed EAs.

I appreciate all the anwsers and help

thank you very much, Peter

//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Black
//---- indicator parameters
extern int MAperiod=7;
extern int Price=0;
//---- indicator buffers
double DOSCBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexDrawBegin(0,MAperiod);
IndicatorDigits(Digits+1);
//---- indicator buffers mapping
SetIndexBuffer(0,DOSCBuffer);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("DOSC("+MAperiod+")");
SetIndexLabel(0,"DOSC");
//---- initialization done
return(0);
}
//----DOSC high/low finder
double FindHigh(double Array[])
{
double DHigh=0.0;

for(int i=0; i<90; i++)
{
if(Array[i]>DHigh)
{
DHigh=Array[i];
}
}
return(DHigh);
}
//----
double FindLow(double Array[])
{
double DLow=100000.0;

for(int i=0; i<90; i++)
{
if(Array[i]<DLow)
{
DLow=Array[i];
}
}
return(DLow);
}
//----OB/OS calculator
double OBOSprice(double DLvl, int Wher)
{
double MAA=iMA(Symbol(), 0, 7, 0, 0, 0, Wher+1)-(Close[Wher+7]/7.0);

return((DLvl+MAA)/0.857142857);
}
//+------------------------------------------------------------------+
//| Detrended Oscilator |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- dosc counted in the 1-st buffer
for(int i=0; i<limit; i++)
DOSCBuffer[i]=iClose(NULL, NULL, i)-iMA(NULL,0,MAperiod,0,MODE_SMA,Price,i);
//---- done
Comment(OBOSprice(FindHigh(DOSCBuffer), 0), "\n", OBOSprice(FindLow(DOSCBuffer), 0));
return(0);
}
//+------------------------------------------------------------------+

this is the one that works... and below is the one that is not, note the similarity (the same!) around both first for loops in each code...

//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Black
#property indicator_color2 Black
//---- indicator parameters
extern int MAperiod=7;
extern int Price=0;
//---- indicator buffers
double DOSCBuffer[];
double OBBuffer[];
double OSBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexDrawBegin(0,MAperiod);
SetIndexStyle(1,DRAW_LINE);
SetIndexDrawBegin(1,MAperiod);
IndicatorDigits(Digits+1);
//---- indicator buffers mapping
SetIndexBuffer(0,DOSCBuffer);
SetIndexBuffer(1,OSBuffer);
//---- name for DataWindow and indicator subwindow label
// IndicatorShortName("DOSC("+MAperiod+")");
// SetIndexLabel(0,"OB");
// SetIndexLabel(1,"OS");
//---- initialization done
return(0);
}
//----DOSC high/low finder
double FindHigh(double Array[])
{
double DHigh=-1000000.0;

for(int i=0; i<90; i++)
{
if(Array[i]>DHigh)
{
DHigh=Array[i];
}
}
return(DHigh);
}
//----
double FindLow(double Array[])
{
double DLow=100000.0;

for(int i=0; i<90; i++)
{
if(Array[i]<DLow)
{
DLow=Array[i];
}
}
return(DLow);
}
//----OB/OS calculator
double OBOSprice(double DLvl, int Wher)
{
double MAA=iMA(Symbol(), 0, 7, 0, 0, 0, Wher+1)-(Close[Wher+7]/7.0);

return((DLvl+MAA)/0.857142857);
}
//+------------------------------------------------------------------+
//| Detrended Oscilator |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- dosc counted in the 1-st buffer
for(int i=0; i<limit; i++)
DOSCBuffer[i]=iClose(NULL, NULL, i)-iMA(NULL,0,MAperiod,0,MODE_SMA,Price,i);
//---- last counted bar will be recounted
int limit1=Bars-counted_bars;
//----
for(int j=0; j<limit1; j++)
{
OBBuffer[j]=OBOSprice(FindHigh(DOSCBuffer), j);
OSBuffer[j]=OBOSprice(FindLow(DOSCBuffer), j);
}
Comment(OBOSprice(FindHigh(DOSCBuffer), 0), "\n", OBOSprice(FindLow(DOSCBuffer), 0));
return(0);
}
//+------------------------------------------------------------------+

 

It's a pity that you destroyed helpful formatting & colors by not using the SRC button.

I for one am not prepared to wade through that to try and understand it.

 

i wasnt going to either but i noticed at the end of the code

you probably cant do this

OBBuffer[j]=OBOSprice(FindHigh(DOSCBuffer), j);
OSBuffer[j]=OBOSprice(FindLow(DOSCBuffer), j);

your calling those functions with parameter DOSCbuffer that has no [] index

Reason: