Tutorial 19 – A new volume indicator

Welcometo tutorial 19 in this series of tutorials that demonstrate and explain TradeStation EasyLanguage programming concepts. The idea behind the series is that if you learn the TradeStation EasyLanguage yourself, you will have a skill that will enable you to program and try out trading ideas without the need to use a professional programmer.

As always, the purpose of this tutorial is to demonstrate the programming techniques rather than to create a tradable indicator. This tutorial was created using TradeStation version 8.3. In general I do not update to the latest version of TradeStation at the earliest opportunity, since it takes a little time for bugs to be worked out.

TO THE BEST OF MARKPLEX CORPORATION’S KNOWLEDGE, ALL OF THE INFORMATION ON THIS PAGE IS CORRECT, AND IT IS PROVIDED IN THE HOPE THAT IT WILL BE USEFUL. HOWEVER, MARKPLEX CORPORATION ASSUMES NO LIABILITY FOR ANY DAMAGES, DIRECT OR OTHERWISE, RESULTING FROM THE USE OF THIS INFORMATION AND/OR PROGRAM(S) DESCRIBED, AND NO WARRANTY IS MADE REGARDING ITS ACCURACY OR COMPLETENESS. USE OF THIS INFORMATION AND/OR PROGRAMS DESCRIBED IS AT YOUR OWN RISK.

ANY EASYLANGUAGE OR POWERLANGUAGE TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS (AND PARTS THEREOF) AND ASSOCIATED TECHNIQUES REFERRED TO, INCLUDED IN OR ATTACHED TO THIS TUTORIAL OR PROGRAM DESCRIPTION ARE EXAMPLES ONLY, AND HAVE BEEN INCLUDED SOLELY FOR EDUCATIONAL PURPOSES. MARKPLEX CORPORATION. DOES NOT RECOMMEND THAT YOU USE ANY SUCH TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS (OR ANY PARTS THEREOF) OR TECHNIQUES. THE USE OF ANY SUCH TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS AND TECHNIQUES DOES NOT GUARANTEE THAT YOU WILL MAKE PROFITS, INCREASE PROFITS, OR MINIMIZE LOSSES.

I recently read an article in Stocks, Futures and Options magazine about a technical trading methodology that utilized volume to try and understand when tops or bottoms of the market may occur.

Often traders will create a plot on a chart by applying a Volume Indicator and an average volume indicator.

In the following chart I added the Vol Avg indicator (click Insert – Indicator and scroll down until you find Vol – Avg). The chart will look something like this:

Volume chart from Tradestation

The chart shows volume (the red and cyan vertical bars below the chart) and an average of the volume (the yellow line). Incidentally, the symbol settings allow two options for volume (see below). They are Trade Vol and Tick Count. The meanings of these terms vary depending on the timescale of the chart you are using. For an ‘intraday chart, ‘ i.e. a 1, 5 or 60 minute etc chart, if the ‘For volume use’ is set to ‘Trad Vol’ then the volume shown is ‘up volume’ (or volume that occurs on an uptick). If it is set to ‘Tick Count’ then volume is shown as ‘up ticks.’ You can find a good write up of all the different volume settings depending on chart type and what they mean at //tradestion.com/wiki. You will need to log in to your account to access the information.

Volume options

This gave me the idea that while the technique I read about may be useful, it is calculating volume based on parts of the day that you may not be interested in. For example, say you wanted to create a strategy or indicator that focused on the volumes that occurred between 11:00 and 12:00 and JUST between those times of day. So, for example, say you were using a 10 minute chart and you wanted to find the 30 bar average JUST between 11:00 and 12:00. Imagine it is now 1:00 p.m. then the program would need to average the volume for the bars between 11:00 and 12:00 today (6 bars on a 10 minute chart), 11:00 and 12:00 the previous day (6 bars), 11:00 and 12:00 the day before that (6 bars) and so on until we were calculating the average volume of 30 bars.

CAUTION: For the technique described below you need to make sure that the MaxBarsBack setting is high enough. More about this below.

Step 1 – Create a new function

