Im am working on a custom indicator atm. I wondered how to calculate a value on 1 bar to a previous bar.
eg. I get a value from a calculation on each bar. so lets say i limit this to just 10 bars. the 10th bar is 10, 9th bar value is 9, 8th is 8 etc... I want to take this value and add it to the next bar value. so ie 10th bar plus 9th bars value, plus the 8th bars value, plus the 6th bars value and so on.... So for this example I would get 10 plus 9 plus 8 plus 7 plus 6 etc.
On the chart Id like it to show the cummulative value on the next bar. So lets say im on the 6th bar, the value for this calulation should = (10 + 9 + 8 + 7) = 34. When the 5th bar shows up it adds the 6 bars value to this cummulative value so = (34 + 6) the 4 previous bars plus the new bar.
Hope this is clear? i dont know how else to put it really.
Heres a basic of the code I have
dResult_1 = High[1];
dResult_2 = High[2];
dResult = dResult_1 - dResult_2;
I now want to add dResult to the last bars dResult, to give:
Cum_Result = ........
lets say in this case dResult = 23 for the 3rd bar
The 2nd bar dResult = 3
so i want to add the 3rd bar value to the 2nd ( 23 + 3 ) to give 26. Then on the next new 2nd bar, add this to the last value of 26. lets say the new 2nd bar comes in at 9, so add 26 to 9.
No matter what I do I cant seem to get the correct result. Any help or suggestion welcome.
eg. I get a value from a calculation on each bar. so lets say i limit this to just 10 bars. the 10th bar is 10, 9th bar value is 9, 8th is 8 etc... I want to take this value and add it to the next bar value. so ie 10th bar plus 9th bars value, plus the 8th bars value, plus the 6th bars value and so on.... So for this example I would get 10 plus 9 plus 8 plus 7 plus 6 etc.
On the chart Id like it to show the cummulative value on the next bar. So lets say im on the 6th bar, the value for this calulation should = (10 + 9 + 8 + 7) = 34. When the 5th bar shows up it adds the 6 bars value to this cummulative value so = (34 + 6) the 4 previous bars plus the new bar.
Hope this is clear? i dont know how else to put it really.
Heres a basic of the code I have
dResult_1 = High[1];
dResult_2 = High[2];
dResult = dResult_1 - dResult_2;
I now want to add dResult to the last bars dResult, to give:
Cum_Result = ........
lets say in this case dResult = 23 for the 3rd bar
The 2nd bar dResult = 3
so i want to add the 3rd bar value to the 2nd ( 23 + 3 ) to give 26. Then on the next new 2nd bar, add this to the last value of 26. lets say the new 2nd bar comes in at 9, so add 26 to 9.
No matter what I do I cant seem to get the correct result. Any help or suggestion welcome.