Strategy Tester - Transient High value in a bar

Back to topics list To post a new topic, please log in or register
avatar
3
albericolima 2015.02.11 13:59
 

MT4 version 5.0 build 1035 

I'm trying to write a function to identify a transient High or Low value in the current bar to place an order or close it using EA.  For that I would like to loop until a certain number of consective pips to be achieved on reverse direction or a maximum delta is achieved.

I couldn't backtest my code because it's been traped in an infinite loop on refreshData() using Strategy Tester.  It follows my code, I would appreciate any suggestions. 

 

//+----------------------+
//| refreshData          |                                            |
//|                      |                                            |
//+----------------------+
void refreshData()
{
   uint elapsed,end,starts=GetTickCount(); 
   Print("Waiting ",Symbol()," rates to be refreshed...");
    while ( !RefreshRates() )
    {
      Sleep(500);      
    } 
    end=GetTickCount();
    elapsed=end-starts; 
    Print ("@",TimeCurrent(), "Elapsed ",elapsed," miliseconds to refresh tick data. Bid: ",Bid," ; Ask: ",Ask); 
}  
//+--------------------------------------------------------------------------------------------+
//| check_reverse                                                                              |
//| It checks whether a bar stops going up or down and takes a reverse direction               |
//| as parameters it takes a certain number of pips or consecutive ticks in reverse directions |                                                                 |
//+--------------------------------------------------------------------------------------------+  
void check_reverse(int up_down)
// 1 - slope up ; 2 - slope down
{
   int counterTicks=0;
   double prev_value=0;
   double init_value=0,delta=0;   
   if ( up_down == 1 )
   // slope up, it stops when max value is achieved
   {
      init_value = Ask;
      while ( (counterTicks <= peak_max_ticks || delta < peak_max_pips) ) 
      //it forces wait for a number of ticks or pips to be achieved in reverse direction
      {
         if (Ask > prev_value)
           counterTicks = 0; 
         else
            counterTicks++;                 
         prev_value = Ask;
         refreshData();
         delta= MathAbs(Ask - init_value)*10;                
      }
   }
   else 
   //( up_down = 2 ) slope down, it stops when min value is achieved
   {
      init_value = Bid;
      while ( (counterTicks <= peak_max_ticks || delta < peak_max_pips) ) 
      //it forces wait for a number of ticks or pips to be achieved in reverse direction
      {
         if (Bid < prev_value)
           counterTicks = 0; 
         else
            counterTicks++;                
         prev_value = Bid;
         refreshData();
         delta= MathAbs(Bid - init_value)*10;                
      }  
   }        
 }     

 

 

avatar
Moderator
3419
GumRai 2015.02.11 14:23 #
 
Please put your //comments on a different line so the code is not too wide to fit my screen
avatar
13006
WHRoeder 2015.02.11 14:50 #
 
winterf3ll: For that I would like to loop I couldn't backtest my code
Don't loop. Remember whatever you need. Return from start. Wait for the next tick. Process. The loop is in the terminal, not in your code.
GumRai: Please put your //comments on a different line so the code is not too wide to fit my screen

Are your books one column but two feet wide? No because that is unreadable. They are 6 inches, sometimes two columns, so you can read it easily. So should be your code. I'm not going to go scrolling back and forth trying to read it. Edit the post with formatted code and you might get additional help.

avatar
3
albericolima 2015.02.11 20:24 #
 
WHRoeder:
winterf3ll: For that I would like to loop I couldn't backtest my code
Don't loop. Remember whatever you need. Return from start. Wait for the next tick. Process. The loop is in the terminal, not in your code.


GumRai: Please put your //comments on a different line so the code is not too wide to fit my screen

Are your books one column but two feet wide? No because that is unreadable. They are 6 inches, sometimes two columns, so you can read it easily. So should be your code. I'm not going to go scrolling back and forth trying to read it. Edit the post with formatted code and you might get additional help.

Hi WHRoeder,I couldn' see the start() function on my EA code, is it a pre-defined function likewise OnTick ?

I've splitted the comments into diferent lines.

 

 

Back to topics list  

To add comments, please log in or register