SI
SI
discoversearch

We've detected that you're using an ad content blocking browser plug-in or feature. Ads provide a critical source of revenue to the continued operation of Silicon Investor.  We ask that you disable ad blocking while on Silicon Investor in the best interests of our community.  If you are not using an ad blocker but are still receiving this message, make sure your browser's tracking protection is set to the 'standard' level.
Strategies & Market Trends : TA-Quotes Plus

 Public ReplyPrvt ReplyMark as Last ReadFilePrevious 10Next 10PreviousNext  
To: Ken Adams who wrote (5411)7/16/1998 12:28:00 PM
From: Nazbuster  Read Replies (2) of 11149
 
Ken,

In general, the QP2 language is actually very easy to learn, but you have to pay GREAT attention to the details, especially the punctuation. (The language is derived from BASIC, a programming language which has been around for many years.) When writing your code, watch out for the following:

Spaces are ignored. Use them for clarity.

Statements end with a semi-colon. Don't put one after a "phrase", only the whole statement. For example,

for i=1 to 10 //implies STEP by +1 if omitted
do //required by QP2, optional/missing in other BASICs
xxx xxx;
xxx;
next i;

Note that the ";" for the "for/next" STATEMENT is after the "next i;", not the "for i=1 to 10" or the "do". Each STATEMENT within the loop gets its own semicolon.

Variables are INTEGER (whole numbers only), FLOAT (if you need decimals), or STRING (for alpha stuff). Declare all variables up front, ending the definition with semicolon: INTEGER a,b,c; (You can use more than one declaration of each type to get all variables defined.)

There is no way to define a variable as GLOBAL or STATIC so its value is retained from symbol to symbol. There is also no way to define an array of variables like "FLOAT sum(10);" to create 10 "cells", each called "sum" so you can create 10 different totals via "sum(5)=sum(5) + close(i);".

When doing calculations, there is a priority order for the arithmetic which usually means multiplication and division before addition or subtraction. Therefore 6+12/3+5 would be 15 not 11. When in doubt, use parentheses to make things clear: (6+(12/3)+5).

There doesn't seem to be exponentiation which is usually expressed as "**" or "^". (Too bad.)

Never set up a situation where you might divide by zero.

Use (or non-use) of the Equal sign is VERY confusing in QP2. This is the WORST part of the QP2 language syntax. You just have to memorize this stuff:

(1) When SETTING values for QP2-defined VARIABLES, use the equal sign. "DaysToLoad = 500;", "input='xxx';"
(2) When SETTING values for QP2 INDICATORS, use the SET statement:
"Set MACD = 8,17,9;"
(3) SETTING the value of QP2-defined SWITCHES seems to be more of a declaration than setting values and does not use the equal sign: "IssueType Common;"
(4) SETTING the value of variables YOU defined is done with the colon-equal: := (I hate this syntax.) "MyVariable := 35;"
(5) In TESTING values (in if/endif statements), use the equal sign: "If a=5 then..."

There are two types of conditional situations in QP2: For/Next and If/Endif.
(1) For/Next is a looping process controlled by the dependent variable and its max/min value.
(2) If/Endif conditions can be joined by AND, OR, and NOT. (You can use &. |, and ! in place of AND, OR and NOT.) Use parens for clarity.
(3) You can "NEST" statements to set up a loop or condition within another:

if a = 1 then
if b < 10 then
xxx;
endif;
else
if b > 10 then
xxx;
else
xxx;
endif;
endif;


I don't know if there is a proper way to exit a for-next loop. Some BASICs permit this via a GOTO branching statement or an EXITLOOP type of statement. The HELP file doesn't seem to address this.

Hope all this helps.
Report TOU ViolationShare This Post
 Public ReplyPrvt ReplyMark as Last ReadFilePrevious 10Next 10PreviousNext