In the MACD sample that comes with MT4, I've noticed the following code:
Can this be rewritten as follows and still be the same?
On a similar topic, do I always have to declare at the start of my indicator:
int i;
For any code that refers to the current bar to work, e.g.
double yesterdayClose = iClose(NULL,0,i+1)
Isn't it just assumed that "i" always refers to the current bar?
In the MACD sample that comes with MT4, I've noticed the following code:
Can this be rewritten as follows and still be the same?
On a similar topic, do I always have to declare at the start of my indicator:
For any code that refers to the current bar to work, e.g.
Isn't it just assumed that "i" always refers to the current bar?
On a similar topic, do I always have to declare at the start of my indicator:
For any code that refers to the current bar to work, e.g.
Isn't it just assumed that i always refers to the current bar?
Current Bar is 0. Previous Bar is 1.
Hence Today = 0. Yesterday=1
int i; Initializes i to Zero {0}.
Just made my code a bit cleaner now.
Thanks.
- Since i defaults to zero, These are all the same
Choose what you think is clearer.int i; : double yesterdayClose = iClose(NULL,0,i+1)
double yesterdayClose = iClose(NULL,0,1)
double yesterdayClose = iClose(NULL,0,0+1)
#define iCB 0 // Current bar #define iPB 1 // Previous bar double yesterdayClose = iClose(NULL,0,iPB)
- I don't use i, j, k because you can't search for them in the code to find where used, and it doesn't document what it means. RaptorUK: suggests shift. I use i plus a name for (zero based) indexes (iBar, iMkt, iCht, iArray) and n plus a name for (one based) counts (nBars, nAboveMA, nElements...) and e plus a name for simulating enumerations with integers.
RaptorUK: suggests shift. . . .
![](https://c.mql5.com/mql4/forum/2014/01/wink_6.gif)
Part of my learning involved taking other people's indicators and modifying them hence why I saw that i defaulted to 0. Everybody seems to do the same things differently!
It's good to know the alternatives. This is the one for me :)
double yesterdayClose = iClose(NULL,0,1)
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
In the MACD sample that comes with MT4, I've noticed the following code:
Can this be rewritten as follows and still be the same?