Not more trade than 2 in one hour

 

Not more trade than 2/3 in one hour how i can do it??

if i look in the orderhistory i can know the orderclos time, but how work it?? he give me the hour minute and second??

and after i stop it how i restar the trade the next hour??

i found this solution

//FAIL1
OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY);
ctm=OrderCloseTime();
if(OrderProfit() < 0) 
 fail1=true; 
else fail1=false;


//FAIL2
OrderSelect(OrdersHistoryTotal()-2, SELECT_BY_POS, MODE_HISTORY);
ctm2=OrderCloseTime(); 
if(OrderProfit() < 0) 
	fail2=true; 
 else fail2=false;

RefreshRates();
if((ctm)==(ctm2))
  stopEA=true// how stop it for on hour??? and how i
else stopEA=false; 

if((fail2) && (fail1))
  //2 consecutive loss
//else stopEA=false;

 if( C1 > C2  && stopEA =true)
    Open trade etc etc



 
// this is a draft version of a function that I've made.
// It checks how many closed trades of a type (buy, sell) were made during the last candle. Check if OK.


int ordersLastBarHistory(int order_type,int time_frame)
{
   int count=0;
   int time_ini = iTime(Symbol(),time_frame,0);
   int time_end = time_ini + time_frame*60;
   for(int i=OrdersHistoryTotal()-1;i>=0;i--)   
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
         continue;
      if(OrderSymbol()!=Symbol())
         continue;  
      if(OrderType()==order_type)
      if(OrderOpenTime()>=time_ini && OrderOpenTime()<=time_end)
         count++;
      if(OrderOpenTime()<time_ini)
         break;  
   }
   return(count);  
}



//how to use it 
if(ordersLastBarHistory(OP_BUY,PERIOD_H1)<2)
{
    // check to make another trade
}


//how to use it (buy and sell)
if((ordersLastBarHistory(OP_BUY,PERIOD_H1)+ ordersLastBarHistory(OP_SELL,PERIOD_H1))<2) //if buy and sells during last candle are less than 2, then
{
    // check to make another trade
}



PS: did you take the red or blue pill?
 

Ok thanks i try this in my EA


The red one....u want too?

i think this condition is better mean i can have 2 consecutive long or 1 long and one sell

//how to use it (buy and sell)
if((ordersLastBarHistory(OP_BUY,PERIOD_H1)+ ordersLastBarHistory(OP_SELL,PERIOD_H1))<2) //if buy and sells during last candle are less than 2, then
{
    // check to make another trade
}




 
The_Matrix:

this owrk for one hour time frame, but if i want to ultilize 4 houre time frame i cand do 4*60

 int time_end = time_ini + time_frame*4*60;

 

Don't change that line. Instead do this:


//how to use it (buy and sell)  PERIOD_H4 <----------
if((ordersLastBarHistory(OP_BUY,PERIOD_H4)+ ordersLastBarHistory(OP_SELL,PERIOD_H4))<2) //if buy and sells during last candle are less than 2, then
{
    // check to make another trade
}


Reason: