Best Month to Trade (Uses Parallel Lists) (Point-and-Click TradeStation® Strategy)
Original Trading Strategy
Links to the section of the video titled “Using & Customizing the Built-In Strategies in Quagensia T Edition” in which this built-in strategy is covered.
This advanced tutorial on lists and loops was made for Quagensia N Edition, but can be followed almost word-for-word in Quagensia T Edition as well.
Peer Reviews, Modifications & Responses
Thanks for Sharing!
Trading Strategy Summary
This Quagensia Strategy uses the power of lists to create a report with 12 rows of data, one for each month of the year. The first column is the number of the month of the year, where January is 1 and December is 12. The second and third columns are the arithmetic and geometric means of the percentage differences between the open and close prices of all the price bars occurring in that month. The last column is the number of price bars that were included in that month’s results.
Run this report on monthly bars, weekly bars, daily bars, 24-hour bars, or intraday bars for any instrument you want to learn more about before placing any trades on that instrument.
Setting the bar period to “Monthly” creates a report of the average price change percentages from the open price of the first trading day of the month to the close price of the last trading day of the month. When run on monthly bars, this report is intended to answer the question “Historically speaking, what have been the best and worst months of the year to hold a long position for a given instrument?”
Setting the bar period to “Daily” creates a report of the average price change percentages of the daily bars in each month, from the open price of each trading day to the close price of the trading day. When run on daily bars, this report is intended to answer the question “Historically speaking, what have been the best and worst months of the year to enter long positions at the beginning of the day and exit at the end of the day for a given instrument?”
Setting the bar period to any other period that is more frequent than “Monthly”, such as weekly bars, “2-Day Bars”, or “15-Minute Bars”, works similar to the way the report works on daily bars. Note that it is the month of the end time of a bar that is used in this report, so a weekly bar that starts in January and ends in February will be included in the February totals.
When run as-is, without customizations, this report includes every price bar in its results. However, this report can be easily customized without code. You can easily plug in your own conditions for which price bars should be included in and excluded from the results.
To customize this report without code, scroll down to the yellow “comment” that starts with the following message and follow its instructions:
”
********************************************************************
********************************************************************
Attention paid users
********************************************************************
********************************************************************
”
This strategy outputs a report when it is applied to a chart in TradeStation®.
It does not place trades.
It is meant to be run as a backtest only, not in a live trading environment.
If you will only be running this report as-is, i.e. if you will not be changing the criteria for what price bars will be included in the results, the value in the “Maximum number of bars study will reference” field in TradeStation®’s “Strategy Properties for All Strategies on this Chart” window can be as low as 0, since by default this report considers only the current price bar. To open the “Strategy Properties for All Strategies on this Chart” window from the TradeStation® user interface, click on the “Properties for All…” button in the “Customize Studies & Strategies” window, which is the window that shows the list of strategies being applied to the chart or about to be applied to the chart which opens whenever you add or edit a TradeStation® strategy. If you will be running this report with your own criteria for what price bars will be included in the results, the value in the “Maximum number of bars study will reference” field will likely have to be larger to account for things like a 10-period simple moving average needing at least 10 price bars of initial data before it can provide a valid result for a given price bar. The larger you make this number, the less likely you will experience run-time errors or logic errors, but the more initial price bars will be required before the first price bar will be considered for inclusion in this report. If you use a really big number for the “Maximum number of bars study will reference” field, like 200, you will notice that the “Start Date” displayed in the report results will be the bar end time for the price bar approximately 200 bars after the first price bar displayed on the chart, because in the example just given, the first 200 bars of data would not be included in the report.
The report will be displayed in the EasyLanguage® Print Log, which you can open from TradeStation®’s main window by clicking on “VIEW” on the main menu and then “EasyLanguage® Print Log”.
To get the report into Excel, open Excel, copy the report’s output from the EasyLanguage® Print Log onto the clipboard, select the entire first column in the Excel file’s main worksheet, then paste the contents of the clipboard into the first column of the Excel worksheet by holding down the “Control” key then pressing the “V” key while the entire first column is selected. If a dialog box appears that says something like “The data you’re pasting isn’t the same size as your selection. Do you want to paste anyway?” click its “OK” button. Then, select the first column again, click the “DATA” or “Data” menu and click the “Text to Columns” button in the ribbon bar that appears directly beneath Excel’s main menu. When you do this, the numbers and charts may update automatically in which case there is nothing left to do, or the “Convert Text to Columns Wizard” may appear. If the wizard appears, follow these steps:
1. In Step 1 of the wizard, select the “Delimited” radio button and click the “Next” button.
2. In Step 2 of the wizard, there are some check boxes in a group with the title “Delimiters”. Uncheck any checked check boxes in this group. Then, check the check box in this group of check boxes that represents the character used to separate the fields in the report, which you will be able to see in the “Data preview” at the bottom of the dialog box. Since this report uses the semicolon ( ; ) character, check the “Semicolon” check box. Then click the “Next” button.
3. In Step 3 of the wizard, click the “Finish” button. A dialog box may appear that asks you if you want to replace the data already in the worksheet. Click its “OK” button. At this point, the wizard will close and the numbers should update automatically in which case there is nothing left to do.
The outputted report includes both the arithmetic and geometric means of the percent differences between the open price and the close price of the bars in question.
Arithmetic Mean (abbreviated “Arith Mean” in this report):
The arithmetic mean of a list of percent returns of a series of trades is the sum of the returns divided by the total count of the returns. The average of 1%, 2%, 3%, and 4% is (0.01 + 0.02 + 0.03 + 0.04)/4 = 0.025. When taking the average of percent returns, the arithmetic mean produces unrealistically high results because it doesn’t account for the fact that a +10% return followed by a -10% return, or vice-versa, does not result in an average return of (10% + (-10%))/2 = 0%. Instead, it results in an average return of -0.5% across both trades. For example, if you started with $1,000 and gained 10%, you would have $1,100. If you then lost 10%, you would have $1,100 – (.10)*$1,100 = $990, which is less than you started with, even though your winning trade made as much as your losing trade lost on a percentage basis.
Geometric Mean (abbreviated “Geo Mean” in this report):
The geometric mean of a list of percent returns of a series of trades can be calculated by calculating the product (multiplication) of (1 + % Return) of all the trades, where a 5% return is 0.05, and then taking the 1/Nth root of this number, where N is the count of the percent returns being averaged, then subtracting 1 from this number. This produces a more realistic overall percent return than the arithmetic mean, because it correctly handles the fact that an X% loss cannot be fully recovered from by an X% gain. For example, the geometric mean of 10% and -10% is ((1.1*0.9)^(1/2)) – 1, which is -0.005, or -0.5%.
This Quagensia Strategy demonstrates how to create a custom report using three lists that together act as “parallel lists” to hold the equivalent of an in-memory data table of report data. Each list represents a single column of data, which for this report are the following three columns: “Sums of Pct Changes ((C-O)/O) By Month of Year for Arithmetic Means”, “Counts of Bars By Month of Year”, and “Products of (1 + ((C-O)/O)) for Geometric Means”. “Parallel lists” are lists that work together as columns of data, where the items at the same numeric index of all the lists represent a row of data. In this report, each of the three lists have 12 items that the report uses, one for each of the months of the year. The items at the same numeric index all represent the same month. For example, the items at the numeric index 5 in all three lists together represent a row of data for the 5th month of the year, May.
Creating custom reports using parallel lists, one for each column in the report like the one made by this Quagensia Strategy, is just one example of the many kinds of powerful things that can be done without code using lists in Quagensia T Edition. Quagensia T Edition makes it easy to create and use lists, single-dimensional arrays, and multi-dimensional arrays of data of the Quagensia data types that represent a single value, such as numbers, dates, times, colors, items selected from a list of choices, text, or booleans (true or false). You may not start out using lists and arrays on day one, but soon enough you will probably find that the use of lists and arrays is the only way to accomplish an intermediate or advanced level task, and you will realize that lack of support for lists and arrays would severely limit your ability to create advanced trading strategies.
Copyright © 2023 Quagensia, Inc. All rights reserved.
How to Get the Quagensia Strategies
This point-and-click trading strategy is built into Quagensia T Edition (for TradeStation®).
Customize Quagensia Strategies with Your Own Ideas
Tweaking Quagensia Trading Strategies using point-and-click with the Quagensia Desktop Application is easy for non-programmers. If you get stuck you can usually find the answer you need in our online help documentation or you can ask a question in our friendly Discord community.
If you don’t want to tweak a Quagensia Trading Strategy with point-and-click to add your own proprietary trading logic, you can still download a Quagensia Trading Strategy file, open it up in the Quagensia Desktop Application, and generate its code, then backtest and optimize the trading strategy on different instruments, different bar periods (weekly bars, daily bars, hourly bars, 15-minute bars, etc.), or different bar types (time-based bars, volume-based bars, tick-based bars, etc.), and use different start and end dates.
Some tweaks you can make to the Quagensia Trading Strategies you download include:
Modify the entry & exit logic.
- Add more conditions, remove conditions, or change them by choosing from among a very large number of components, including many exotic indicators.
- Add or modify stop losses, trailing stops, and profit targets. Make them tighter, less tight, or based on an entirely different calculation.
- Add or modify time stops. For example, exit after a certain number of bars either unconditionally or only if the post-entry price action did or did not exhibit certain characteristics.
Enhance the output of the strategy to go beyond simply placing orders.
- Draw lines, shapes, and text on the chart. For instance, you can mark times or prices where each entry or exit condition of a multi-condition entry or exit was true, even if all the necessary entry or exit conditions were not true at the same time so an entry or exit did not occur.
- Write information to NinjaTrader®’s NinjaScript® Output window or TradeStation®’s EasyLanguage® Print Log window.
- Write information to a file. You can even output a report that can be opened in Microsoft Excel or consumed by another application that reads comma-delimited, semicolon-delimited, or otherwise character-delimited tabular data files.


