Inserted Code
datetime last_rvalue_routine = 0; int rv[10][6]; int init() { ArrayInitialize(rv, 2); return(0); } void RValueRoutine() { int i, j; if (iTime(NULL, PERIOD_M1, 1) != last_rvalue_routine) { last_rvalue_routine = iTime(NULL, PERIOD_M1, 1); for (i = 9; i >= 1; i--) { for (j = 0; j <= 5; j++) rv[i][j] = rv[i-1][j]; } rv[0][0] = RValue(PERIOD_M1); rv[0][1] = RValue(PERIOD_M5); rv[0][2] = RValue(PERIOD_M15); rv[0][3] = RValue(PERIOD_M30); rv[0][4] = RValue(PERIOD_H1); rv[0][5] = RValue(PERIOD_H4); } return; }
The function RValueRoutine() is called from start(), and it's supposed to run every 1 minute bar (and it does).
This part below is supposed to copy the rows from 0 to 9 (row 0 goes to row 1, row 1 goes to row 2, etc, but in the inverse way, so that the 0th row doesn't override all the others), and so it always overrides the last row every time it's run.
Inserted Code
for (i = 9; i >= 1; i--) { for (j = 0; j <= 5; j++) rv[i][j] = rv[i-1][j]; }
This part below puts the values of the function RValue() for the given period in the first row of the 2-dimensional array rv.
Inserted Code
rv[0][0] = RValue(PERIOD_M1); rv[0][1] = RValue(PERIOD_M5); rv[0][2] = RValue(PERIOD_M15); rv[0][3] = RValue(PERIOD_M30); rv[0][4] = RValue(PERIOD_H1); rv[0][5] = RValue(PERIOD_H4);
So my goal with this was to gradually (1 time per minute bar) fill the 2-dimensional array rv with the values of the function RValue(). In the first time the function ran, only the first row would have values different from 2. On the 2nd time, both the 1st and 2nd row would have values different than 2, etc... But what happens is that the 0th row overrides all the others every time this code runs, so I get a matrix with equal rows... I seriously can't find the logic error here..