indicator not showing up in window =(

 

took me a while but i thought...thought being the keyword here, that i finally got this indicator i've been working on to well...work. if anybody could take a look and see what the problem(s) is/are I would greatly appreciate it thank you!


//+------------------------------------------------------------------+
//| Weighted Probability.mq4 |
//| basefree |
//| |
//+------------------------------------------------------------------+
#property copyright "basefree"
#property link ""

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_buffers 1
#property indicator_color1 Red
//---- buffers
double ExtMapBuffer1[];
int posbars[];
int negbars[];
int voidbars[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(4);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexBuffer(1,posbars);
SetIndexBuffer(2,negbars);
SetIndexBuffer(3,voidbars);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i,counted_bars=IndicatorCounted();
int poscounter=0;
int negcounter=0;
int voidcounter=0;
i=Bars-counted_bars-1;
//----
while(i>=0)
{
if(Open[i]<Close[i])
{
posbars[i]=1;
negbars[i]=0;
voidbars[i]=0;
poscounter++;
negcounter=0;
voidcounter=0;
}
if(Open[i]>Close[i])
{
posbars[i]=0;
negbars[i]=1;
voidbars[i]=0;
poscounter=0;
negcounter++;
voidcounter=0;
}
if(Open[i]==Close[i])
{
posbars[i]=0;
negbars[i]=0;
voidbars[i]=1;
poscounter=0;
negcounter=0;
voidcounter++;
}
i--;
}
//---- Probability for posbars -- adding up the elements in the array

double prob_pos=0;
int prob_pos_elements=ArrayRange(posbars,0);

for(int a=0;a<=prob_pos_elements;a++)
{
prob_pos+=posbars[a];
}

double prob_pos_average=prob_pos/prob_pos_elements;
//--- Probability for negbars

double prob_neg=0;
int prob_neg_elements=ArrayRange(negbars,0);

for(int b=0;b<=prob_neg_elements;b++)
{
prob_neg+=negbars[b];
}

double prob_neg_average=prob_neg/prob_neg_elements;

//---- Probability for voidbars
double prob_void=0;
int prob_void_elements=ArrayRange(voidbars,0);

for(int c=0;c<=prob_void_elements;c++)
{
prob_void+=voidbars[c];
}

double prob_void_average=prob_void/prob_void_elements;

//---- Main output
if(counted_bars>0) counted_bars--;
int limit=Bars-counted_bars;
for(i=0;i<limit;i++)
{
int np=poscounter;
int nn=negcounter;
int nv=voidcounter;
int r;
double p;

if(poscounter>negcounter && poscounter>voidcounter)
{
r=np;
p=prob_pos_average;

ExtMapBuffer1[i]=BDP(np,prob_pos_average,r);
}
if(negcounter>poscounter && negcounter>voidcounter)
{
r=nn;
p=prob_neg_average;

ExtMapBuffer1[i]=BDP(nn,prob_neg_average,r);
}
if(voidcounter>poscounter && voidcounter>negcounter)
{
r=nv;
p=prob_void_average;

ExtMapBuffer1[i]=BDP(nv,prob_void_average,r);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator BDP function |
//+------------------------------------------------------------------+
double BDP(int n,double p,int r)
{
double answer;
answer=fac(n)/(fac(n-r)*fac(r))*MathPow(p,r)*MathPow(1-p,n-r);

return(answer);
}
//+------------------------------------------------------------------+
//| Custom indicator factorial function |
//+------------------------------------------------------------------+
double fac(int n)
{
double t=1;
for(int j=n;j>1;j--)
{
t*=j;
}

return(t);
}

 
int start() {
int i,counted_bars=IndicatorCounted();
int poscounter=0;
int negcounter=0;
int voidcounter=0;
for (int i=Bars-counted_bars-1; i>=0; i--) {  //comment0: easier to read than //while(i>=0) {
  if(Open[i]<Close[i]) {                      //comment1: I would use if(){}else if(){} else{}
    posbars[i]=1; negbars[i]=0; voidbars[i]=0; poscounter++; negcounter=0; voidcounter=0;
  }
  if(Open[i]>Close[i]) {
    posbars[i]=0; negbars[i]=1; voidbars[i]=0; poscounter=0; negcounter++; voidcounter=0;
  }
  if(Open[i]==Close[i]) {
    posbars[i]=0; negbars[i]=0; voidbars[i]=1; poscounter=0; negcounter=0; voidcounter++;
  }
  // comment0: use for loop // i--;
}
/* comment2 At this point, poscounter/negcounter/voidcounter are either 0 or 1 never greater
 * You probably don't want to set them to zero in the loop
 * Also do these need to be static so they survive between calls?
 */
//---- Probability for posbars -- adding up the elements in the array
double prob_pos=0;
int prob_pos_elements=ArrayRange(posbars,0);

for(int a=0;a<=prob_pos_elements;a++) { // comment3: you are accessing one element too many
  prob_pos+=posbars[a];                 // change to a<prob
}

// ...                                  // likewise other loops
                                        // Also ArrayRange will always be the same
                                        // for each array

//---- Main output
if(counted_bars>0) counted_bars--;
int limit=Bars-counted_bars;           // comment4 should this be
for(i=0;i<limit;i++) {                 // for(i=Bars-1-counted_bars; i>=0; i--) {
  int np=poscounter;
  int nn=negcounter;   // comment5: np/nn/nv are never modified
  int nv=voidcounter;  // you could have used the counter's instead
  int r;
  double p;

if(poscounter>negcounter && poscounter>voidcounter) {  
  /* comment6 since counters are always
   * 0 or 1 this may never executed
   * likewise for the others
   * change    if(){}; if(){}; if(){}
   * change to if(){} else if(){} else{}
   */
  r=np;
  p=prob_pos_average;
  ExtMapBuffer1[i]=BDP(np,prob_pos_average,r);
}
//...
 

whroeder~

thank you very much for your help! I greatly appreciate it. I modified what you said, making the counters static, using counters instead of np, nn, and nv etc. still not showing up though =(. there's probably something that i did incorrectly. if you wouldn't mind taking another look, that would be awesome. thank you very much again.


//+------------------------------------------------------------------+
//| Weighted Probability.mq4 |
//| basefree |
//| |
//+------------------------------------------------------------------+
#property copyright "basefree"
#property link ""

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_buffers 1
#property indicator_color1 Red
//---- buffers
double ExtMapBuffer1[];
int posbars[];
int negbars[];
int voidbars[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(4);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexBuffer(1,posbars);
SetIndexBuffer(2,negbars);
SetIndexBuffer(3,voidbars);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
static int poscounter=0;
static int negcounter=0;
static int voidcounter=0;
//----
for(int i=Bars-counted_bars-1; i>=0; i--)
{
if(Open[i]<Close[i])
{
posbars[i]=1;
negbars[i]=0;
voidbars[i]=0;
poscounter++;
negcounter=0;
voidcounter=0;
}
else if(Open[i]>Close[i])
{
posbars[i]=0;
negbars[i]=1;
voidbars[i]=0;
poscounter=0;
negcounter++;
voidcounter=0;
}
else
{
posbars[i]=0;
negbars[i]=0;
voidbars[i]=1;
poscounter=0;
negcounter=0;
voidcounter++;
}
i--;
}
//---- Probability for posbars -- adding up the elements in the array

double prob_pos=0;
int prob_pos_elements=ArrayRange(posbars,0);

for(int a=0;a<prob_pos_elements;a++)
{
prob_pos+=posbars[a];
}

double prob_pos_average=prob_pos/prob_pos_elements;
//--- Probability for negbars

double prob_neg=0;
int prob_neg_elements=ArrayRange(negbars,0);

for(int b=0;b<prob_neg_elements;b++)
{
prob_neg+=negbars[b];
}

double prob_neg_average=prob_neg/prob_neg_elements;

//---- Probability for voidbars
double prob_void=0;
int prob_void_elements=ArrayRange(voidbars,0);

for(int c=0;c<prob_void_elements;c++)
{
prob_void+=voidbars[c];
}

double prob_void_average=prob_void/prob_void_elements;

//---- Main output
if(counted_bars>0) counted_bars--;
for(int j=Bars-counted_bars-1; j>=0; j--)
{
double p;

if(poscounter>negcounter && poscounter>voidcounter)
{
p=prob_pos_average;

ExtMapBuffer1[j]=BDP(poscounter,prob_pos_average,poscounter);
}
else if(negcounter>poscounter && negcounter>voidcounter)
{
p=prob_neg_average;

ExtMapBuffer1[j]=BDP(negcounter,prob_neg_average,negcounter);
}
else
{
p=prob_void_average;

ExtMapBuffer1[j]=BDP(voidcounter,prob_void_average,voidcounter);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator BDP function |
//+------------------------------------------------------------------+
double BDP(int n,double p,int r)
{
double answer;
answer=fac(n)/(fac(n-r)*fac(r))*MathPow(p,r)*MathPow(1-p,n-r);

return(answer);
}
//+------------------------------------------------------------------+
//| Custom indicator factorial function |
//+------------------------------------------------------------------+
double fac(int n)
{
double t=1;
for(int j=n;j>1;j--)
{
t*=j;
}

return(t);
}

Reason: