Count Positive and Negative Bars
-
What is the easiest method to count the number of bars that ended up positive and negative over the last 25 bars?
-
Always the best method to do calculations over tha past candles is by using custom indicators, this is what they are supposed to do - claculations. Also, normally indicators does not recalculate things that were already calculated and this is natural to them, but not natural for expert advisors and scripts.
In the EA this can be done with a regular loop - you start from the first candle, iterate through the old candles and increase some variables within the loop. The easiest will be to code it actually, something like that:
int positive = 0; int negative = 0; for (int i=1; i<=25; i++) { if (Close* > Open*) {positive++;} else {negative++;} } -
OK thanks
So I write my source code and stick it in a custom block and have it execute every tick or bar, correct?
see pictureBut how would I then be able to use the value for negative and positive for further manipulations?
Sorry but I am still having a hard time creating custom code blocks...and how to connect and use them afterwards
-
I can't give you beautiful solution for this. "positive" and "negative" can be global Variables and then their "int" will not be needed, but you need to remember that this block also needs those global variables to be defined with their correct names. Again, the best is really to have some indicator, you can search for something or ask someone to make one. This is very easy calculation and I can even say that you can do it on your own. Plus, the indicator does not recalulate things every time and can show something meaningful.
-
Okay thanks for the reply
I have been thinking during my holiday and will make an indicator to solve this issue