Custom Indicator Not Displaying Outputs of Divison

 

 Howdy, I have been working on several projects and I have hit a dead end multiple times on the account that I can't seem to get my custom indicator to display lines whose calculations contain division. 


 I created an example problem below. This following example attempts to find the percentage of a Candle's Close in relation to it's High and Lows; my problem arises from trying to divide and find percentages like such: 


Preparing The Indicator: 

#property indicator_separate_window   // Indicator is drawn in the main window
#property indicator_buffers 1       // Number of buffers
#property indicator_color1 Blue     // Color of the 1st line

double Buf_0[]; 
//--------------------------------------------------------------------
int init()                          // Special function init()
  {
   SetIndexBuffer(0,Buf_0);         // Assigning an array to a buffer
   SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,1);// Line style
   SetIndexLabel(0, "Example Line"); 

int start()                         // Special function start()
  {
       int i,                           // Bar index
       Counted_bars;                // Number of counted bars
//--------------------------------------------------------------------
      Counted_bars=IndicatorCounted(); // Number of counted bars
      i=Bars-Counted_bars-1;           // Index of the first uncounted
      while(i>=0)                      // Loop for uncounted bars
      {
     

        
        Buf_1[i] = DivisionExample(
i ); //try replacing i with integers to prove the function works. 

        i--; 

     }
//--------------------------------------------------------------------
   return(1);                          // Exit the special funct. start()
  }


Function: 

double DivisionExample(int shift = 0)
{
   double h = iHigh(_Symbol, 1, shift), 
   l = iLow(_Symbol, 1, shift), 
   c = iClose(_Symbol, 1, shift), 
   
   a = h - l, //the size of candle x. 
   b = c - l, //converting candle x's Close to digits for proper proportion. 
   d =  (b/a) * 100, //obtaining the percentage within the candle the Close is. 
   output = d; 
   
   return(output); 

}


If you can attempt this yourself, you will realize that there is no line to be seen but when I manually replace i in the buffer with an integer it plots a valid and true line so therefore the function is techincally spitting out a nice percentage double. I've tried type casting, trying to create my own bar counter as an alternative to i, and I even tested it in Comments and Text Object tests in EA's to prove I was getting a valid output. It seems the function has trouble when dealing with i. Anyone have an idea how I can fix this? It seems to be a bug and it's greatly hindering me from success. The division part of the function is the main culprit to look at because if you replace the division sign with any other arithmetic sign it produces a line easily. Please help. 

 
galfaria:

 Howdy, I have been working on several projects and I have hit a dead end multiple times on the account that I can't seem to get my custom indicator to display lines whose calculations contain division. 


 I created an example problem below. This following example attempts to find the percentage of a Candle's Close in relation to it's High and Lows; my problem arises from trying to divide and find percentages like such: 


Preparing The Indicator: 


Function: 


If you can attempt this yourself, you will realize that there is no line to be seen but when I manually replace i in the buffer with an integer it plots a valid and true line so therefore the function is techincally spitting out a nice percentage double. I've tried type casting, trying to create my own bar counter as an alternative to i, and I even tested it in Comments and Text Object tests in EA's to prove I was getting a valid output. It seems the function has trouble when dealing with i. Anyone have an idea how I can fix this? It seems to be a bug and it's greatly hindering me from success. The division part of the function is the main culprit to look at because if you replace the division sign with any other arithmetic sign it produces a line easily. Please help. 

Check the experts tab. See this
Files:
Test.mq4  2 kb