Code error

 

Hi all

I am currently trying to find an error in my code.  I've been debugging this part of the program for some time by now, but I've not been able to find the error.  It must be a very simple one, as the code is very simple, as you can see below.  The problem is that when I try to calculate priceDifference_25percent[li_8] in the following code, it calculates it as 0 (actually, it displays it as blank in the following print statement).  I've tried to set the difference variable to 4.00000 (by hard coding it in the code), but it doesn't change anything.  I would be extremely thankful, if you could glance through the code and try to find the error, as I'm completely lost. 

As you can see, I've been debugging the program, and I can see that variables priceHigh, priceLow, and differerence are correct.  But when I try to divide variable differece by 4.0, it fails.

All the variables are defined as double. 

         priceHigh[li_8] = High[li_8];
         priceLow[li_8] = priceLow[li_8 + 1];                 // We are currently on the top, so the bottom has not changed
         difference = priceHigh[li_8] - priceLow[li_8 + 1];   // The difference betwen current high and last low
         priceDifference_25percent[li_8] = (difference / 4.0);

Print("Current priceHigh: ", priceHigh[li_8]);                                  // <----- 1.3024
Print("Current priceLow: ", priceLow[li_8]);                                   // <----- 1.3001
Print("Last priceHigh: ", priceHigh[li_8 + 1]);                                // <----- 1.3024
Print("Last priceLow: ", priceLow[li_8 + 1]);                                 // <----- 1.3001
Print("difference: ", difference);                                                  // <----- 0.0023
Print("priceDifference_25percent: ", priceDifference_25percent);    // <----- 0 (actually, it is displayed as blank)

         priceAvgUp[li_8] = ( (difference + (priceAvgUp[li_8 + 1] * 2)) / 3);    // new priceAvgUp = ( (current high - previous low) + (previous priceAvgUp * 2) ) / 3

Thanks in advance. 

Best regards

 

priceDifference_25percent[li_8].

Is the array Double_Type?

Is the index [ li_8 ] within the range of ArraySize()-1 ?

 

Hi ubzen

Yes.  Following are the definition of the relevant  definitions:

double priceHigh[];   
double priceLow[];    
double priceEntry[];  
double priceTarget[]; 
double priceSL[];     
double priceAvgUp[];
double priceAvgDown[];
double difference = 0.0;
double priceDifference_25percent[]; 

 

Hi ubzen

Sorry about my English ... I'll try again ... :-)  Following, you find the definition of all the relevant  variables found in my previous mail:

double priceHigh[];
double priceLow[];
double priceEntry[];
double priceTarget[];
double priceSL[];
double priceAvgUp[];
double priceAvgDown[];
double difference = 0.0;
double priceDifference_25percent[];

 

Hi RaptorUK

Actually, I'm changing an indicator that I found on the internet, because it is not working quite as I'd like it to do (I'm will be using it in the EA that I'm currently trying to build).  These arrays are used as input to IndexBuffers (via SetIndexBuffer), and those buffers are the interface between my EA and the indicator.  The size is not set in the program.

   SetIndexBuffer(3, priceHigh);
   SetIndexBuffer(4, priceLow);
   SetIndexBuffer(5, priceEntry);
   SetIndexBuffer(6, priceTarget);
   SetIndexBuffer(7, priceSL); 

Do you think, that is the problem? 

Best regards

G

 

Hi RaptorUK

You are right.  I changed the Print statement, but it still doesn't work, i.e. it says that variable priceDifference_25percent[li_8] contains blank.  Do you think, I have to define a new variable that I initiate as 4.0, and then I use that one in the formula, i.e.

 double xx = 4.0;

priceDifference_25percent[li_8] = (difference / xx); 

?

Best regards

 

Hi uzben 

Variable li_8 is used at a counter in a loop in the indicator.  It is defined as follows: 

   int li_0 = 0;
   li_0 = Bars - li_4; 

   for (int li_8 = li_0 - 1; li_8 >= 0; li_8--) { 

      ....

   }

 

Best regards

 
gjon:

Hi uzben 

Variable li_8 is used at a counter in a loop in the indicator.  It is defined as follows: 

   int li_0 = 0;
   li_0 = Bars - li_4; 

   for (int li_8 = li_0 - 1; li_8 >= 0; li_8--) { 

      ....

   }

 

Best regards

Hi, if you don't find, try to attach whole code. Much easier to help you.
 
gjon:

Hi RaptorUK

Actually, I'm changing an indicator that I found on the internet, because it is not working quite as I'd like it to do (I'm will be using it in the EA that I'm currently trying to build).  These arrays are used as input to IndexBuffers (via SetIndexBuffer), and those buffers are the interface between my EA and the indicator.  The size is not set in the program.

Ah I see . . .  you shouldn't be using this source code and you must not post it on this forum.  It is DECOMPILED (stolen) CODE.

Please do not post DECOMPILED CODE again or you will be banned.  

 

Hi RaptorUK

Ok, I didn't know that ... :-)

Anyway, thanks for your effort, I preciate it a lot.  And a nice weekend to you!

Best regards

 

Hi RaptorUK

I checked the indicator that I'm working on, and I can see that it is what I call an 'open source', i.e. there is a very nice man out there that has made this indicator, and the source code can be freely downloaded, so the rest of us can learn from it.  So the code has not been decompiled or stolen in any way.  Well, of course the author can have taken the idea from somewhere else, but that I don't know anything about, as I don't know the author.  I just wanted to let you know, so next time, you remember to ask about it, before you start screeming out load with capital letters and red colours ... ;-)

Anyway, I woke up this morning with fresh mind, and I found the error at once.  And as I expected, it was a simple one.

A nice weekend to you.

Best regards