{"id":103,"date":"2013-04-23T12:17:00","date_gmt":"2013-04-23T12:17:00","guid":{"rendered":"http:\/\/zerodha.com\/z-connect\/?p=270"},"modified":"2026-02-26T17:28:05","modified_gmt":"2026-02-26T11:58:05","slug":"algoz-technical-analysis","status":"publish","type":"post","link":"https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis","title":{"rendered":"Coding Technical Analysis Functions"},"content":{"rendered":"<p style=\"text-align: left;\">Beginners, don&#8217;t worry if you don&#8217;t understand when you read this manual. We will explain how to code your technical analysis strategy in the &#8220;<a href=\"https:\/\/zerodha.com\/z-connect\/blog\/view\/code-your-technical-analysis-strategy\">Code your strategy<\/a>&#8221; section.<\/p>\n<h3>Technical Analysis<strong><br \/>\n<\/strong><\/h3>\n<p style=\"text-align: left;\"><strong>NEST Pulse<\/strong> provides many built-in Technical Analysis functions. Using only a single line of code you can calculate functions such as Moving Averages, Bollinger Bands, Japanese Candlesticks and so on. The following is a simple example of how to use one of the most common technical analysis functions, the Simple Moving Average:<\/p>\n<pre style=\"text-align: left;\">LAST &gt;SimpleMovingAverage(CLOSE, 20)<\/pre>\n<p style=\"text-align: left;\">The script will check if the last traded price is over the 20-day Moving Average of the close price.<\/p>\n<p style=\"text-align: left;\">The CLOSE variable is actually a vector of closing prices, not just the most recent close price. You can use OPEN, HIGH, LOW, CLOSE and VOLUME vectors to create your own calculated vectors using the &#8220;SET&#8221; keyword:<\/p>\n<pre style=\"text-align: left;\">SET Median = (CLOSE + OPEN)\/ 2<\/pre>\n<p style=\"text-align: left;\">This code creates a vector containing the median price for each trading day.<\/p>\n<p style=\"text-align: left;\">We can use the Median vector inside any function that requires a vector:<\/p>\n<pre style=\"text-align: left;\">LAST &gt;SimpleMovingAverage(Median, 20)<\/pre>\n<p style=\"text-align: left;\">This function evaluates to True when the last traded price is greater than the 20-day Moving Average of the Median price.<\/p>\n<p style=\"text-align: left;\">Because Functions return Vectors, Functions can also be used as valid arguments within other Functions like:<\/p>\n<pre style=\"text-align: left;\">LAST &gt;SimpleMovingAverage(SimpleMovingAverage(CLOSE, 30), 20)<\/pre>\n<p style=\"text-align: left;\">This evaluates to True when the last price is greater than the 20-day moving average of the 30-day moving average of the close price.<\/p>\n<h4 style=\"text-align: left;\">Crossovers<\/h4>\n<p style=\"text-align: left;\">You may be familiar with the term &#8220;crossover&#8221;, which is what happens when one series crosses over the top of another series as depicted in the image below:<\/p>\n<div id=\"attachment_1161\" style=\"width: 784px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1161\" class=\"size-full wp-image-1161 \" src=\"https:\/\/zerodha.com\/z-connect\/wp-content\/uploads\/2013\/10\/img_52667092ba7dc.png\" alt=\"\" width=\"774\" height=\"346\" \/><p id=\"caption-attachment-1161\" class=\"wp-caption-text\">Moving Average Crossover on a Google Finance chart<\/p><\/div>\n<p style=\"text-align: left;\">Many technical indicators such as the MACD for example, have a &#8220;signal line&#8221;. A buy or sell signal is generated when the signal line crosses over or under the technical indicator.<\/p>\n<p style=\"text-align: left;\">The CROSSOVER function helps you when one series has crossed over another.<\/p>\n<p style=\"text-align: left;\">For example, we can find the exact point in time when one moving average crossed over another by using the CROSSOVER function:<\/p>\n<pre style=\"text-align: left;\">SET MA1 = SimpleMovingAverage(CLOSE, 28)<\/pre>\n<pre style=\"text-align: left;\">SET MA2 = SimpleMovingAverage(CLOSE, 14)<\/pre>\n<pre style=\"text-align: left;\">CROSSOVER(MA1, MA2) = TRUE<\/pre>\n<p style=\"text-align: left;\">The script above will evaluate to true when the MA1 vector most recently crossed over the MA2 vector. And we can reverse the script to the MA1 vector crossed below the MA2 vector: CROSSOVER(MA2, MA1) = TRUE<\/p>\n<h3 style=\"text-align: left;\">Primitive functions and operators<strong><br \/>\n<\/strong><\/h3>\n<h4 style=\"text-align: left;\">Primitives<\/h4>\n<p style=\"text-align: left;\">The built-in functions of NEST Pulse, are known as Primitives. These important functions define the NEST Pulse programming language and provide the basic framework required to build complex trading systems from the ground up.<\/p>\n<p style=\"text-align: left;\">Literally any type of trading system can be developed using the NEST Pulse programming language with minimal effort. If a system can be expressed in mathematical terms or programmed in any structured, procedural language such as C++, VB, or Java you can rest with the assurance that the same formulas can also be programmed using the NEST programming language.<\/p>\n<p style=\"text-align: left;\">Sometimes Technical Analysis formula can be very complex. For example, Technical Analysis functions exist that require recursive calculations and complicated IF-THEN-ELSE structures as part of their formula. These complex trading systems are traditionally developed in a low level programming language.<\/p>\n<p style=\"text-align: left;\">You can perform these calculations in a much\u00a0 simpler way by means of vector operations and simulated control structure using NEST Pulse. Here&#8217;s more on it:<\/p>\n<h4 style=\"text-align: left;\">Conditional IF function<strong><br \/>\n<\/strong><\/h4>\n<p style=\"text-align: left;\">IF(Condition, True part, False part)<\/p>\n<p style=\"text-align: left;\">The conditional &#8220;IF&#8221; function allows you to design complex Boolean logic filters. If you paste the following script into the Script area in your trading Software Application, you will see a column of numbers that oscillate between 1 and -1, depending on when the closing price is greater than the opening price:<\/p>\n<pre style=\"text-align: left;\">SET A = IF(CLOSE &gt; OPEN, 1, -1)<\/pre>\n<p style=\"text-align: left;\">The first argument of the &#8220;IF&#8221; function is a logical test. The second argument is the value that will be used if the condition evaluates to TRUE. Conversely, the third argument is the value that will be used if the condition evaluates to FALSE.<\/p>\n<p style=\"text-align: left;\">The logical test may be any value or expression that can be evaluated to TRUE or FALSE. For example, CLOSE = OPEN is a logical expression; if the close price is the same as the opening price, the expression evaluates to TRUE, otherwise, the expression evaluates to FALSE.<\/p>\n<h4 style=\"text-align: left;\">LOOP function<\/h4>\n<pre style=\"text-align: left;\">LOOP(Vector1, Vector2, Offset1, Offset2, Operator)<\/pre>\n<p style=\"text-align: left;\">LOOP provides simulated control structure by means of a single function call.<\/p>\n<p style=\"text-align: left;\">Consider the following:<\/p>\n<pre style=\"text-align: left;\">SET X = CLOSE<\/pre>\n<pre style=\"text-align: left;\">SET X = REF(X, 1) + X<\/pre>\n<p style=\"text-align: left;\">This script simply adds the previous close to the most current close, REF(X, 1) is evaluated once. This is expected behavior for a vector programming language; vectors are calculated independently in a stepwise fashion and are not recursive.<\/p>\n<p style=\"text-align: left;\">Now by changing CLOSE to 0, logically we would expect X to equal the previous X value plus one, and therefore expect REF(X, 1) to be evaluated once for each record in the vector:<\/p>\n<pre style=\"text-align: left;\">SET X = 0<\/pre>\n<pre style=\"text-align: left;\">SET X = REF(X, 1) + X<\/pre>\n<p style=\"text-align: left;\">Although we are looking at the exact same formula, because we are initializing X with a scalar and X is not related to any existing vector we would now expect X to be calculated as a series: 1,2,3,4,5,6,&#8230;n<\/p>\n<p style=\"text-align: left;\">We are now exceeding the limits of a vector programming language by requiring control structure. Anytime we assign a variable to itself such as SET X = F(X) we are expecting F(X) to be recursive. In the first example we write SET X = CLOSE. CLOSE is a variable, not a function and does not have any relationship with X. Our expectations change when we initialize X with anything other than an existing vector.<\/p>\n<p style=\"text-align: left;\">The LOOP function overcomes this inherent limitation by simulating a structured programming construct, the for-loop iteration:<\/p>\n<p style=\"text-align: left;\">LOOP(Vector1, Vector2, Offset1, Offset2, Operator)<\/p>\n<p style=\"text-align: left;\">Vector1 is the vector to initialize the calculation form. Offset1 is the offset where values are referenced in Vector1 for the incremental calculation, and Offset2 is the offset where values are referenced from in Vector2.<\/p>\n<p style=\"text-align: left;\"><strong>Example 1:<\/strong><\/p>\n<p style=\"text-align: left;\">X (Vector1) is a series from 5.25 to 11.25.<\/p>\n<p style=\"text-align: left;\">If we write LOOP(X, 2, 1, 0, MULTIPLY) the vector returned will contain values initialized by X, offset by 1 and multiplied by 2.<\/p>\n<p style=\"text-align: left;\"><strong>Example 2:<\/strong><\/p>\n<p style=\"text-align: left;\">In the case of SET X = REF(X, 1), Vector1 is X and Vector2 is 1. Since we&#8217;re adding the value of 1 (not a vector) to X in the following example, Offset2 is set to zero:<\/p>\n<pre style=\"text-align: left;\">SET X = LOOP(X, 1, 1, 0, ADD)<\/pre>\n<p style=\"text-align: left;\">And now X contains the series 1,2,3,4,5,6,&#8230;n<\/p>\n<p style=\"text-align: left;\"><strong>Example 3:<\/strong><\/p>\n<pre style=\"text-align: left;\">SET X = REF(CLOSE,1)<\/pre>\n<pre style=\"text-align: left;\">SET Y = (REF(Y, 3) - X) * 2<\/pre>\n<p style=\"text-align: left;\">Because Y requires control structure we must instead write: SET X = REF(CLOSE,1)<\/p>\n<pre style=\"text-align: left;\">SET Y = LOOP(Y, X, 3, 0, SUBTRACT) * 2<\/pre>\n<p style=\"text-align: left;\">We could reduce that to:<\/p>\n<pre style=\"text-align: left;\">SET Y = LOOP(Y, CLOSE, 3, 1, SUBTRACT) * 2<\/pre>\n<p style=\"text-align: left;\">Valid operators are ADD, SUBTRACT, MULTIPLY and DIVIDE.<\/p>\n<p style=\"text-align: center;\">\u00a0<\/p>\n<h4>COUNTIF<\/h4>\n<p style=\"text-align: left;\">COUNTIF(Condition): Returns a Vector representing the total number of times the specified condition evaluated to TRUE. Example: COUNTIF(CROSSOVER(SimpleMovingAverage(CLOSE, 14), CLOSE)) The script returns a vector with increasing values expressing the number of times the 14-day Simple Moving Average crossed over the closing price.<\/p>\n<h4 style=\"text-align: left;\">LASTIF<\/h4>\n<p style=\"text-align: left;\">LASTIF(Condition): Similar to COUNTIF, except LASTIF returns a Vector containing the number of days since the last time the specified condition evaluated to TRUE. The count is reset to zero(0) each time the condition evaluates to TRUE.<\/p>\n<p style=\"text-align: left;\">Example: LASTIF(CLOSE &lt; REF(CLOSE, 1)) The script returns a vector that increases in value for each bar where the closing price was not less than the previous closing price. When the condition evaluates to TRUE, meaning the closing price was less than the previous closing price, the reference count is reset to zero.<\/p>\n<h4 style=\"text-align: left;\">SUMIF<\/h4>\n<p style=\"text-align: left;\">SUMIF(Condtion, Vector) Last in the &#8220;IF&#8221; function lineup is the SUMIF function. This function outputs a running sum of all values in the supplied Vector wherever the supplied condition evaluates to TRUE.<\/p>\n<p style=\"text-align: left;\">For example if we wanted a Vector containing the sum of Volume for all the days where the closing price closed up 5%, we could write:<\/p>\n<pre style=\"text-align: left;\">SUMIF(CLOSE &gt; REF(CLOSE,1) * 1.05, VOLUME)<\/pre>\n<p style=\"text-align: left;\">The result will be a Vector containing a running sum of Volume for each day where the closing price closed up at by least 5%.<\/p>\n<h4 style=\"text-align: left;\">SUM<\/h4>\n<p style=\"text-align: left;\">SUM(Vector, Periods): The SUM function (not to be confused with the SUMIF function) outputs a Vector containing a running sum, as specified by the Periods argument.<\/p>\n<p style=\"text-align: left;\">Example:<\/p>\n<p style=\"text-align: left;\">SUM(CLOSE, 10) The script returns a vector of sums based on a 10-period window.<\/p>\n<h4 style=\"text-align: left;\">AVG<\/h4>\n<p style=\"text-align: left;\">AVERAGE(Vector, Periods)<\/p>\n<p style=\"text-align: left;\">AVG(Vector, Periods): Returns a vector containing a running average, as specified by the Periods argument. The AVERAGE function can also be referenced by AVG for short. Example: AVERAGE(CLOSE, 10) AVG(CLOSE, 10) Both scripts return a vector of averages based on a 10- period window.<\/p>\n<h4 style=\"text-align: left;\">MAX<\/h4>\n<p style=\"text-align: left;\">MAX(Vector, Periods): Returns a vector containing a running maximum, as specified by the Periods argument. The values represent the maximum value for each window.<\/p>\n<p style=\"text-align: left;\">Example:<\/p>\n<pre style=\"text-align: left;\">MAX(CLOSE, 10)<\/pre>\n<p style=\"text-align: left;\">Returns a vector of maximum values based on a 10- period window.<\/p>\n<h4 style=\"text-align: left;\">MIN<\/h4>\n<p style=\"text-align: left;\">MIN(Vector, Periods): Returns a vector containing a running minimum, as specified by the Periods argument. The values represent the minimum value for each window.<\/p>\n<p style=\"text-align: left;\">Example:<\/p>\n<pre style=\"text-align: left;\">MIN(CLOSE, 10)<\/pre>\n<p style=\"text-align: left;\">Returns a vector of minimum values based on a 10- period window.<\/p>\n<h4 style=\"text-align: left;\">MAXOF<\/h4>\n<p style=\"text-align: left;\">MAXOF(Vector1, Vector2, [Vector3]..[Vector8]): Returns a vector containing a maximum value of all specified vectors, for up to eight vectors. Vector1 and Vector2 are required and vectors 3 through 8 are optional.<\/p>\n<p style=\"text-align: left;\">Example:<\/p>\n<pre style=\"text-align: left;\">MAXOF(CLOSE, OPEN)<\/pre>\n<p style=\"text-align: left;\">Returns a vector containing the maximum value for each bar, which is either the opening price or the closing price in this example.<\/p>\n<h4 style=\"text-align: left;\">MINOF<\/h4>\n<p style=\"text-align: left;\">MINOF(Vector1, Vector2, [Vector3]..[Vector8]):Returns a vector containing a minimum value of all specified vectors, for up to eight vectors. Vector1 and Vector2 are required and vectors 3 through 8 are optional.<\/p>\n<p>Example:<\/p>\n<pre>MINOF(CLOSE, OPEN)<\/pre>\n<p style=\"text-align: left;\">Returns a vector containing the minimum value for each bar, which is either the opening price or the closing price in this example.<\/p>\n<h4 style=\"text-align: left;\">REF<\/h4>\n<p style=\"text-align: left;\">REF(Vector, Periods)<\/p>\n<p style=\"text-align: left;\">By default all calculations are performed on the last, most recent value of a vector. The following script evaluates to true when the last open price (the current bar&#8217;s open price) is less than Rs.30:<\/p>\n<pre style=\"text-align: left;\">OPEN &lt; 30<\/pre>\n<p style=\"text-align: left;\">By default OPEN is assumed to be the current bar&#8217;s open. You can reference a previous value of a vector by using the REF function: REF(OPEN, 1) &lt; 30, and now the script will check if the previous bar&#8217;s open price was less than Rs.30. The number 1 (the second argument) tells the REF function to reference values as of one bar ago. To reference values two bars ago, simply use 2 instead of 1. The valid range for the Periods argument is 1- 250 unless otherwise noted.<\/p>\n<h4 style=\"text-align: left;\">TREND<\/h4>\n<p style=\"text-align: left;\">TREND(Vector)<\/p>\n<p style=\"text-align: left;\">The TREND function can be used to determine if data is trending upwards, downwards, or sideways. This function can be used on the price (open, high, low, close), volume, or any other vector. The TREND function returns a constant of either UP, DOWN or SIDEWAYS. Example: TREND(CLOSE) = UP AND TREND(VOLUME) = DOWN<\/p>\n<p style=\"text-align: left;\">TREND is often the first function used as a means of filtering securities that are not trending in the desired direction.<\/p>\n<h4 style=\"text-align: left;\">CROSSOVER<\/h4>\n<p style=\"text-align: left;\">Many technical indicators such as the MACD for example, have a &#8220;signal line&#8221;. Traditionally a buy or sell signal is generated when the signal line crosses over or under the technical indicator. The CROSSOVER function helps you one series has crossed over another. For example, we can find the exact point in time when one moving average crossed over another by using the CROSSOVER function: SET MA1 = SimpleMovingAverage(CLOSE, 28)<\/p>\n<pre style=\"text-align: left;\">SET MA2 = SimpleMovingAverage(CLOSE, 14)<\/pre>\n<pre style=\"text-align: left;\">CROSSOVER(MA1, MA2) = TRUE<\/pre>\n<p style=\"text-align: left;\">The script above will evaluate to true when the MA1 vector most recently crossed over the MA2 vector. And we can reverse the script to the MA1 vector crossed below the MA2 vector: CROSSOVER(MA2, MA1) = TRUE<\/p>\n<h3 style=\"text-align: left;\">Math Functions<\/h3>\n<p style=\"text-align: left;\">Note that all math functions return a vector.<\/p>\n<p style=\"text-align: left;\">For example ABS(CLOSE &#8211; OPEN) returns a vector of the ABS value of CLOSE &#8211; OPEN (one record per bar). The RND function returns a vector of random values, one for each bar, and so forth.<\/p>\n<h4 style=\"text-align: left;\">ABS<\/h4>\n<p style=\"text-align: left;\">The ABS function returns the absolute value for a number. Negative numbers become positive and positive numbers remain positive.<\/p>\n<p>Example:<\/p>\n<pre>ABS(CLOSE - OPEN)<\/pre>\n<p style=\"text-align: left;\">The script always evaluates to a positive number, even if the opening price is greater than the closing price.<\/p>\n<h4 style=\"text-align: left;\">SIN<\/h4>\n<p style=\"text-align: left;\">The SIN function returns the sine of a number (angle).<\/p>\n<p>Example:<\/p>\n<pre>SIN(45)<\/pre>\n<p style=\"text-align: left;\">The script outputs 0.851<\/p>\n<h4 style=\"text-align: left;\">COS<\/h4>\n<p style=\"text-align: left;\">COS returns the cosine of a number (angle).<\/p>\n<p>Example:<\/p>\n<pre>COS(45)<\/pre>\n<p style=\"text-align: left;\">The script outputs 0.525<\/p>\n<h4 style=\"text-align: left;\">TAN<\/h4>\n<p style=\"text-align: left;\">The TAN function returns the tangent of a number (angle).<\/p>\n<p>Example:<\/p>\n<pre>TAN(45)<\/pre>\n<p style=\"text-align: left;\">The script outputs 1.619<\/p>\n<h4 style=\"text-align: left;\">ATN<\/h4>\n<p style=\"text-align: left;\">Returns the arc tangent of a number.<\/p>\n<p>Example:<\/p>\n<pre>ATN(45)<\/pre>\n<p style=\"text-align: left;\">The script outputs 1.548<\/p>\n<h4 style=\"text-align: left;\">EXP<\/h4>\n<p style=\"text-align: left;\">EXP raises &#8220;e&#8221; to the power of a number. The LOG function is the reverse of this function. Example: EXP(3.26)<\/p>\n<p style=\"text-align: left;\">The script outputs 26.28<\/p>\n<h4 style=\"text-align: left;\">LOG<\/h4>\n<p style=\"text-align: left;\">Returns the natural logarithm of a positive number. The EXP function is the reverse of this function.<\/p>\n<p>Example:<\/p>\n<pre>LOG(26.28)<\/pre>\n<p style=\"text-align: left;\">The script outputs 3.26<\/p>\n<h4 style=\"text-align: left;\">LOG10<\/h4>\n<p style=\"text-align: left;\">Returns the base 10 logarithm of a positive number.<\/p>\n<p style=\"text-align: left;\">Example: LOG10(26.28) The script outputs 1.42<\/p>\n<h4 style=\"text-align: left;\">RND<\/h4>\n<p style=\"text-align: left;\">The RND function returns a random number from 0 to a maximum value. Example: RND(100) Outputs a random number from 0 to 100.<\/p>\n<h3 style=\"text-align: left;\">Operators<\/h3>\n<h4 style=\"text-align: left;\">Equal (=)<\/h4>\n<p style=\"text-align: left;\">The equal operator is used to assign a value to a variable or vector, or to compare values. When used for assignment, a single variable or vector on the left side of the = operator is given the value determined by one or more variables, vectors, and\/or expressions on the right side. Also, the SET keyword must precede the variable name when the = operator is used for an assignment:<\/p>\n<pre style=\"text-align: left;\">SET A = 123<\/pre>\n<pre style=\"text-align: left;\">SET B = 123<\/pre>\n<pre style=\"text-align: left;\">A = B = TRUE<\/pre>\n<h4 style=\"text-align: left;\">Greater Than (&gt;)<\/h4>\n<p style=\"text-align: left;\">The &gt; operator determines if the first expression is greater-than the second expression. Example:<\/p>\n<pre style=\"text-align: left;\">SET A = 124<\/pre>\n<pre style=\"text-align: left;\">SET B = 123<\/pre>\n<pre style=\"text-align: left;\">A &gt; B = TRUE<\/pre>\n<h4 style=\"text-align: left;\">Less Than (&lt;)<\/h4>\n<p style=\"text-align: left;\">The &lt; operator determines if the first expression is less-than the second expression. Example: SET A = 123<\/p>\n<pre style=\"text-align: left;\">SET B = 124<\/pre>\n<pre style=\"text-align: left;\">A &gt; B = TRUE<\/pre>\n<h4 style=\"text-align: left;\">Greater Than Or Equal To (&gt;=)<\/h4>\n<p style=\"text-align: left;\">The &gt;= operator determines if the first expression is greater-than or equal to the second expression. Example:<\/p>\n<pre style=\"text-align: left;\">SET A = 123<\/pre>\n<pre style=\"text-align: left;\">SET B = 123<\/pre>\n<pre style=\"text-align: left;\">A &gt;= B = TRUE<\/pre>\n<p style=\"text-align: left;\">And:<\/p>\n<pre style=\"text-align: left;\">SET A = 124<\/pre>\n<pre style=\"text-align: left;\">SET B = 123<\/pre>\n<pre style=\"text-align: left;\">A &gt;= B = TRUE<\/pre>\n<h4 style=\"text-align: left;\">Less Than Or Equal To (&lt;=)<\/h4>\n<p style=\"text-align: left;\">The &lt;= operator determines if the first expression is less-than or equal to the second expression. Example:<\/p>\n<pre style=\"text-align: left;\">SET A = 123<\/pre>\n<pre style=\"text-align: left;\">SET B = 123<\/pre>\n<pre style=\"text-align: left;\">A &lt;= B = TRUE<\/pre>\n<p style=\"text-align: left;\">And:<\/p>\n<pre style=\"text-align: left;\">SET A = 123 SET B = 124 A &lt;= B = TRUE<\/pre>\n<h4 style=\"text-align: left;\">Not Equal (&lt;&gt;or !=)<\/h4>\n<p style=\"text-align: left;\">Both the != and the &lt;&gt; inequality operators determine if the first expression is not equal to the second expression. Example:<\/p>\n<pre style=\"text-align: left;\">SET A = 123<\/pre>\n<pre style=\"text-align: left;\">SET B = 124<\/pre>\n<pre style=\"text-align: left;\">A = B = TRUE<\/pre>\n<h4 style=\"text-align: left;\">AND<\/h4>\n<p style=\"text-align: left;\">The AND operator is used to perform a logical conjunction on two expressions, where the expressions are Null, or are of Boolean subtype and have a value of True or False. The AND operator can also be used a bitwise operator to make a bit-by-bit comparison of two integers. If both bits in the comparison are 1, then a 1 is returned. Otherwise, a 0 is returned. When using the AND to compare Boolean expressions, the order of the expressions is not important. Example:<\/p>\n<pre style=\"text-align: left;\">(TRUE = TRUE AND FALSE = FALSE) = TRUE<\/pre>\n<p style=\"text-align: left;\">And:<\/p>\n<pre style=\"text-align: left;\">(TRUE = TRUE AND FALSE = TRUE) = FALSE<\/pre>\n<h4 style=\"text-align: left;\">OR<\/h4>\n<p style=\"text-align: left;\">The OR operator is used to perform a logical disjunction on two expressions, where the expressions are Null, or are of Boolean subtype and have a value of True or False.<\/p>\n<p style=\"text-align: left;\">The OR operator can also be used a &#8220;bitwise operator&#8221; to make a bit-by-bit comparison of two integers. If one or both bits in the comparison are 1, then a 1 is returned. Otherwise, a 0 is returned.<\/p>\n<p style=\"text-align: left;\">When using the OR to compare Boolean expressions, the order of the expressions is important.<\/p>\n<p style=\"text-align: left;\">Example:<\/p>\n<pre style=\"text-align: left;\">(TRUE = TRUE OR TRUE = FALSE) = TRUE<\/pre>\n<p style=\"text-align: left;\">And:<\/p>\n<pre style=\"text-align: left;\">(FALSE = TRUE OR TRUE = FALSE) = FALSE<\/pre>\n<h4 style=\"text-align: left;\">XOR<\/h4>\n<p style=\"text-align: left;\">The XOR operator is used to perform a logical exclusion on two expressions, where the expressions are Null, or are of Boolean subtype and have a value of &#8220;True&#8221; or &#8220;False&#8221;.<\/p>\n<p style=\"text-align: left;\">The XOR operator can also be used a &#8220;bitwise operator&#8221; to make a bit-by-bit comparison of two integers. If both bits are the same in the comparison (both are 0&#8217;s or 1&#8217;s), then a 0 is returned. Otherwise, 1 is returned.<\/p>\n<p style=\"text-align: left;\">Example:<\/p>\n<pre style=\"text-align: left;\">(TRUE XOR FALSE) = TRUE<\/pre>\n<p style=\"text-align: left;\">And:<\/p>\n<pre style=\"text-align: left;\">(FALSE XOR FALSE) = FALSE<\/pre>\n<h4 style=\"text-align: left;\">NOT<\/h4>\n<p style=\"text-align: left;\">The NOT operator is used to perform a logical negation on an expression. The expression must be of Boolean subtype and have a value of True or False. This operator causes a True expression to become False, and a False expression to become True.<\/p>\n<p style=\"text-align: left;\">Example:<\/p>\n<pre style=\"text-align: left;\">NOT (TRUE = FALSE) = TRUE<\/pre>\n<p style=\"text-align: left;\">And:<\/p>\n<pre style=\"text-align: left;\">NOT (TRUE = TRUE) = FALSE<\/pre>\n<h4 style=\"text-align: left;\">EQV<\/h4>\n<p style=\"text-align: left;\">The EQV operator is used to perform a logical comparison on two expressions (I.e., are the two expressions identical), where the expressions are Null, or are of Boolean subtype and have a value of True or False.<\/p>\n<p style=\"text-align: left;\">The EQV operator can also be used a &#8220;bitwise operator&#8221; to make a bit-by-bit comparison of two integers. If both bits in the comparison are the same (both are 0&#8217;s or 1&#8217;s), then a 1 is returned. Otherwise, 0 is returned.<\/p>\n<p style=\"text-align: left;\">The order of the expressions in the comparison is not important.<\/p>\n<p style=\"text-align: left;\">Example:<\/p>\n<pre style=\"text-align: left;\">TRUE EQV TRUE = TRUE<\/pre>\n<p style=\"text-align: left;\">And:<\/p>\n<pre style=\"text-align: left;\">TRUE EQV FALSE = FALSE<\/pre>\n<h4 style=\"text-align: left;\">MOD<\/h4>\n<p style=\"text-align: left;\">The MOD operator divides two numbers and returns the remainder. In the example below, 5 divides into 21, 4 times with a remainder of 1.<\/p>\n<p style=\"text-align: left;\">Example:<\/p>\n<pre style=\"text-align: left;\">21 MOD 5 = 1<\/pre>\n<p style=\"text-align: left;\">Happy Trading.<\/p>\n<p>&lt;<\/p>\n<p>p style=&#8221;text-align: left;&#8221;>This blog is an antecedent to the Trading Systems blog which is continued <a href=\"https:\/\/zerodha.com\/z-connect\/blog\/view\/algoz-trading-systems\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Beginners, don&#8217;t worry if you don&#8217;t understand when you read this manual. We will explain how to code your technical analysis strategy in the &#8220;Code your strategy&#8221; section. Technical Analysis NEST Pulse provides many built-in Technical Analysis functions. Using only a single line of code you can calculate functions such as Moving Averages, Bollinger Bands, [&hellip;]<\/p>\n","protected":false},"author":176551,"featured_media":1760,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[531],"tags":[186],"class_list":["post-103","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-general","tag-algoz"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v23.5 (Yoast SEO v26.6) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Coding Technical Analysis Functions &#8211; Z-Connect by Zerodha<\/title>\n<meta name=\"description\" content=\"Beginners, don&#039;t worry if you don&#039;t understand when you read this manual. We will explain how to code your technical analysis strategy in the &quot;Code your\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Coding Technical Analysis Functions\" \/>\n<meta property=\"og:description\" content=\"Beginners, don&#039;t worry if you don&#039;t understand when you read this manual. We will explain how to code your technical analysis strategy in the &quot;Code your\" \/>\n<meta property=\"og:url\" content=\"https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis\" \/>\n<meta property=\"og:site_name\" content=\"Z-Connect by Zerodha\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/zerodha.social\" \/>\n<meta property=\"article:author\" content=\"https:\/\/facebook.com\/zerodha.social\" \/>\n<meta property=\"article:published_time\" content=\"2013-04-23T12:17:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-26T11:58:05+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/zerodha.com\/z-connect\/wp-content\/uploads\/2013\/04\/coding-technical-analysis.png\" \/>\n\t<meta property=\"og:image:width\" content=\"708\" \/>\n\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Team Zerodha\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@zerodhaonline\" \/>\n<meta name=\"twitter:site\" content=\"@zerodhaonline\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Team Zerodha\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis\",\"url\":\"https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis\",\"name\":\"Coding Technical Analysis Functions &#8211; Z-Connect by Zerodha\",\"isPartOf\":{\"@id\":\"https:\/\/zerodha.com\/z-connect\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis#primaryimage\"},\"image\":{\"@id\":\"https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis#primaryimage\"},\"thumbnailUrl\":\"https:\/\/zerodha.com\/z-connect\/wp-content\/uploads\/2013\/04\/coding-technical-analysis.png\",\"datePublished\":\"2013-04-23T12:17:00+00:00\",\"dateModified\":\"2026-02-26T11:58:05+00:00\",\"author\":{\"@id\":\"https:\/\/zerodha.com\/z-connect\/#\/schema\/person\/ab459269e8365cddd9d34c1885428210\"},\"description\":\"Beginners, don't worry if you don't understand when you read this manual. We will explain how to code your technical analysis strategy in the \\\"Code your\",\"breadcrumb\":{\"@id\":\"https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis#primaryimage\",\"url\":\"https:\/\/zerodha.com\/z-connect\/wp-content\/uploads\/2013\/04\/coding-technical-analysis.png\",\"contentUrl\":\"https:\/\/zerodha.com\/z-connect\/wp-content\/uploads\/2013\/04\/coding-technical-analysis.png\",\"width\":708,\"height\":350},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/zerodha.com\/z-connect\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"General\",\"item\":\"https:\/\/zerodha.com\/z-connect\/category\/general\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Coding Technical Analysis Functions\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/zerodha.com\/z-connect\/#website\",\"url\":\"https:\/\/zerodha.com\/z-connect\/\",\"name\":\"Zerodha product and business updates\",\"description\":\"Z-Connect is Zerodha&#039;s official blog. Get the latest updates, product announcements news, and insights all in one place.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/zerodha.com\/z-connect\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/zerodha.com\/z-connect\/#\/schema\/person\/ab459269e8365cddd9d34c1885428210\",\"name\":\"Team Zerodha\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/zerodha.com\/z-connect\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/48197431b96187c109ad9cec95277dad5d96c853020ea2b0f26c675792bd17a5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/48197431b96187c109ad9cec95277dad5d96c853020ea2b0f26c675792bd17a5?s=96&d=mm&r=g\",\"caption\":\"Team Zerodha\"},\"description\":\"Simple and secure, no nonsense investing and trading.\",\"sameAs\":[\"https:\/\/facebook.com\/zerodha.social\",\"https:\/\/x.com\/zerodhaonline\"],\"url\":\"https:\/\/zerodha.com\/z-connect\/author\/team-zerodha\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Coding Technical Analysis Functions &#8211; Z-Connect by Zerodha","description":"Beginners, don't worry if you don't understand when you read this manual. We will explain how to code your technical analysis strategy in the \"Code your","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis","og_locale":"en_US","og_type":"article","og_title":"Coding Technical Analysis Functions","og_description":"Beginners, don't worry if you don't understand when you read this manual. We will explain how to code your technical analysis strategy in the \"Code your","og_url":"https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis","og_site_name":"Z-Connect by Zerodha","article_publisher":"https:\/\/www.facebook.com\/zerodha.social","article_author":"https:\/\/facebook.com\/zerodha.social","article_published_time":"2013-04-23T12:17:00+00:00","article_modified_time":"2026-02-26T11:58:05+00:00","og_image":[{"width":708,"height":350,"url":"http:\/\/zerodha.com\/z-connect\/wp-content\/uploads\/2013\/04\/coding-technical-analysis.png","type":"image\/png"}],"author":"Team Zerodha","twitter_card":"summary_large_image","twitter_creator":"@zerodhaonline","twitter_site":"@zerodhaonline","twitter_misc":{"Written by":"Team Zerodha","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis","url":"https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis","name":"Coding Technical Analysis Functions &#8211; Z-Connect by Zerodha","isPartOf":{"@id":"https:\/\/zerodha.com\/z-connect\/#website"},"primaryImageOfPage":{"@id":"https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis#primaryimage"},"image":{"@id":"https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis#primaryimage"},"thumbnailUrl":"https:\/\/zerodha.com\/z-connect\/wp-content\/uploads\/2013\/04\/coding-technical-analysis.png","datePublished":"2013-04-23T12:17:00+00:00","dateModified":"2026-02-26T11:58:05+00:00","author":{"@id":"https:\/\/zerodha.com\/z-connect\/#\/schema\/person\/ab459269e8365cddd9d34c1885428210"},"description":"Beginners, don't worry if you don't understand when you read this manual. We will explain how to code your technical analysis strategy in the \"Code your","breadcrumb":{"@id":"https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis#primaryimage","url":"https:\/\/zerodha.com\/z-connect\/wp-content\/uploads\/2013\/04\/coding-technical-analysis.png","contentUrl":"https:\/\/zerodha.com\/z-connect\/wp-content\/uploads\/2013\/04\/coding-technical-analysis.png","width":708,"height":350},{"@type":"BreadcrumbList","@id":"https:\/\/zerodha.com\/z-connect\/general\/algoz-technical-analysis#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/zerodha.com\/z-connect\/"},{"@type":"ListItem","position":2,"name":"General","item":"https:\/\/zerodha.com\/z-connect\/category\/general"},{"@type":"ListItem","position":3,"name":"Coding Technical Analysis Functions"}]},{"@type":"WebSite","@id":"https:\/\/zerodha.com\/z-connect\/#website","url":"https:\/\/zerodha.com\/z-connect\/","name":"Zerodha product and business updates","description":"Z-Connect is Zerodha&#039;s official blog. Get the latest updates, product announcements news, and insights all in one place.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/zerodha.com\/z-connect\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/zerodha.com\/z-connect\/#\/schema\/person\/ab459269e8365cddd9d34c1885428210","name":"Team Zerodha","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/zerodha.com\/z-connect\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/48197431b96187c109ad9cec95277dad5d96c853020ea2b0f26c675792bd17a5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/48197431b96187c109ad9cec95277dad5d96c853020ea2b0f26c675792bd17a5?s=96&d=mm&r=g","caption":"Team Zerodha"},"description":"Simple and secure, no nonsense investing and trading.","sameAs":["https:\/\/facebook.com\/zerodha.social","https:\/\/x.com\/zerodhaonline"],"url":"https:\/\/zerodha.com\/z-connect\/author\/team-zerodha"}]}},"jetpack_featured_media_url":"https:\/\/zerodha.com\/z-connect\/wp-content\/uploads\/2013\/04\/coding-technical-analysis.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/zerodha.com\/z-connect\/wp-json\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zerodha.com\/z-connect\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zerodha.com\/z-connect\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zerodha.com\/z-connect\/wp-json\/wp\/v2\/users\/176551"}],"replies":[{"embeddable":true,"href":"https:\/\/zerodha.com\/z-connect\/wp-json\/wp\/v2\/comments?post=103"}],"version-history":[{"count":35,"href":"https:\/\/zerodha.com\/z-connect\/wp-json\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":443272,"href":"https:\/\/zerodha.com\/z-connect\/wp-json\/wp\/v2\/posts\/103\/revisions\/443272"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/zerodha.com\/z-connect\/wp-json\/wp\/v2\/media\/1760"}],"wp:attachment":[{"href":"https:\/\/zerodha.com\/z-connect\/wp-json\/wp\/v2\/media?parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zerodha.com\/z-connect\/wp-json\/wp\/v2\/categories?post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zerodha.com\/z-connect\/wp-json\/wp\/v2\/tags?post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}