We will name the function we are creating _AVtweenTimes and we will pass four inputs to the function:

  • StartTime
  • EndTime
  • Value to be passed (I have spoken about using this function to calculate volume averages, but it could also be used to find the average of price series
  • Length

A call to the function will look like:

_AVtweenTimes(1154,1210,V,20)

Where 1154 is the start time, 1210 is the end time, V (or volume) is what th eprogram will calculate the average of and 20 is the length of the average.

Tradestation provides a lot of useful functions and other Easylanguage programs and it is often instructive to open the programs and see how Tradestation programmed them. A good example is the Average function. If you open it you will see that it calls another function which sums the value of a specific attribute of a number of previous bars depending on the value of the length input. Opening the Summation function reveals how this is achieved.

The function uses a ‘for’ construct to count backwards the last ‘length’ bars (including the current bar) and calculates their sum.

For Value1 = 0 to Length – 1
Begin
Sum = Sum + Price[Value1] ;
End ;

Our function will behave similarly, but with several significant differences. So let’s get started…..

Create a new function named _AVtweenTimes (click File – New- Window, select the EasyLanguage tab and click Function.) Make sure the return type is Double Numeric).

Enter the following code:

New volume calculation function

Press F3 to verify the code and correct any typos.

The program works as follows:

  1. It starts looking backwards, testing whether the time of each bar falls between the StartTime and the EndTime. If it does, it adds its value to the Sum variable and increments the Counter variable. If not, it keeps looking backwards until it finds a time within the time range.
  2. If a bar is not within the time constraints, the program increments the Counter2 variable.
  3. All the variables are set to zero after the result is passed back to the indicator.

I have added some comments to the program to help in its understanding.

Step 2 – Create a test indicator to access the function

Create a new indicator (click File – New- Window, select the EasyLanguage tab and click Indicator) and enter the following code:

Plot1(_AVtweenTimes(1154,1210,V,20),”test”,cyan);
Plot2(V,”-v”,blue);

Step 3 – Apply to Chart

