Saving values

 
Hi,

I am trying to save Price value as X, but X is still refreshed after every tick.
Could you please give me a small tip how to improve my code?

double Price;
double X;

int start()
{
//Time[t0], if Bid>1.3000 -> X = current EURUSD(Bid)
{
if(Bid>1.3000)
{
Price = MarketInfo("EURUSD",MODE_BID);
}
X = Price;

//Time[t0+1], if Bid<= 1.3000 -> X != cuttent EURUSD(Bid), X = value from (t0) time 
if(Bid<=1.3000)
{
Price = X; // X from [t0] time. 
}
}}
Thanks.
 
norisk:
Hi,

I am trying to save Price value as X, but X is still refreshed after every tick.
Could you please give me a small tip how to improve my code?

Thanks.

If you want other people to read your code please fix your indenting . . .

double Price;
double X;
bool PriceIsSaved = false;

int start()
   {
   if(Bid > 1.3000 && !PriceIsSaved)
      {
      X = MarketInfo("EURUSD", MODE_BID);
      PriceIsSaved = true;
      }

   if(Bid <= 1.3000)
      {
      Price = X; // X from [t0] time. 
      }
   }

 
You might want to explain in detail what exactly it is that you are trying to do . . .

 
RaptorUK thanks for help.

So maybe in another way, I would like to save in array last 10 times of ticks (or prices in future).

COuld you please tell me what I am doing wrong in my code?

datetime _array[10];
int count = 0; 
int j = 0;
int i = 0; 

int init()
{
int count = 0;       
int j = 0;
int i = 0;
return(0);
}

int start()
{
      count++;
      _array[j] = TimeCurrent();
      j++;
      count = 0;
      for (i=0;i<11;i++) 
      {
                  Print("Time [0] = ", _array[0]);
                  Print("Time [1] = ", _array[1]);
                  Print("Time [2] = ", _array[2]);
    }
  return(0);
}
 
norisk:
RaptorUK thanks for help.

So maybe in another way, I would like to save in array last 10 times of ticks (or prices in future).

COuld you please tell me what I am doing wrong in my code?

The first element in the array is element 0,  but before you save the datetime to the array you increment the count,  so your first element will be element 1,  element 0 will have a datetime of 0.  Your for loop runs from 0 to 10,  when it should run from 0 to 9  and your Print() should be this . . .

for (i = 0; i < 10; i++) 
   {
   Print("Time [", i, "] = ", TimeToStr(_array[i], TIME_DATE|TIME_SECONDS) );
   }

 move  count++ to after this loop . . . 

 

something like this?

datetime _array[10];
int count = 0; 
int j = 0;
int i = 0; 

int init()
{
int count = 0;       
int j = 0;
int i = 0;
return(0);
}

int start()
{
      _array[j] = TimeCurrent();
      j++;
      count = 0;

for (i = 0; i < 10; i++) 
   {
   Print("Time [", i, "] = ", TimeToStr(_array[i], TIME_DATE|TIME_SECONDS) );
   }
   count++;
   
  return(0);
}
but I still get:

Time [0] = 2013.05.22 05:53:51
Time [1] = 2013.05.22 05:53:51
Time [2] = 2013.05.22 05:53:51
Time [3] = 2013.05.22 05:53:51
Time [4] = 2013.05.22 05:53:52
Time [5] = 2013.05.22 05:53:52
Time [6] = 2013.05.22 05:53:52
Time [7] = 2013.05.22 05:53:53
Time [8] = 2013.05.22 05:53:54
Time [9] = 2013.05.22 05:53:55

... next loop:

Time [0] = 2013.05.22 05:53:51 ->should be: 05:53:56
Time [1] = 2013.05.22 05:53:51 ->should be: 05:53:57
Time [2] = 2013.05.22 05:53:51 ->should be: 05:53:58
Time [3] = 2013.05.22 05:53:51 ->should be: 05:53:59
Time [4] = 2013.05.22 05:53:52 ->should be: 05:53:60
Time [5] = 2013.05.22 05:53:52 ->should be: 05:54:00
Time [6] = 2013.05.22 05:53:52 ->should be: 05:54:01
Time [7] = 2013.05.22 05:53:53 ->should be: 05:54:02
Time [8] = 2013.05.22 05:53:54 ->should be: 05:54:03
Time [9] = 2013.05.22 05:53:55 ->should be: 05:54:04

...
 
Once you store the _array[9] element, then what happens the following tick?
int start(){
  _array[j] = TimeCurrent();
 
norisk:

something like this?

but I still get:

Time [0] = 2013.05.22 05:53:51
Time [1] = 2013.05.22 05:53:51
Time [2] = 2013.05.22 05:53:51
Time [3] = 2013.05.22 05:53:51
Time [4] = 2013.05.22 05:53:52
Time [5] = 2013.05.22 05:53:52
Time [6] = 2013.05.22 05:53:52
Time [7] = 2013.05.22 05:53:53
Time [8] = 2013.05.22 05:53:54
Time [9] = 2013.05.22 05:53:55

... next loop:

Time [0] = 2013.05.22 05:53:51 ->should be: 05:53:56
Time [1] = 2013.05.22 05:53:51 ->should be: 05:53:57
Time [2] = 2013.05.22 05:53:51 ->should be: 05:53:58
Time [3] = 2013.05.22 05:53:51 ->should be: 05:53:59
Time [4] = 2013.05.22 05:53:52 ->should be: 05:53:60
Time [5] = 2013.05.22 05:53:52 ->should be: 05:54:00
Time [6] = 2013.05.22 05:53:52 ->should be: 05:54:01
Time [7] = 2013.05.22 05:53:53 ->should be: 05:54:02
Time [8] = 2013.05.22 05:53:54 ->should be: 05:54:03
Time [9] = 2013.05.22 05:53:55 ->should be: 05:54:04

...

Looks OK to me . . . what were you expecting ?  code what you want to happen not what you don't want to happen,  think about what you want logically . . .