A reader of this blog proffered an excellent question on this indicator. I hope this post answers his question and I am always open to any input that might improve my coding!
Because I use BarNumber in my MODULUS calculation the different time frames that I keep track of may not align with the time frames on the chart; your 10-minute bar O, H, L, and C values may not align with the values I am storing in my 10-minute bar container. Take a look at this snapshot of a spreadsheet.
Here I print out a 5-minute bar of the ES.D. Because I use BarNumber in my Modulus calculation, I don’t get to a zero remainder until 9:50 in the 10, 15, and 20 minute time frames. At 9:50 I start building fresh 10, 15, 20 minute bars by resetting the O, H, L and C to those of the 5-minute bars. From there I keep track of the highest highs and lowest lows by extracting the data from the 5-minute bar. I always set the close of the different time frames to the current 5-minute bar’s close. Once the modulus for the different time frames reaches zero I close out the bar and start fresh again. The 25-minute bar didn’t reach zero until the 10:05 bar.
I will see if I can come up with some code that will sync with the data on the chart.
In this post, I want to share some code that I was surprised wasn’t really all that accessible. I was in need of passing a 2-D array to a function and couldn’t remember the exact syntax. The semantics of the problem is pretty straightforward.
Build Array
Pass Array as Reference
Unpack Array
Do Calculation
A 2D Array Is Just Like a Table
Any readers please correct me if I am wrong here, but you can’t use dynamic arrays on any dimension greater than 1. A dynamic array is one where you don’t initially know the size of the array so you leave it blank and TradeStation allocates memory dynamically. Also, there are a plethora of built-in functions that only work with dynamic arrays. Once we step up in dimension then that all goes out the window. I know what you are thinking, just use multiple dynamic arrays. Sometimes you want to keep the accounting down to a minimum and a matrix or table fits this bill. So if you do use multi-dimension arrays just remember you will need to know the total number of rows and columns in your table. Table? What do you mean table? I thought we were talking about arrays. Well, we are and a two-dimensional array can look like a table with rows as your first index and columns as your second. Just like an Excel spreadsheet. First, let’s create a very small and simple table in EasyLangauge:
array: testArray[2,2](0);
Once begin testArray[0,0] = 100; testArray[0,1] = 5;
You will notice I used the keyword Once. I use this whenever I want to play around with some code in my EasyLanguage Sandbox. Huh? In programmer-ese a Sandbox is a quick and dirty environment that runs very quickly and requires nearly zero overhead. So here I apply the code to print out just one line of output when applied to any chart. Notice how I declare the 2-D array – use the keyword Array: and the name of the array or table and allocate the total number of rows as the first argument and the total number of columns as the second argument. Also notice the arguments are separated by a comma and enclosed in square brackets. The following value enclosed in parentheses is the default value of every element in the array. Remember arrays are zero-based in EasyLanguage. So if you dimension an array with the number 2 you access the rows with 0 and 1 and 2. Same goes for columns as well. Did you catch that. If you dimension an array with the number 2 shouldn’t there be just 2 rows? Well in EasyLanguage when you dimension an array you get a free element at row 0 and column 0. In EasyLanguage you can just ignore row 0 and column 0 if you like. Here is the code if you ignore row 0 and column 0.
Should I Use Row 0 and Column Zero – It’s A Preference
array: testArray[2,2](0);
Once begin testArray[1,1] = 100; testArray[1,2] = 5;
Even though you get one free row you still cannot go beyond the boundaries of the array size. If I were to say something like:
testArray[3,1] = 300;
I would get an error message. If you want to work with a zero element then all of your code must coincide with that. If not, then your code shouldn’t try to access row 0 or column 0. Okay here is the function that I programmed for this little test:
For j= 1 to numOfRows Begin print(j," ",tempArray[j,whichColumn]); If tempArray[j,whichColumn] > tempHi then tempHi = tempArray[j,whichColumn]; end;
GetArrayHH = tempHi;
Function That Utilizes a 2D Array
Notice in the inputs how I declare the tempArray with the values x and y. You could have used a and b if you like or any other letters. This informs the compiler to expect a 2D array. It doesn’t know the size and that’s not important as long as you control the boundaries from the calling routine. The second parameter is the number of rows in the table and the third parameter is the column I am interested in. In this example, I am interested in column 2.
The Caller Function is the QuarterBack – Make Sure You Don’t Throw it Out of Bounds
Again this function assumes the caller will prevent stepping out of bounds. I loop the number of rows in the table and examine the second column and keep track of the highest value. I then return the highest column value.
This was a simple post, but remembering the syntax can be tough and know that EasyLangauge is zero-based when it comes to arrays is nice to know. You can also use this format for your own Sandbox.
Backtesting with [Trade Station,Python,AmiBroker, Excel]. Intended for informational and educational purposes only!
Get All Five Books in the Easing Into EasyLanguage Series - The Trend Following Edition is now Available!
Announcement – A Trend Following edition has been added to my Easing into EasyLanguage Series! This edition will be the fifth and final installment and will utilize concepts discussed in the Foundation editions. I will pay respect to the legends of Trend Following by replicating the essence of their algorithms. Learn about the most prominent form of algorithmic trading. But get geared up for it by reading the first four editions in the series now. Get your favorite QUANT the books they need!
This series includes five editions that covers the full spectrum of the EasyLanguage programming language. Fully compliant with TradeStation and mostly compliant with MultiCharts. Start out with the Foundation Edition. It is designed for the new user of EasyLanguage or for those you would like to have a refresher course. There are 13 tutorials ranging from creating Strategies to PaintBars. Learn how to create your own functions or apply stops and profit objectives. Ever wanted to know how to find an inside day that is also a Narrow Range 7 (NR7?) Now you can, and the best part is you get over 4 HOURS OF VIDEO INSTRUCTION – one for each tutorial.
This book is ideal for those who have completed the Foundation Edition or have some experience with EasyLanguage, especially if you’re ready to take your programming skills to the next level. The Hi-Res Edition is designed for programmers who want to build intraday trading systems, incorporating trade management techniques like profit targets and stop losses. This edition bridges the gap between daily and intraday bar programming, making it easier to handle challenges like tracking the sequence of high and low prices within the trading day. Plus, enjoy 5 hours of video instruction to guide you through each tutorial.
The Advanced Topics Edition delves into essential programming concepts within EasyLanguage, offering a focused approach to complex topics. This book covers arrays and fixed-length buffers, including methods for element management, extraction, and sorting. Explore finite state machines using the switch-case construct, text graphic manipulation to retrieve precise X and Y coordinates, and gain insights into seasonality with the Ruggiero/Barna Universal Seasonal and Sheldon Knight Seasonal methods. Additionally, learn to build EasyLanguage projects, integrate fundamental data like Commitment of Traders, and create multi-timeframe indicators for comprehensive analysis.
The Day Trading Edition complements the other books in the series, diving into the popular approach of day trading, where overnight risk is avoided (though daytime risk still applies!). Programming on high-resolution data, such as five- or one-minute bars, can be challenging, and this book provides guidance without claiming to be a “Holy Grail.” It’s not for ultra-high-frequency trading but rather for those interested in techniques like volatility-based breakouts, pyramiding, scaling out, and zone-based trading. Ideal for readers of the Foundation and Hi-Res editions or those with EasyLanguage experience, this book offers insights into algorithms that shaped the day trading industry.
For thirty-one years as the Director of Research at Futures Truth Magazine, I had the privilege of collaborating with renowned experts in technical analysis, including Fitschen, Stuckey, Ruggiero, Fox, and Waite. I gained invaluable insights as I watched their trend-following methods reach impressive peaks, face sharp declines, and ultimately rebound. From late 2014 to early 2020, I witnessed a dramatic downturn across the trend-following industry. Iconic systems like Aberration, CatScan, Andromeda, and Super Turtle—once thriving on robust trends of the 1990s through early 2010s—began to falter long before the pandemic. Since 2020 we have seen the familiar trends return. Get six hours of video instruction with this edition.
Pick up your copies today – e-Book or paperback format – at Amazon.com