# Tutorial 47 – Adding a new data element to an EasyLanguage array

Welcome to tutorial 47 in this series of tutorials designed to teach EasyLanguage coding skills.

For some reason, it seems that a lot of people I speak to are somewhat wary of using arrays. I think the perception is that they are difficult or complicated. They may take a little getting used to, but a one dimensional array is really like a variable that can store several values at the same time. Each variable within the array is referenced by a number.

When you do start using arrays you will quickly realize that you are either limited by the array size, or you artificially limit the size of the array to make your program run faster. In doing so you may find that you need to somehow, add new data to the array – and delete the oldest, without overwriting data that you actually need.

This tutorial introduces two methods of how to achieve this.

Please join our email mailing list if you have not already done so and we will let you know when we release new tutorials or programs.

## Sort the array every time there is a new entry

In the first method we literally ‘step’ the array every time we need to add a new value to the array. In the example included in the video (which is ten element array) this means that every time we need to add a new entry to the array we copy the contents of the ninth elemnt into the tenth element, the contents of the eigth elemnt into the ninth element, the contents of the eighth element into the ninth element and so on. Finally we put the new data into the first element.

Imagine a ladder with something on every step. The oldest information is on the top step and the newest on the bottom step. To add a new piece of data to the bottom step we need to move all the other information up one step first. The information stored on the top step will disappear in the process. Once all the information has been moved up a step, the new information can be added to the bottom step.

In actual fact the array could also store values in the zero element, but we are ignoring this because:

• I think it makes it a little easier to understand
• The Tradestation array sorting functions do not utilize the zero element.

This method works fine, and everything is kept in the correct order, i.e. the most recent entries are in the earlier array locations (i.e. the most recent data is in the array location number 1, and so on). The problem is, the program is doing a lot of processing by having to sort the array avery time a new piece of data needs to be added. This issue may be exacerbated when sorting very large two dimensional array frequently.

The video below demonstrates this method.

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.

## Tutorial 47 Video 2 – Use an ‘index’ method to ‘slot’ new values into the array without sorting

Another method, described in the video below, is to make use of an ‘index’ value. This value is inremented every time a new value that needs to be stored in the array is found, however when it reached a maximum value it is reset to one. Each time, the new value is slotted into the array at the location indicated by the ‘index’ value. I describe this in the video below.

The advantage of this method is that it is more efficient.

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

EasyLanguage is a programming language that is part of the TradeStation trading platform. It can be used to write programs to help in the technical analysis and trading of foreign exchange (forex or FX), commodities (e.g. the Dow e-mini, S&P e-mini etc), options, and stocks.