Open and new chart and apply the indicator (Insert – Indicator, select the indicator that you just created and MAKE SURE that the Prompt for Format check box is selected.

You will then see the following screen:

Max bars back settings

I added the blue oval to highlight the Maximum Number of Bars Study will Reference or MaxBarsBack settings. As I mentioned above, for this function to work correctly it is imperative that the MaxBarsBack is set correctly. To calculate what the setting should be, divide the Length setting that you are using by the number of bars between the StartTime and the EndTime. Multiply the result by the number of bars per day. MaxBarsBack controls the number of bars that need to be on the chart before an indicator or strategy starts to calculate.

Once applied the chart should look like this:

Volume indicator applied to chart

The cyan line shows the indicator just created and the blue line is a plot of volume. Notice how the cyan line changes during the time period that we specified and then stays horizontal.

TO THE BEST OF MARKPLEX CORPORATION’S KNOWLEDGE, ALL OF THE INFORMATION ON THIS PAGE IS CORRECT, AND IT IS PROVIDED IN THE HOPE THAT IT WILL BE USEFUL. HOWEVER, MARKPLEX CORPORATION ASSUMES NO LIABILITY FOR ANY DAMAGES, DIRECT OR OTHERWISE, RESULTING FROM THE USE OF THIS INFORMATION AND/OR PROGRAM(S) DESCRIBED, AND NO WARRANTY IS MADE REGARDING ITS ACCURACY OR COMPLETENESS. USE OF THIS INFORMATION AND/OR PROGRAMS DESCRIBED IS AT YOUR OWN RISK.

ANY EASYLANGUAGE OR POWERLANGUAGE TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS (AND PARTS THEREOF) AND ASSOCIATED TECHNIQUES REFERRED TO, INCLUDED IN OR ATTACHED TO THIS TUTORIAL OR PROGRAM DESCRIPTION ARE EXAMPLES ONLY, AND HAVE BEEN INCLUDED SOLELY FOR EDUCATIONAL PURPOSES. MARKPLEX CORPORATION. DOES NOT RECOMMEND THAT YOU USE ANY SUCH TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS (OR ANY PARTS THEREOF) OR TECHNIQUES. THE USE OF ANY SUCH TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS AND TECHNIQUES DOES NOT GUARANTEE THAT YOU WILL MAKE PROFITS, INCREASE PROFITS, OR MINIMIZE LOSSES.

If you see any errors in this tutorial – or I have not made something clear, I would be most grateful if you could please let me know. You can e-mail me at: tutorials@markplex.com. Also, let me know if you have any ideas for new tutorials.

Disclaimer The information, materials, products and services on this Web site are made available subject to the following terms and conditions. Markplex Corporation reserves the right to change these terms and conditions at its sole discretion. This Web site and any downloads, videos, tutorials, programs and information contained herein is presented solely for educational, informational, and/or entertainment use and under no circumstances should be used for actual trading. We at Markplex Corporation are not Broker/Dealers, Financial Advisers or Registered Analysts. No offer or solicitation to buy or sell securities, securities derivatives, futures products or off-exchange foreign currency (forex) transactions of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given or in any manner endorsed by Markplex Corporation. You are fully responsible for any investment or trading decisions you make. Futures and options trading has a large potential risk. You must be aware of the risks and be willing to accept them in order to invest in the futures and options markets. This Web site is neither a solicitation nor an offer to buy and/or sell futures or options. No representation is being made that any account will or is likely to achieve profits or losses similar to those discussed on this Web site. Past performance, whether actual or indicated by historical tests of strategies, is no guarantee of future performance or success. No warranties of profitability are being made or given. There is a possibility that you may sustain a loss equal to or greater than your entire investment regardless of which asset class you trade (equities, options futures or forex); therefore, you should not invest or risk money that you cannot afford to lose. CFTC RULE 4.41 - Hypothetical or simulated performance results have certain inherent limitations. Unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not actually been executed, the results may have under- or over-compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profits or losses similar to those shown. Screen shots on this site are examples and are not meant to imply that any of the programs or tutorials available on this Web site will generate profitable trades. EasyLanguage or PowerLanguage trading strategies, signals, studies, indicators, showme studies, paintbar studies, probabilitymap studies, activitybar studies, functions (and parts thereof) and associated techniques referred to, included in or attached to this tutorial or program description are examples only, and have been included solely for educational, informational, and entertainment use. Markplex Corporation does not recommend that you use any such trading strategies, signals, studies, indicators, showme studies, paintbar studies, probabilitymap studies, activitybar studies, functions (or any parts thereof) or techniques. The use of any such trading strategies, signals, studies, indicators, showme studies, paintbar studies, probabilitymap studies, activitybar studies, functions and techniques does not guarantee that you will make profits, increase profits, or minimize losses. Markplex Corporation assumes no liability for any damages, direct or otherwise, resulting from the use of this information and/or program(s) described, and no warranty is made regarding its accuracy or completeness. Use of this Web site including the information, tutorials and/or programs included on it is at your own risk. You shall indemnify and hold Markplex Corporation harmless from any and all liability, loss, trading losses, costs, damage, or expense, including attorneys' fees you or third party may suffer (other than damage to your tangible property or injuries to employees occurring during the course of work) as a result of claims, demands, costs, or judgments arising out of third party and any other claims based on Markplex Corporation's performance, including, but not limited to losses resulting from the use of Markplex Corporation developed software, programs, web sites, tutorials, or the TradeStation charting and/or trading platform. Any testimonials on this Web site may not be representative of the experience of other clients and are not indicative of future results or success.
This Web site contains or may contain references and links to other companies and/or their Web sites, none of which is under the control of Markplex Corporation. Markplex Corporation makes no representations, warranties or endorsements whatsoever about any other Web sites to which you may have access through the Markplex Corporation Web site, or any products or services of those other companies, even if the products or services of those other companies or their Web sites are described or offered on the Markplex Corporation Web site or integrated with Markplex Corporation's products or services. TradeStation®, EasyLanguage® and PowerEditor® are registered trademarks of TradeStation Technologies, Inc. Other brand and product names which appear on this site are the trademarks or service marks of their respective owners, including: Microsoft® is a registered trademark in the United States Microsoft®Excel® is a registered trademark of Microsoft® Neither TradeStation Technologies nor any of its affiliates has reviewed, certified, endorsed, approved, disapproved or recommended, and neither does or will review, certify, endorse, approve, disapprove or recommend, any product or service that offers training, education or consulting regarding the use of EasyLanguage.

By continuing to use and navigate our sites, services, applications, tools or messaging, you are agreeing to our Terms and Conditions and the use of cookies, web beacons and similar technologies as described in our Privacy Policy and Privacy Policy on the use of cookies.