| / | Forum |
|
gnovak
2008.06.19 21:38
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 |
|
This article dwells on the ways of transferring an indicator code into an Expert Advisor Code and on writing Expert Advisors with no calling to custom indicators, and with the whole program code for the calculation of necessary indicator values inside the Expert Advisor. This article gives a general scheme of Expert Advisor changing and the idea of building an indicator function based on a custom indicator. The article is intended for readers, already having experience of programming in MQL4 language. |
|
BarrowBoy
2008.06.20 14:25
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); } |
|
BarrowBoy
2008.06.20 14:29
Use iCustom() to call your indicator from your EA
|