I've tried everything to debug the code for a 2X Stochastic. I think the logic and math are right, but I cannot get it to display. It keeps telling me the return new Array is an invalid return. Please help. Thanks.
Announcement
Collapse
No announcement yet.
Stuck on Coding 2X Stochastic
Collapse
X
-
FiveString
There are a couple of errors in the script. The first one is in this line of code which is invalid
PHP Code:var KFullStudy = ema(3, KFast, 0);
The separate function would look like this
PHP Code:function calcKFast(){
var LL = lowest(7, hl2());
var HH = highest(7, hl2());
if ((HH - LL) == 0) {
var KFast=0;
}else{
var KFast = (100 * ((((high(0)+low(0))/2) - LL) / (HH-LL)));
}
return KFast;
}
PHP Code:var myStudy = efsInternal("calcKFast");
PHP Code:var KFullStudy = ema(3, myStudy);
PHP Code:var KFullStudy = ema(3, efsInternal("calcKFast"));
PHP Code:var DFullStudy = ema(3, KFull, 0);
PHP Code:var DFullStudy = ema(3, KFullStudy);
Having said all the above I think you are taking an unnecessarily complex route to calculate your study.
In fact the same study can be written in its most basic form as follows
PHP Code:function main(){
var KFullStudy = ema(3, stochK(7,1,1, hl2()));
var DFullStudy = ema(3,KFullStudy);
return new Array(KFullStudy.getValue(0),DFullStudy.getValue(0));
}
All you need to do is add the preMain() function with the required statements, user defined parameters (if any), etc
Alex
-
More Issues
Alex, I'm glad you have so much patience. I've cut and pasted from a number of places to get the attached the version I got working, but it does have some problems.
The efs file attached has "commented out" a section that I had to add to get it to work. The comments describe the problems.
The program does not ask for or allow user input for the variables and does not recognize the default values for those variables, so without the additional section, the program does not work.
I expect it's something simple, but I can't find it.
Thanks.
RichardAttached Files
Comment
-
Richard
As far as I know all comments are ignored except for the specific word main()
The addBand() functions need to be inside the main() function if you want them to be user adjustable.
When you move them into main() you will also need to add a tagID that is unique to each addBand() function
Alex
Comment
-
Alex,
Have now got it going, thank you.
Next step is tracing through the levels of called functions to see if there are any differences with the formula I tried to do.
It appears that the stochK called uses a value of Close(0) rather than High(0)+Low(0)/2. Am I wrong? If not, is there a simple way to change this or do I need to create more functions?
My latest is attached.Attached FilesLast edited by FiveString; 10-27-2006, 01:12 PM.
Comment
-
Alex,
I see on line 86 of my code where we call StochK with the parameter hl2.
But I can't see in StochK that there is an input for that parameter or where it uses the hl2. This also particularly shows in line 53 within calcPercentK which starts with close(0). I can't see where this is modified to become hl2.
What am I missing?
Richard
Comment
-
Alex,
Thank you for your infinite patience.
I understand the syntax of passing parameters to the stochK function. What I don't see is how those parameters are used when I look at the coding within that function. It does not define the series parameter coming in nor seem to use it. And the equation in line 53 does not adjust to use the series parameter passed in.
Richard
Comment
-
Richard
I am not sure I understand what equation you are referring to. In line 53 of the script you posted I see the following
fpArray[x] = new FunctionParameter("OverBought", FunctionParameter.NUMBER);
Also I am not sure how you can see the coding of the built-in stochK() function since that is hard-coded into the application
Alex
Comment
Comment