why it works properly for + or - but not / ?

 

Dear all,

 

Here is my code:

 

   double a[];

 

   SetIndexBuffer(0,a);

   SetIndexStyle(0,DRAW_HISTOGRAM);

 

    int limit;

   int counted_bars=IndicatorCounted();

   if(counted_bars<0) return(-1);

   if(counted_bars>0) counted_bars--;

   limit=Bars-counted_bars;



   for(int i=0; i<limit; i++)

     {

      double b=iBands(NULL,0,20,3,0,PRICE_CLOSE,MODE_UPPER,i);

      double c=iBands(NULL,0,20,3,0,PRICE_CLOSE,MODE_LOWER,i);

      double d= iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,i);

      double result=(b+c) / d;

      a[i]=result;

     }

 

it works properly if I amend it as "(b+c) + d" or "b+c) - d" but doesn't work when it is "(b+c) / d", what's the problem?

 
wing:

Dear all,

 Here is my code:

it works properly if I amend it as "(b+c) + d" or "b+c) - d" but doesn't work when it is "(b+c) / d", what's the problem?

Well if you have the formula that works why not use it ?  Perhaps you should explain exactly what the problem is ?  what it does wrong or what it doesn't do right or what is not done.
 
RaptorUK:
Well if you have the formula that works why not use it ?  Perhaps you should explain exactly what the problem is ?  what it does wrong or what it doesn't do right or what is not done.

it is because the original formula is (b+c)/d.

 

I changed it to + and - for testing purpose.

 

The problem is, when I changed it back to "/", there is nothing shown in the indicator window.  If I use + or -, a histogram shown clearly. 

 
wing:

it is because the original formula is (b+c)/d.

 

I changed it to + and - for testing purpose.

 

The problem is, when I changed it back to "/", there is nothing shown in the indicator window.  If I use + or -, a histogram shown clearly. 

Are the values of b, c and d ?  are they correct ?  if d is very much larger than b+c then the result will be very small.  Which window are you putting the indicator on ?  Main or Separate ?
 
wing: it works properly if I amend it as "(b+c) + d" or "b+c) - d" but doesn't work when it is "(b+c) / d", what's the problem?

What does (price1+price2)+price3 mean? An banana + a pear + a apple does not equal some amount of raisins.  Meaningless. Whether it shows something is irrelevant.

What does (price1+price2) / price3 = mean? (banana + pear) / apple is meaningless.

The problem is your thinking.

 
1. 
wing:

it is because the original formula is (b+c)/d.

I changed it to + and - for testing purpose.

The problem is, when I changed it back to "/", there is nothing shown in the indicator window.  If I use + or -, a histogram shown clearly. 

1. Prints them 

   for(int i=0; i<limit; i++)

     {

      double b=iBands(NULL,0,20,3,0,PRICE_CLOSE,MODE_UPPER,i);
      Print ("b ",b);
      double c=iBands(NULL,0,20,3,0,PRICE_CLOSE,MODE_LOWER,i);
      Print ("c ",c);
      double d= iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,i);
      Print ("d ",d);
      double result=(b+c) / d;
      Print ("res ",result);
      a[i]=result;
      Print ("a "b);
     }

2. See Data Window (Ctrl + D)

 
wing:

Dear all,

 Here is my code:

it works properly if I amend it as "(b+c) + d" or "b+c) - d" but doesn't work when it is "(b+c) / d", what's the problem?

b, c and  d are all based on the same MA so the result is a constant value of 2.00,  that is why you see no histogram.
 
phi.nuts:
1. 

1. Prints them 

2. See Data Window (Ctrl + D)


Thanks, phi.nuts!

 

really appreciate your help! 

Reason: