Download MetaTrader 5

help me to open new order if the market open new candlestick

To add comments, please log in or register
Write articles and earn money. We pay 200 USD for them!
Mahfoud Allali
324
Mahfoud Allali 2015.10.30 11:44 

if (market open new candlstick)

{

openbuy(); 

Adam Slucki
412
Adam Slucki 2015.10.30 12:47  
I think it's somewhere else on this forum, but I'm pasting solution here.

//declare in global scope
static datetime time = Time[0];

//use in OnTick/Timer/Event function
if (Time[0] > time) 
 {
     time = Time[0];

     //do your trading here
 }


Of course if you run EA on 1 hour chart, it'll detect hourly openings etc.

Snelle Moda
602
Snelle Moda 2015.10.30 12:57  

You can also check for a new bar/candlestick to appear.

See this code for an example:


// Rates structure array for last two bars 
   MqlRates mrate[2];                 
   CopyRates(Symbol(), Period(), 0, 2, mrate);

// NEW BAR CHECK.
//---------------
   static double   dBar_Open;     
   static double   dBar_High;
   static double   dBar_Low;
   static double   dBar_Close;
   static long     lBar_Volume;
   static datetime nBar_Time;

// Boolean for new BAR confirmation. 
   bool bStart_NewBar = false;

// Check if the price data has changed tov the previous bar.   
   if(mrate[0].open != dBar_Open || mrate[0].high != dBar_High || mrate[0].low != dBar_Low || mrate[0].close != dBar_Close || mrate[0].tick_volume != lBar_Volume || mrate[0].time != nBar_Time)
         {
         bStart_NewBar = true; // A new BAR has appeared!        

// Update the new BAR data.     
         dBar_Open   = mrate[0].open;      
         dBar_High   = mrate[0].high;
         dBar_Low    = mrate[0].low;
         dBar_Close  = mrate[0].close;                 
         lBar_Volume = mrate[0].tick_volume;
         nBar_Time   = mrate[0].time;
         }

// Check if a new bar has formed.   
   if(bStart_NewBar == true)
         {
         
// your code for opening a new trade:
         if()
               {
               
               }         
         
         
         
         }
Ahmed Soliman
15714
Ahmed Soliman 2015.10.30 22:51  
if(Time[0]==TimeCurrent())
{
   //Do something
}
Siti Latifah
6449
Siti Latifah 2015.10.31 03:41  
Ahmed Soliman:

another way... you use like below


if (Volume[0] < 3) {

      //do something here

       }

   

Ndumiso Mavuso
4373
Ndumiso Mavuso 2015.10.31 16:05  
  if (Volume[0]==1)
  {
  //Do stuff
  }

Easy and work most of the time but its unreliable.

Mahfoud Allali
324
Mahfoud Allali 2015.10.31 20:42  

Thank you, my friends have been successfully command

i need just  another command

if ( timenow>= 10:00 && timenow<=10:29)

{

 closeall();

} 
Mahfoud Allali
324
Mahfoud Allali 2015.10.31 21:28  
Mahfoud Allali:

Thank you, my friends have been successfully command

i need just  another command

if(Hour()==10 && Minute()==00)
{
closeall();

}

 

:D 

To add comments, please log in or register