OnTick and OnCalculate

To add comments, please log in or register
tasogare
10
tasogare  

At the risk of pointing out the obvious and making some experts on this site cringe, I cant help but notice that indicators for MT4 usually have OnCalculate(), while EAs usually have OnTick() or OnStart(). I know, I am very wise and perceptive. A true prodigy. Bet you guys are having a hard time keeping up.

Only problem is, I'm trying to include some of the constant int variables (rates_total for example) that go along with OnCalculate into my OnTick function. That's right.


FOR EXAMPLE.


If I have something like iOpen(NULL, PERIOD_M5, i), I need "for(int i = (rates_total - prev_calculated)-1; i >= 0; i--)" before it, and I need an array initialized, and stuff. That way (i) means something. And those variables come from OnCalculate().

I'd like to just skip that rubbish when making an EA and in my OnTick() function, just write " iOpen(NULL, PERIOD_M5, 0) " instead of using i. But I figured out after 1,000 years of backtesting that, iOpen(NULL, PERIOD_M5, i) is NOT the same as iOpen(NULL, PERIOD_M5, 0). Even when we're just talking indicators and the array is initialized, i is still not the same as 0. Even though they're both supposed to be the current bar. I think. Gives out a totally different outcome.


So, anyone have thoughts to add on this? How do I get all those const int OnCalculate variables into my OnTick() function. Rather, is it even possible?

I'm ready for the criticism and the "n0000b LEARN HOW TO PROGRAM FIRST", "BRO do you even CODE?!", remarks, I don't care. I'm that desperate for an answer lol.

 
Keith Watford
Moderator
20381
Keith Watford  

 But I figured out after 1,000 years of backtesting that, iOpen(NULL, PERIOD_M5, i) is NOT the same as iOpen(NULL, PERIOD_M5, 0).

It is if i=0.

iOpen does not use any of the constants that you get in OnCalculate.

In an EA if you want to use the high[?] that you get in an indicator, use High[?] instead.

tasogare
10
tasogare  
K I'll throw out iOpen entirely then for EA's. It's not doing me any good atm lol.
William Roeder
20208
William Roeder  

tasogare: while EAs usually have OnTick() or OnStart().

I'm trying to include some of the constant int variables (rates_total for example) that go along with OnCalculate into my OnTick function.

I'm ready for the criticism and the "n0000b LEARN HOW TO PROGRAM FIRST", "BRO do you even CODE?!", remarks, I don't care. I'm that desperate for an answer.

  1. OnStart is only for scripts. You're thinking of old event handling function start().
              Event Handling Functions - Functions - Language Basics- MQL4 Reference

  2. Rates_total just equals Bars. The others are already pre-defined. Only prev_calculated doesn't exist in EAs.

  3. You need to read the manual. Just get the value(s) of the indicator(s) into the EA and do what you want with it.
    You should encapsulate your iCustom calls to make your code self-documenting.
              Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum

To add comments, please log in or register