Previous tick's value - page 3

 
PreviousTick = CurrentTick;

CurrentTick =   Bid;

if ( CurrentTick < PreviousTick )

       {

difference = PreviousTick - Bid;

TotalDescent = TotalDescent + difference;

descentarray[0]=TotalDescent;

       }


this code makes mt4 chart crash. whats wrong with it?

difference, TotalDescent are declared as double, with a starting value of 0. descentarray is declared as a 1d array with no maximum # of items. there is a if statement to filter out previousTick = 0 case, and the TotalAscent counterpart works fine. 

it runs until the first decrement tick comes, then it crashes. is there somewhat i missed?

 

Please use the </> button to insert your code.


 
J.P.Satrio:


this code makes mt4 chart crash. whats wrong with it?

difference, TotalDescent are declared as double, with a starting value of 0. descentarray is declared as a 1d array with no maximum # of items. there is a if statement to filter out previousTick = 0 case, and the TotalAscent counterpart works fine. 

it runs until the first decrement tick comes, then it crashes. is there somewhat i missed?

Do you size the array?

 
Keith Watford:

Do you size the array?

Nope, since im unsure what size would be neccessary. As i said, the ascension side works fine with the array without a fixed size set.
 
J.P.Satrio:
Nope, since im unsure what size would be neccessary. As i said, the ascension side works fine with the array without a fixed size set.

You have to size the array. If you are not sure of the size needed, everytime you want to give it an extra element, increase the size by one.

 
Keith Watford:

You have to size the array. If you are not sure of the size needed, everytime you want to give it an extra element, increase the size by one.

I will give it a try for shure, thanks. However, I saw many cases when the coders did not set a size for the arrays. Still unshure why is this case different.
If id have to check if there is a necessity to increase and resize my array on every tick that would make it much more complex, so i think im gonna set a size huge enough to manage the amount of data. What happens if an array got full? (Never happened to me) crash again?
 
J.P.Satrio:
I will give it a try for shure, thanks. However, I saw many cases when the coders did not set a size for the arrays. Still unshure why is this case different.
If id have to check if there is a necessity to increase and resize my array on every tick that would make it much more complex, so i think im gonna set a size huge enough to manage the amount of data. What happens if an array got full? (Never happened to me) crash again?

I don't think that you will ever see a case where an array is not sized. If you try to put a value in an element that does not exist, the code will crash.

 
Keith Watford:

I don't think that you will ever see a case where an array is not sized. If you try to put a value in an element that does not exist, the code will crash.

That did it. Thanks!
 

This thread helped me develop code that will tell me the difference between the previous Ask and the current Ask. If the difference is zero then it prints 0.0, but if the difference is not zero then there are too many digits, such as 1.000000000006551e-05. Is there something wrong with my code or is there a way to correct this? The symbol is EURUSD, if that matters. This is my first mql code so apologies in advance for the shortcomings. Thanks!

/* Global Variables */
double ask_prev;
double ask_curr;
double ask_diff;
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

   MqlTick tick_curr;
//---
   if(SymbolInfoTick(Symbol(),tick_curr))
     {
      ask_curr = tick_curr.ask;
      ask_diff = ask_curr - ask_prev;
      Print(ask_diff);
      ask_prev = tick_curr.ask;
     }
   else Print("SymbolInfoTick() failed, error = ",GetLastError());
  }
//+------------------------------------------------------------------+
 
rdone:

This thread helped me develop code that will tell me the difference between the previous Ask and the current Ask. If the difference is zero then it prints 0.0, but if the difference is not zero then there are too many digits, such as 1.000000000006551e-05. Is there something wrong with my code or is there a way to correct this? The symbol is EURUSD, if that matters. This is my first mql code so apologies in advance for the shortcomings. Thanks!

Why not just...

MqlTick tick_curr, tick_last;

void OnTick()
{
   tick_last = tick_curr;
   SymbolInfoTick(Symbol(),tick_curr);
}