newbee writing EA help

 

Hi all... I'm a newbee and trying to write an EA. All is going well but I wish to make the EA stay out of trading for 2 periods (candles) after it closes a trade. I've tried using "TimeCurrent()" and adding the seconds of the period but I get a warning of different data types. I seem at a loss as to how to go about it . Any help would be appreciated.

Thanks ron 

 
How does your code look like - my crystal ball broke :(
 
ronhoddo2:

Hi all... I'm a newbee and trying to write an EA. All is going well but I wish to make the EA stay out of trading for 2 periods (candles) after it closes a trade. I've tried using "TimeCurrent()" and adding the seconds of the period but I get a warning of different data types. I seem at a loss as to how to go about it . Any help would be appreciated.

Thanks ron 

I use this code to manage onTick. I only want to process on each miniute. If you change:
NextBar = TimeMinute(Time[0]) + 1;    << to 2 or 3, you will have a pause of 2-3 minutes.


void OnTick()
  {
//---
   CheckNextBar();          // starts MAIN
  }

....You could use code snippets to suit your purpose

void CheckNextBar()                  //processing begins at next bar
   {
    //--initialised to current bar
    static int NextBar = TimeMinute(Time[0]);   //--note only initialies once
    //--up to one minute behind real time
    int barTime = TimeMinute(Time[0]);         
        
    if(barTime == NextBar)
    {
     NextBar = TimeMinute(Time[0]) + 1;      // add 1 minute and wait
     if(NextBar > 59) NextBar = 0;           // int Mod(60)
     StartMain();                            // Start processing
     }   
//--here is every Tick()
   }

Hope you find an answer...
 
Greco608:
I use this code to manage onTick. I only want to process on each miniute. If you change:
NextBar = TimeMinute(Time[0]) + 1;    << to 2 or 3, you will have a pause of 2-3 minutes.


void OnTick()
  {
//---
   CheckNextBar();          // starts MAIN
  }

....You could use code snippets to suit your purpose

void CheckNextBar()                  //processing begins at next bar
   {
    //--initialised to current bar
    static int NextBar = TimeMinute(Time[0]);   //--note only initialies once
    //--up to one minute behind real time
    int barTime = TimeMinute(Time[0]);         
        
    if(barTime == NextBar)
    {
     NextBar = TimeMinute(Time[0]) + 1;      // add 1 minute and wait
     if(NextBar > 59) NextBar = 0;           // int Mod(60)
     StartMain();                            // Start processing
     }   
//--here is every Tick()
   }

Hope you find an answer...

Not a good idea if you have a disconnection that misses a bar or more. Check for inequality rather than equality.

 
Greco608:
I use this code to manage onTick. I only want to process on each miniute. If you change:
NextBar = TimeMinute(Time[0]) + 1;    << to 2 or 3, you will have a pause of 2-3 minutes.


void OnTick()
  {
//---
   CheckNextBar();          // starts MAIN
  }

....You could use code snippets to suit your purpose

void CheckNextBar()                  //processing begins at next bar
   {
    //--initialised to current bar
    static int NextBar = TimeMinute(Time[0]);   //--note only initialies once
    //--up to one minute behind real time
    int barTime = TimeMinute(Time[0]);         
        
    if(barTime == NextBar)
    {
     NextBar = TimeMinute(Time[0]) + 1;      // add 1 minute and wait
     if(NextBar > 59) NextBar = 0;           // int Mod(60)
     StartMain();                            // Start processing
     }   
//--here is every Tick()
   }

Hope you find an answer...
Beside honest_knave

1) Please use SRC button (or Ctrl-Alt-M) to post code!

2) Time is measured in seconds if you add 1 (or 2,3) you add 1 (or 2,3) seconds!

3) Use either 60 (or 120, 180) or n*60!

4) You may need the function PeriodSeconds(..).
 
Carl Schreiber:

2) Time is measured in seconds if you add 1 (or 2,3) you add 1 (or 2,3) seconds!

3) Use either 60 (or 120, 180) or n*60!

4) You may need the function PeriodSeconds(..).

Hi Carl,

He is using TimeMinute() ... a bit hard to see when not in SRC box (I had to look twice!).

--------------

Greco608:
I use this code to manage onTick. I only want to process on each miniute. If you change:

A simple way to detect a new bar (MT4):

static datetime LastBar = 0;
datetime ThisBar = Time[0];
if(LastBar != ThisBar)
  {
   Print("This is a new bar");
   LastBar = ThisBar;
  }
 
ronhoddo2:

Hi all... I'm a newbee and trying to write an EA. All is going well but I wish to make the EA stay out of trading for 2 periods (candles) after it closes a trade. I've tried using "TimeCurrent()" and adding the seconds of the period but I get a warning of different data types. I seem at a loss as to how to go about it . Any help would be appreciated.

Thanks ron 

It depends exactly what you want.

Let's say you are trading the H1 chart.

Last order was closed at 13:37

Do you want the next order to be opened on or after 15:00 (so skip the rest of 13:00 candle and the 14:00 candle)

Or do you want the next order to be opened on or after 15:37 (2 hours later)