Download MetaTrader 5

trade once per bar and ignoring new tickets to reset my ea

To add comments, please log in or register
poklopec
32
poklopec  

what is best way for trade once per bar ??? or for create only 1 object at bar.

and how I can do to procced my EA full? I mean to ignoring new tickets to reset my ea from a new beginning on every tick so ea can procced all code in it.

Carl Schreiber
6691
Carl Schreiber  
NextTradeBar = _Period*60 + Time[i]; // Time[i] = bar of last trade
if (TimeCurrent() <= NextTradeBar) return;
// untested!!
2) don't understand what you want.
rod178
272
rod178  
augi182:

what is best way for trade once per bar ??? or for create only 1 object at bar.

and how I can do to procced my EA full? I mean to ignoring new tickets to reset my ea from a new beginning on every tick so ea can procced all code in it.

bool checkNewBar(int barPeriod, bool initOnly)
{  
   if(barPeriod<=0 && initOnly==true) return(false);
   int timeOldBar=0;  
   switch(barPeriod)
   {
      case PERIOD_M1:  static int timeOldBarM1 =-1; timeOldBar=timeOldBarM1;  break;
      case PERIOD_M5:  static int timeOldBarM5 =-1; timeOldBar=timeOldBarM5;  break;
      case PERIOD_M15: static int timeOldBarM15=-1; timeOldBar=timeOldBarM15; break;
      case PERIOD_M30: static int timeOldBarM30=-1; timeOldBar=timeOldBarM30; break;
      case PERIOD_H1:  static int timeOldBarH1 =-1; timeOldBar=timeOldBarH1;  break;
      case PERIOD_H4:  static int timeOldBarH4 =-1; timeOldBar=timeOldBarH4;  break;
      case PERIOD_D1:  static int timeOldBarD1 =-1; timeOldBar=timeOldBarD1;  break;
      case PERIOD_W1:  static int timeOldBarW1 =-1; timeOldBar=timeOldBarW1;  break;
      case PERIOD_MN1: static int timeOldBarMN1=-1; timeOldBar=timeOldBarMN1; break; 
   }      
   int countFrom;
   int count=0;
   if(barPeriod<=PERIOD_H1) {countFrom=PERIOD_H1;} else countFrom=barPeriod;
   while(count<=countFrom-barPeriod)
   {
      if(timeOldBar<0 || (TimeMinute(TimeCurrent())==count && TimeCurrent()>=iTime(NULL,barPeriod,0) && count!=TimeMinute(timeOldBar)))
      {   
         Print("tttt  ",TimeHour(TimeCurrent()),":",TimeMinute(TimeCurrent()),"  count->",count,"     TimeCurrent->",TimeCurrent(),"    timeNewOpen->",iTime(NULL,barPeriod,0),"    timeOldBarOpen->",timeOldBar ); 
         switch(barPeriod)
         {
            case PERIOD_M1:  timeOldBarM1 =iTime(NULL,barPeriod,0); return(true);
            case PERIOD_M5:  timeOldBarM5 =iTime(NULL,barPeriod,0); return(true);
            case PERIOD_M15: timeOldBarM15=iTime(NULL,barPeriod,0); return(true);
            case PERIOD_M30: timeOldBarM30=iTime(NULL,barPeriod,0); return(true);
            case PERIOD_H1:  timeOldBarH1 =iTime(NULL,barPeriod,0); return(true);
            case PERIOD_H4:  timeOldBarH4 =iTime(NULL,barPeriod,0); return(true);
            case PERIOD_D1:  timeOldBarD1 =iTime(NULL,barPeriod,0); return(true);
            case PERIOD_W1:  timeOldBarW1 =iTime(NULL,barPeriod,0); return(true);
            case PERIOD_MN1: timeOldBarMN1=iTime(NULL,barPeriod,0); return(true); 
         }    
      }
      count=count+barPeriod; //Print("**************** ",count);
   }
   return(false);                
}
poklopec
32
poklopec  
2) example I mean that EA ignore new tickets for 10 second(ea didnt start from beginning of his code for 10 seconds)
rod178
272
rod178  
augi182:
2) example I mean that EA ignore new tickets for 10 second(ea didnt start from beginning of his code for 10 seconds)

You stated trade 'once per bar'.  MT4 does not support less than M1.

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI  
augi182:
2) example I mean that EA ignore new tickets for 10 second(ea didnt start from beginning of his code for 10 seconds)
Create a timer then.
poklopec
32
poklopec  
And how? I never do anything with time :(
Carl Schreiber
6691
Carl Schreiber  
Read the book or the docs.
whroeder1
14779
whroeder1  
augi182: And how? I never do anything with time :(
  1. 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.
  2. void OnStart(){
       static datetime delay=0;
       if(TimeCurrent() < delay) return;
       :
       delay = TimeCurrent() + 10;      // Ignore for 10 seconds
    
    How hard is that?
To add comments, please log in or register