Up

Version 1.3 New Features

Protect Formulas Keltner Bands Commodity Channel Index Money Flow Index Previous Features
IF THEN Statements SnapShot or Chart Mini Quote Sheets

IF THEN STATEMENTS

Introduction

One of the most exciting new features we have added to the latest ErlangerQuote is the ability to perform IF THEN decisions. The following examples will help you see how that is done. The first example is presented to clarify how IF THEN works while the second is a more practical example. 

Note: If you would like to get this example running quickly you can download the Style sheet for the quote sheet containing the IF THEN example: ZIPPED IF THEN STYLE SHEET. Then make a new quote sheet, right click on it and Load the new Style sheet. This will apply all the columns that are in the example to your blank quote sheet. You will have to type in the symbols however the formulas will be intact and ready to read. To use them in other places, just save them with a name that helps you remember what they do.

Figure 4 The first  IF THEN example is in column C, the second example is in columns D and E.

Example 1. A Simple IF THEN 

Quote sheets in ErlangerQuote default to displaying True or False when the underlying result in the cell of the quote sheet is a logical equation. Thus if you put a statement like Ask>0 in a Formula column, the result will show True for every stock. However underneath the code the actual values are available. if the logic equation reduces to true the value 1 is created, and if the logic reduces to false the value 0 is created. We can use these values to help us make IF THEN decisions but to do that we need to disable the displaying of True and False and let the actual values come through. To accomplish this a new option was added to the menu called Override Alert Formatting, which is available if you click on a column and select Column->Override Alert Formatting.

 

In Figure 4 column C contains a formula that Ask if and only if the Ask is greater than 50. Its based on the formula:

 

( Ask > 50 ) * Ask

 

Add this formula to a quote sheet. (You can name the column (ask>50)*Ask so its easy to remember later. You can turn off the row lock under Quote Sheet->Grids->Lock Row Height, and then stretch it so the name shows up above the column.)

 

Now right click on the column you just made, and select Column->Override Alert Formatting. 

 

This will prevent the True False display and allow an actual value to be displayed.  

 

It will also allow the values True (1) and False (0) from the expression to be used in equations to simulate the decision IF THEN statement.

You can see from reducing our formula that when Ask is in fact above 50, the expression ( Ask > 50 ) is True. Since a True is a 1, you have the equation now reduced to:

( 1 x Ask ) = Ask

Note we used x to represent multiply but in the program its actually the asterisk character *. Therefore if Ask is greater than 50 the column displays Ask, since 1 times a number is that same number.

If on the other hand Ask is less than 50, the expression ( Ask > 50 ) is False. Since a False is a 1, you have the equation now reduced to 

( 0 x Ask ) = 0

Therefore if Ask is less than 50 the column displays 0, since 0 times a number is 0.

The way we put this to work to make it an IF THEN is through the incredible magical feature called multiplication. (Which we did not invent). 

We can use the resulting 0 or 1 with a multiply in a creative way. Since multiplying by 1 retains the initial value and multiplying by 0 makes the original value disappear it serves as a gate function, turning on and off the result we are looking for.

Therefore our simple statement is the same as:

IF Ask > 50 THEN Display Ask ELSE Display 0

In our example quote sheet you can see that only 2 of the 6 stocks have Ask's greater than 50 on the day we captured this screen.

Example 2. The "Bag Sag" IF THEN 

Take a look at columns D and E in Figure 4. This more complex example compares today's low to yesterday's low and tells which is lower, and at the same time, only display the low that is lowest. Thus if we see numbers in the rightmost column it means that today's low was lower than yesterday and if we see numbers in the leftmost column it means that yesterday's low was lower than today. I look at this as a story of which day has more lows, and thus which day "sags" the bottom of the bag the most. At the time we snapped the quote sheet in Figure 1 Microsoft had just announced it would miss earnings for the first time in 10 years, and so everything tech dropped. Logically the values in the today's column are showing up while the there are very few numbers in the yesterday column. So the bag is sagging today more than yesterday (which we would expect). And the only stock that is not lower today is a biotech stock.

We set this IF THEN system up with two columns:

Column D compares the low of today with the low of yesterday. If today's low is greater than yesterdays low's, then yesterday was the lower of the two lows, and its value is displayed, otherwise it displays 0. The formula is:

( Low(D,0) > Low(D,-1) ) x Low(D,-1 )

Column E holds the inverse formula, in this case the low of today must be lower than the low of yesterday to display its value. The formula is:

( Low(D,0) < Low(D,-1) ) x Low(D)

The result is that values in the column on the left are showing that yesterday they hit a lower low while values in the column on the right means those stocks have hit a lower low today compared to yesterday. 

In Figure 5 you can see the the 60 minute chart for AOL. The lines represent the low for day of the 14th and the 15th of December 2000. As you can see AOL was lower on the 15th than the 14th. In the quote sheet in Figure 1 you can see that in the row for AOL, the column called "today low" has the low price of AOL displayed. The column to the left called "yest low" is empty. This proves the formula is working, as we are only displaying the lowest of the two lows.

Figure 5 AOL gives a visual comparison of the lows of today and yesterday.

Example 3. Graphing with the IF THEN in a Formula Study

You can use the IF THEN feature to make some interesting Formula Studies on charts. In Figure 6 below you can see the results of plotting the formula on the chart:

( Low(D,0) < Low(D,-1) ) x Low(D)

We start by right clicking on the chart and selecting Formula Studies, which brings up the Formula Study Dialog. Enter the formula in the area for the formula, and be sure and add a check to the new check box "Don't Plot Zero Values". Set the type of plot to Square Line Chart. Then check ON Show Name Labels, Show Data Line, and Show Markers. Set the Line color to something that will stand out on your backgrounds, and set the thickness to the 2nd selection in the drop down menu. Be sure and save the formula with a name like "today low".

The horizontal lines in this study represent the times when the low of the current day is less than the low of the previous day. The line stays horizontal until another event where the low of today is less than the low of previous day. That might not occur for sometime, as the period from Dec 4 to 6 shows.