Calculate Stochastic Formula on a array (non indicator buffer array) - is iStochasticOnArray available somewhere?
Not that I know the logic, but I would venture a guess that the third argument to
ArrayMinimum, and likewise ArrayMaximum, are wrong.
For example, in the first iteration, the value of "i" is "ArraySize(Commercial)-COTIndexPeriod", making the third argument equal to "ArraySize(Commercial)-1", and in that case, the logic attempts to look past the top of the array.?
Maybe the "+COTIndexPeriod" terms should be removed?
I would further guess that the "-1" terms should be removed as well, and the loops should start at ".... - 1".
In other words, I'm guessing that SmallestBuffer[i] is to hold the smallest value of the period in Commercial that starts at index i, and is of COTIndexPeriod length. Similarly for LargestBuffer. Then COTIndex[i] would have a value relating to the period [ i, i+COTIndexPeriod-1 ] in Commercial.
For example, in the first iteration, the value of "i" is "ArraySize(Commercial)-COTIndexPeriod", making the third argument equal to "ArraySize(Commercial)-1", and in that case, the logic attempts to look past the top of the array.?
Maybe the "+COTIndexPeriod" terms should be removed?
I would further guess that the "-1" terms should be removed as well, and the loops should start at ".... - 1".
In other words, I'm guessing that SmallestBuffer[i] is to hold the smallest value of the period in Commercial that starts at index i, and is of COTIndexPeriod length. Similarly for LargestBuffer. Then COTIndex[i] would have a value relating to the period [ i, i+COTIndexPeriod-1 ] in Commercial.
richplank:
Not that I know the logic, but I would venture a guess that the third argument to ArrayMinimum, and likewise ArrayMaximum, are wrong.
For example, in the first iteration, the value of "i" is "ArraySize(Commercial)-COTIndexPeriod", making the third argument equal to "ArraySize(Commercial)-1", and in that case, the logic attempts to look past the top of the array.?
Maybe the "+COTIndexPeriod" terms should be removed?
I would further guess that the "-1" terms should be removed as well, and the loops should start at ".... - 1".
In other words, I'm guessing that SmallestBuffer[i] is to hold the smallest value of the period in Commercial that starts at index i, and is of COTIndexPeriod length. Similarly for LargestBuffer. Then COTIndex[i] would have a value relating to the period [ i, i+COTIndexPeriod-1 ] in Commercial.
Not that I know the logic, but I would venture a guess that the third argument to ArrayMinimum, and likewise ArrayMaximum, are wrong.
For example, in the first iteration, the value of "i" is "ArraySize(Commercial)-COTIndexPeriod", making the third argument equal to "ArraySize(Commercial)-1", and in that case, the logic attempts to look past the top of the array.?
Maybe the "+COTIndexPeriod" terms should be removed?
I would further guess that the "-1" terms should be removed as well, and the loops should start at ".... - 1".
In other words, I'm guessing that SmallestBuffer[i] is to hold the smallest value of the period in Commercial that starts at index i, and is of COTIndexPeriod length. Similarly for LargestBuffer. Then COTIndex[i] would have a value relating to the period [ i, i+COTIndexPeriod-1 ] in Commercial.
Hi Rich,
Thanks for your input. I couldnt see the forest for the trees, you are right and I removed everything except for the parameters to ArrayMaximum and ArrayMinimum. Below is my final optimized code to run Stochastics on a array:
int start() { //<snip>...begin of start() //calculate Stochastic Fast %K for (i =ArraySize(MyArray)-StochPeriod-1; i >= 0; i--) { ExtMapBuffer1[i] = CalculateStochOnArray(MyArray,i); } //<snip>...end of start()... } //calculates Stochastics fast %k. takes the array holding our values and current index we are iterating through double CalculateStochOnArray(double TheArray[], int i) { double SmallestBuffer[], //buffer to hold the smallest value LargestBuffer[], //buffer to hold the largest value StochFastK, //Stochastic Fast %K top, //holds top half of calculation bottom; //holds bottom half of calculation int position=0; //place in SmallestBuffer/Largestbuffer for our largest or smallest value ArrayResize(SmallestBuffer, ArraySize(TheArray)); //size our array accordingly ArrayResize(LargestBuffer, ArraySize(TheArray)); position = ArrayMinimum(TheArray, StochPeriod, i); //find the smallest value that starts at index i and is of StochasticPeriod length SmallestBuffer[i] = TheArray[position]; position = ArrayMaximum(TheArray, StochPeriod, i); //find the largest value that starts at index i and is of StochasticPeriod length LargestBuffer[i] = TheArray[position]; top = TheArray[i]-SmallestBuffer[i]; //holds top half of StochFastK calculation bottom = MathMax(0.0001, LargestBuffer[i] - SmallestBuffer[i]); //holds bottom half of StochFastK calculation. Use MathMax to prevent divide by zero errors StochFastK = (top/bottom)*100; return(StochFastK); }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
I need to calculate the stochastic formula on a array (looking for fast %k only), this array is not a indicator buffered array. This is my code:
So the goal is to have the Stochastic value stored in the COTIndex[i] array. However, the calculated values are in incorrect. Does anyone have a Stochastic-On-Array (iStochOnArray) implementation? or maybe does anyone see where the logical problem is on my code? I'm stuck and would greatly appreciate any help!
Thank you
Mike