Hi,
one problem of your code is the line:
int AveragePips = NormalizeDouble(TotalPips/NumberofBarsforAverage,1); // calculate average Pips from last n candles
here you divide TotalPips througt NumberofBarsforAverage which is a const of 260000 even if
you have much less elements in your array. So you could use a separate counter or you take
the size of the array for the division.
Another problem is that AvaragePips is of type int - you should use a double instead of an int
(even your function is declared as a double function and you return an int)
And of course it is very inefficient to increase the array by one element on each pass.
I hope, this helps you.
Best regards,
May I suggest a simplification of your issue (not an exact correction of your code, but something so simple that it saves you a lot of work)?
You are trying to calculate the equivalent of Average Range of a Bar for a time period between London Open and New York Close ( 14 Hours).
Now the value of a bar's range is close in value to its True Range value, and given that the standard ATR(Average true Range) Indicator uses a Simple Moving Average, then a ATR of a period equivalent to the 14 hours will give you similar results as what you are trying to achieve, if you obtain the value at the last bar of that period (closing bar of New York close).
For example, on a H1 chart, the ATR(14) at closing bar of New York close, will give similar results as the code you are trying to calculate, just as for a M15 chart, an ATR(56) will be similar.
This will reduce your project to 1 or 2 lines of code using iATR() function. It is not exactly the same, but it is very close and will save you plenty of coding and be more efficient.
Hi Werner,
Thanks so much for spotting my mistakes, I managed to solve it some how!
Hi,
one problem of your code is the line:
here you divide TotalPips througt NumberofBarsforAverage which is a const of 260000 even if
you have much less elements in your array. So you could use a separate counter or you take
the size of the array for the division.
Another problem is that AvaragePips is of type int - you should use a double instead of an int
(even your function is declared as a double function and you return an int)
And of course it is very inefficient to increase the array by one element on each pass.
I hope, this helps you.
Best regards,
Hi Fernando,
That's a great idea, I never thought of it myself before. Thanks for the recommendation!
May I suggest a simplification of your issue (not an exact correction of your code, but something so simple that it saves you a lot of work)?
You are trying to calculate the equivalent of Average Range of a Bar for a time period between London Open and New York Close ( 14 Hours).
Now the value of a bar's range is close in value to its True Range value, and given that the standard ATR(Average true Range) Indicator uses a Simple Moving Average, then a ATR of a period equivalent to the 14 hours will give you similar results as what you are trying to achieve, if you obtain the value at the last bar of that period (closing bar of New York close).
For example, on a H1 chart, the ATR(14) at closing bar of New York close, will give similar results as the code you are trying to calculate, just as for a M15 chart, an ATR(56) will be similar.
This will reduce your project to 1 or 2 lines of code using iATR() function. It is not exactly the same, but it is very close and will save you plenty of coding and be more efficient.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all! As explained in the subject, I am having difficulties calculating the average pip per bar for only the London and NY trading sessions.
Here's a summary of what I did, lest my code doesn't make sense to some of you:
Could any kind soul help me out on this, what's wrong with the inputting of elements in the array such that my code wouldn't run?
Many thanks in advance!