any ideas if this is the correct averaging process?
I would also like to work out the average that price comes near the LWMA but doesn't touch it - perhaps I could just work out the overall average for this and say that
- the low comes to within an average of x of the lower LWMA
- the high comes to withing an average of x of the higher LWMA
?
hi i have to say that a read only fast over your code. what are you trying to investigate? the average pips (of the last 20 candels) which are above the upper lwma/under the lower lwma? if so you have to reset the variables in the beginning of each loop.
try this:
while(i>=0) { //RESET THE TEMPORARY VARIABLES AFTER EACH LOOP varPriceExceededHighCount=0; varPriceExceededHigh=0; varPriceExceededLowCount=0; varPriceExceededLow=0; //********************************************* for (int j=19; j>=0; j--) { if (High[i+j] > iMA(NULL, 0, 2, 0, MODE_LWMA, PRICE_HIGH, i+j)) { //count this bar towards the total and add it to the var varPriceExceededHighCount++; varPriceExceededHigh= varPriceExceededHigh + (High[i+j] - iMA(NULL, 0, 2, 0, MODE_LWMA, PRICE_HIGH, i+j)); } if (Low[i+j] < iMA(NULL, 0, 2, 0, MODE_LWMA, PRICE_LOW, i+j)) { varPriceExceededLowCount++; varPriceExceededLow= varPriceExceededLow + (iMA(NULL, 0, 2, 0, MODE_LWMA, PRICE_LOW, i+j) - Low[i+j]); } } // for //calculate averages if (varPriceExceededHighCount!=0) varavHigh = varPriceExceededHigh/varPriceExceededHighCount; bufferHigh[i] = varavHigh; if (varPriceExceededLowCount!=0) varavLow = varPriceExceededLow/varPriceExceededLowCount; bufferLow[i] = varavLow; i--; } // while
i hope i am getting right what you wanted to do.
//z
It's more that I want it over the whole range of candles on the chart. If the variables are reset then so is the average???
So, if price exceeds the LWMA, I count it toward the average for that. If it exceeds the lower then I count it towards the average of the low.
I should end up with out of say 50 candles something like
price exceeded the high 10 times by an average of 50pips each time &
price exceeded the low by 7 times by an average of 24 pips each time.- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have some code to work out the average amount of pips that price exceeds a 2 period LWMA on my chart.
Someone advised me it had to be worked out using the moving average but shouldn't it be using all the candles on the chart?
So, if price exceeds the LWMA, I increase the count to work out the average. If it doesn't exceed the LWMA, then I don't use it in the calculation.