EA - last bar only

 

Although I'm very comfortable writing an indicator, mostly due to my 20 years of programming the VB type languages, I'm having difficulty with the Expert idea.

The main issue is dealing with the time dimension. My understanding is that the EA, like the indicator, keeps polling the data. I wish to evaluate a condition based on the previous bar and I obviously wish to only do it once. The timing of the bar obviously would depend on the time frame of the current chart.

How would I instantiate a variable that would get reset with every new bar?

Is there a way to "hard code" the time frame that the EA works on?

and finally, do I have to include my indicator in the EA or can I place a call to it within the EA like any other indicator - what is preferred?

Thanks folks.

Jerry

 

G

> Is there a way to "hard code" the time frame that the EA works on?

> How would I instantiate a variable that would get reset with every new bar?

Sure is - use something like this OTTOMH :)

NB the value of any

int YourEAPeriod=PERIOD_H1;
int SomeVar; // this value volatile, lost at each new tick never mind new bar
static int SomeStaticVar; // any value set is preserved across ticks - start() initiates every tick 
// as long as the code from the last tick has finished...
start()
{

if (Period()!=YourEAPeriod)
  {
   Alert("Wrong period for this EA");
   Print("Wrong period for this EA");
   return(0); // quit if EA on chart of wrong time period 
  }

// Check to only execute once per bar
if (Volume[0]>1) return(0); // quit if after first tick of new bar

///... your main EA code START





///... your main EA code END

return(0);
}
 
Use iCustom() to call your indicator from your EA
Reason: