Creating a simple Binary Indicator

 

Hi all,

I am trying to create a simple binary indicator, that returns value 1 when an argument is true, and 0 when the argument is false.  For example:


#property indicator_separate_window

int start()
{
double SCORE;
double MCCI=iCCI(0,0,14,PRICE_TYPICAL,0);
double MCCI2=iCCI(0,0,14,PRICE_TYPICAL,1);

if (MCCI > MCCI2)
SCORE=1;
else
SCORE=0;

return(0);


Nothing is returned when I use the above code, and I am unsure why. Can anyone assist?

 
HorizonT:

Nothing is returned when I use the above code, and I am unsure why. Can anyone assist?

Returned to where ?  what were you expecting to have happened ? 
 

Hi Raptor,

Apologies for not being more specific. I would like to return a subchart that would display 1 or 0 at each data point along the chart based on the logical argument previously specified. The actual look of the chart is not really important, line or histogram. I just need to be able to see visually if the argument is true or not as I am moving through the chart.

 
HorizonT:

Hi Raptor,

Apologies for not being more specific. I would like to return a subchart that would display 1 or 0 at each data point along the chart based on the logical argument previously specified. The actual look of the chart is not really important, line or histogram. I just need to be able to see visually if the argument is true or not as I am moving through the chart.

You need an Indicator buffer and write the value you want displayed for each bar to that buffer . . .  I don't see any suggestion of Indicator buffers in the code you have posted.  look in the Book for more info and the CodeBase for examples.
 

Hi Raptor,

Thanks, problem is now sorted. It has taken a bit of time to get my head around the buffers, but now I think I have it, and my code is working:

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 White

double B1;
double B2;
double B3[];

int init()
{

SetIndexBuffer(0,B3);
SetIndexStyle(0,DRAW_HISTOGRAM,0,0,0);

return(0);
}
int start()
{

int counted_bars=IndicatorCounted();

double SCORE;
for(int i=0;i<Bars;i++)
{
B1=iCCI(0,0,14,PRICE_TYPICAL,i);    // Current level of CCI
B2=iCCI(0,0,14,PRICE_TYPICAL,i-1);  // Level of CCI 1 period ago


if (B1 > B2)
{
SCORE=1;
}
else
{
SCORE=0;
}


B3[i]=SCORE;
}
return(0);
}
Reason: