Download MetaTrader 5

time difference betwen two prices

To add comments, please log in or register
FaatP94
64
FaatP94 2014.10.10 19:39 

Hello guy, how can I catch the time between two prices ? That's how I am trying:

 

if(check == true && OrdersTotal()==0)
{
 
   static double firstPrice;
   static bool firstTest = false;
   static bool secondTest = false;
   
   if(firstTest == false)
   {
   firstPrice = Ask;
   //here I want to catch the first datetime
   firstTest = true;
   }
   
   if(secondTest == false)
   {
   if(Ask>firstPrice+unterschied*Point || Ask<firstPrice-unterschied*Point)
   {
   //here I want to catch the second datime
   }
   
   }
   
   

        
}//if(check == true && OrdersTotal()==0)
Carl Schreiber
6670
Carl Schreiber 2014.10.10 19:54  

Sure!

1) Count ticks per minute and divide by 60 or (per 30 seconds or 10 seconds or ..)

2) Count ticks with the use of GetTickCount() (= millisecods).

FaatP94
64
FaatP94 2014.10.10 20:09  
thank you for the quick reply. I had the same idea to count the ticks per minute but how to do that ? 
Carl Schreiber
6670
Carl Schreiber 2014.10.10 21:16  

sigh..

int nTicks, TicksPerSec;
datetime NewBar;

void OnTicks(){
   ...
   if ( NewBar != Time[0] ) {
       TicksPerSec = nTicks/(_Period*60);
       NewBar = Time[0];
       nTicks = 1;
   } else nTicks++;
   ...
}
(untested) something like this?
whroeder1
14753
whroeder1 2014.10.12 12:28  
gooly: sigh..
That's why I say:
You have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
Emphasis on "post your attempt."
FaatP94
64
FaatP94 2014.10.12 14:16  

@WHRoeder , your right. I updatet my first post! 

@gooly thank you for helping me at the first problem, it works  

FaatP94
64
FaatP94 2014.10.13 14:09  
#push please
Carl Schreiber
6670
Carl Schreiber 2014.10.13 16:07  
GetTickCount() - look it up in the reference
FaatP94
64
FaatP94 2014.10.14 14:53  
if(check == true && OrdersTotal()==0)
{

   if(firstTest == false)
   {
   firstPrice = Ask;
   //here I want to catch the first datetime
  
   firstTest = true;
   }
   
   if(firstTest == true && mainTest == false)
   {
   m=GetTickCount();
   
   if(Ask>firstPrice+unterschied*Point || Ask<firstPrice-unterschied*Point)
   {
   showPrice = true;
   mainTest=true;

   }

   if(showPrice==true)
   {
   Alert("Time is" +m);
   }
 }
   
   

        
}//if(check == true && OrdersTotal()==0)
That is how I tried it but it doesent work ... I want that the Ea checks every tick the elapsed time betwen the firstPrice and the secondPrice which is the firstPrice-unterschied(difference) and the ea should return it to a variable.
I also tried it with m=TimeSeconds(TimeCurrent(); but it doesen't work 
Carl Schreiber
6670
Carl Schreiber 2014.10.14 15:02  

sigh... :(

Just use and amend the example in the reference of GetTickCount()...

FaatP94
64
FaatP94 2014.10.22 22:24  
int test()
{
   int m = 0;
   static int start = GetTickCount();
   if(firstTest == false)
   {
   firstPrice = Ask;
  
   firstTest = true;
   }
   
      if(firstTest == true && mainTest == false)
      {
      m=GetTickCount()-start;
      }
            if(Ask>=firstPrice+unterschied*Point || Ask<=firstPrice-unterschied*Point)
            {
  
               showPrice = true;
               mainTest=true;
               
            }

   
   
   if(showPrice==true)
   {

   mainTest=false;
   showPrice = false;
   
   }
 
 
return(m);
 
}//int test()
That's my code now. The first value which this function returns is right but then it will add up the first value with the second etc. Does someone know how to fix it ?
12
To add comments, please log in or register