|Tools, Techniques, and Training for Nirvana Platforms|
|OmniTrader, VisualTrader, OmniFunds & OmniVest|
|1 Tim 6:18-19 (ESV) … (the rich) are to do good, to be rich in good works, to be generous and ready to share, thus storing up treasure for themselves as a good foundation for the future, so that they may take hold of that which is truly life.|
| Using Custom Indicators in Scans|
USA: TX, Mansfield
|I originally posted this question in the Nirvana forum because I was browsing for an answer and found a thread that had been started there. I am moving my portion (and Jim's reply) here because I prefer to use TradeTight. |
I have a custom indicator that I want to use in an omniscan. What is the correct syntax?
Transferred by Don on 7/18/2015, Original Author: Don Schuman - 7/18/2015 2:53 AM, jump to original link
USA: TX, Mansfield
|Jim's Reply: |
Myindicator(Param,param,…) depending on how many #param stmts your Indic has. It will return the Return value to the script.
If your Indic has no param's then use ()
Transferred by Don on 7/18/2015, Original Author: Jim Dean - 7/18/2015 5:23 AM, jump to original link
USA: GA, Lawrenceville
|Thanks, Don. Here is a more thorough explanation of it, in the Syntax Room: |
USA: GA, Lawrenceville
|And, here is a long-winded followup that has to do with Boolean truth values and other nifty stuff about how the OLang indicator's return value can be used … |
If the Return value from the called function is itself a true/false flag, no other Boolean operators or syntax are needed.
That is, if myindicator() returns 0, it is interpreted as "false" … if it returns -1 (or any other nonzero value), it is interpreted as "true".
Or you can combine it (as a T/F value) with other logical conditions, such as:
myindicator() And Sma(V,50) > 1e5
Final note: although myindicator() by itself is considered equiv to True for any nonzero value, there is one special case where it must be exactly -1 to be treated as "true" … that's when it is used with a "not" modifier. "not true" = "false" … "not false" = "true" … the not operator flips the sense of the answer.
If you say "not myindicator()", then if myindicator() is -1, or if it's zero, it works properly. But if myindicator() has any other nonzero value, "not myindicator()" will fail to reverse it to "false" - in that case, use "myindicator() <> 0" instead.
The reason for this has to do with zeros and ones = the binary code that all computers think in. The binary representation for "false" is 0000000… etc … which also happens to represent a numeric value of "0". Binary for "true" is 11111111… etc … which also represents a numeric value of -1.
"Not" simply toggles the binary digits between 1<> 0, so: "not 1001001" changes to "0110110".
(1001001 has a decimal value of 73, and 0110110 equals 54 … "not 73" yields 54 and vice versa.)
Clearly, more than you asked about - but I've always considered number theory and its application to computers to be interesting and useful. If you are more interested in this, Google for things like "Boolean algebra" or "Bit Masking". It has a lot to do with electronics design and is a part of math "field theory" so some of the articles you find might be sort of intense.
Here's another application of it that might intrigue you:
OLang is restricted to a single, single-precision return value for each bar. So, we naturally conclude that there is no way to convey two or three or more pieces of info out of an OLang routine at once.
But, you can. For instance, you can use the integer portion to hold one value and the decimal portion to hold a second unrelated value, while the +/- sign can itself represent a third unrelated T/F value. Of course you need to "build" and "extract" the components of the return value carefully, using "int()" and "frac()" functions … and you need to keep in mind the reliable limit of only six full 0-9 digits in single precision - but even with those limitations, you can do a LOT using just a single number return.
Taking it further, you can actually convey FIFTEEN individual T/F distinctions, using Bit-Masking, in a single return value, since 32,767 = 111111111111111 in binary, and bit masking allows you to toggle each of those 1's individually to 0's. I've never need to do that much at once, but it's possible.
Here is a useful link with some info about converting between decimal and binary, plus a cute little converter tool - try converting 65,535 to decimal, for instance - it becomes 1111111111111111 … 16 ones - which in a "16-bit" processor is a "pure" representation of "true" - a snapshot is attached showing the math, and here is the link:
Math can be very useful and interesting!
image.jpg (130KB - 4 downloads)
|Owner of site: Jim Dean -- Forum content is confidential, and may not be distributed without written permission.|