Rank:: Advanced Member
Groups: Registered, Registered Users, Subscribers, Unverified Users Joined: 10/28/2004(UTC) Posts: 3,111 Location: Perth, Western Australia
Was thanked: 16 time(s) in 16 post(s)
|
underground wrote:"All Three Increasing or Decreasing"
If(ROC(Fml("Name_A"),1,$)>=0,1,
If(ROC(Fml("Name_A"),1,$)<=0,-1,0))
+
If(ROC(Fml("Name_B"),1,$)>=0,1,
If(ROC(Fml("Name_B"),1,$)<=0,-1,0))
+
If(ROC(Fml("Name_C"),1,$)>=0,1,
If(ROC(Fml("Name_C"),1,$)<=0,-1,0))
I would also check the logic here again too!
Have you ever heard of a tool called a truth table or logic table? They are an invaluable coding/programming tool that allows you to see what the results of an algorithm are, to make sure the code performs as intended.
A simple example, for the AND boolean operator:
A B A AND B
0 0 0
0 1 0
1 0 0
1 1 1
In your case the table might look like:
X:=ROC(Fml("Name_A"),1,$);
Z:=If(X>=0,1,If(X<=0,-1,0))
X Z
0 1
1 1
10 1
-1 -1
-10 -1
Now although your function return the right results, we can use the truth table to see that Z variable never returns 0. This is because the Z variable has only two states, and you have coded three states. We can then re-write the Z variable as:
Z:=If(X>=0,1,-1)
which is simpler and probably less prone to error!
Remember: when using referential operators the combinations to be considered are:
= equal
<> not equal to
< less than
> greater than
<= less than or equal to
>= greater than or equal to
In some serious programming applications (investing is a serious concern to most of us!?) all six situations should be considered, if not coded into the program.
If you follow these rules and use these tools against your code, you will see the flawed logic in your code. Your indicator can return integer values between 3 and -3, including zero. Unless you are only looking for the extreme values (3 and -3) then you are going to be in a lot of trouble when trying to create the filter for the possible scenarios that lead to these other results. I suggest you have another read of the guidelines for posting code, rethink what you are trying to achieve, write it down in very clear and precise simple terms, post it here, code it in MS and post it here too. We can then help you achieve the results you seek.
Hope this helps.
wabbit :D
|