How to store the bid and ask price of the last 60 seconds in an array and to use them? - page 2

 
zzuegg:

this should work. i have not tested it, just coded quikly here in editor..

TimeCurrent() was wrong, works only for times > seconds. i use GetTickCount() which according to the doc should return uptime in milliseconds.

The calculations inside the sleep function is to make shure that waittime is only one sec, no matter how long the execution of the code inside the loop takes.

You can use the array for calculations when ArrayIsReady==true

//z

int start(){

bool running=true;

int execution=0;
double values[60];
int FilledValues=0;
bool ArrayIsReady=false;
double tmpPrice=0;
while(running){
execution=GetTickCount();
tmpPrice=MarketInfo(Symbol(),MODE_ASK);
      for(int i = 59; i > 0; i--)
      {
         values[i]=values[i-1]
      }
      values[0] = tmpPrice;

      FilledValues++;
      if(FilledValues>60) ArrayIsReady=true; 
 Sleep(1000-(GetTickCount()-execution));  
}
Still not working, No, it is sampling every tick instead of price at every sec interval.
 
How do I sample price at every second?
 
above code may only work in an EA since i don't know if indicatores are allowed to sleep.
 
Inside EA, however taking every tick and not price at every second
 
what if you change to Sleep(1000)?
 
same
 

I assume you have changed something in my code. because for me its working perfectly.

So stop saying that it is not working and check your code!

int start(){

bool running=true;

int execution=0;
double values[60];
int FilledValues=0;
bool ArrayIsReady=false;
double tmpPrice=0;
while(running){
execution=GetTickCount();
tmpPrice=MarketInfo(Symbol(),MODE_ASK);
      for(int i = 59; i > 0; i--)
      {
         values[i]=values[i-1];
      }
      values[0] = tmpPrice;

      FilledValues++;
      if(FilledValues>60) ArrayIsReady=true; 
      string tmp="";
      for(int j=0;j<60;j++){
         tmp=tmp+" "+DoubleToStr(values[j],Digits);
      }
      Comment(tmp);
 Sleep(1000-(GetTickCount()-execution));  
}

}
 

I cut and paste.

it is taking every tick not every seconds.

I compared tick[0] to tick[50] with values[0] to values[50] - same

With or without the sleep function, no difference.

 

actully on my metatrader the EA updates correctly the values every second..

 
johnnybegoode:

With or without the sleep function, no difference.

If you sleep you MUST RefreshData()
Reason: