Would you like a way to quickly determine what the best and worst months of the year were to hold a long position for your instrument of choice? The answer may surprise you, so you should definitely find out before you trade. Generating this report is easy with Quagensia® N Edition.
You can then go a step further by customizing this report without code, to only include the months that more closely matched the current market conditions for a given instrument.
In this video, you will learn how to accomplish these things and more using a completely no-code Quagensia Strategy named “Best Month to Trade (Uses Parallel Lists)”. It’s one of many no-code trading strategies that come with Quagensia N Edition. Once you’ve watched this video, you can learn how to build this Quagensia Strategy using lists and loops entirely without code just by clicking choices on a screen by watching the more advanced “How to Create the “Best Month to Trade” Strategy with Lists & Loops in Quagensia N Edition” video.
Video Transcript: Determine the Best Month to Trade with Quagensia N Edition (Uses Lists and Excel)
Would you like a free way to quickly determine what the best and worst months of the year were to hold a long position for your instrument of choice? The answer may surprise you, so you should definitely find out before you trade. Generating this report is easy with the free version of Quagensia N Edition.
Paid users can go a step further by customizing this report without code, to only include the months that more closely matched the current market conditions for a given instrument.
Hi, I’m Brook from Quagensia,
and in this video, I’ll show you how to accomplish these things and more using a completely no-code Quagensia Strategy that I built named “Best Month to Trade (Uses Parallel Lists)”. It’s one of many no-code trading strategies you can get free by downloading Quagensia N Edition from the Quagensia website at quagensia.com.
Let’s get started.
This video only covers this Quagensia Strategy named “Best Month to Trade (Uses Parallel Lists)” but note that all the strategies you see here are free for all users, and you can even customize them for free during the Quagensia N Edition free trial period without any programming knowledge by simply clicking choices on the screen as you would verbally describe your trading ideas.
From within Quagensia N Edition open the Quagensia Strategy named “Best Month to Trade (Uses Parallel Lists)” by clicking here and choosing “View Strategy”.
Before you generate this strategy’s code and send it to NinjaTrader® 8 by clicking this button, first open NinjaTrader® 8.
While NinjaTrader® is loading, it should be noted that Quagensia N Edition is a product of Quagensia, Inc., a company which has no affiliation with NinjaTrader, LLC.
Also, NinjaTrader® and NinjaScript® are registered trademarks of NinjaTrader, LLC.
Now that NinjaTrader® has opened, do the following from within it:
First, connect it to the market data source that has market data for your instrument. For this example, let’s connect to the “Kinetick — End of Day (Free)” market data source.
Second, open the NinjaScript® Editor because that is where the code will be sent and automatically compiled.
Third, from within NinjaTrader® 8 open the Strategy Analyzer because that is where you can run a quick backtest of the strategy to generate the report for your instrument.
Fourth and finally, open the NinjaScript® Output Window because that is where the report results will be printed.
Note that you only need to open the NinjaTrader® 8 windows as just described one time after a computer reboot and you can leave them open for many days, during which time you can send as many strategies from Quagensia N Edition to NinjaTrader® 8 as you want.
Now that NinjaTrader® 8 is set up, generate this strategy’s code and send it to NinjaTrader® 8 by clicking this button, titled “Generate Code and Copy Code File to NinjaTrader® 8 Strategy Code Folder”. If you have your sound up and the NinjaScript® Editor open, you should hear the sound of success that indicates that NinjaTrader® 8 compiled the strategy successfully into a format that it understands so that you can backtest it.
Now let’s generate the report by backtesting this strategy from within the NinjaTrader® 8 Strategy Analyzer. Choose the strategy we just created from the drop-down list. Then choose to generate the report for either a single instrument or multiple instruments at once, such as every stock in the S&P 500®, Dow 30, or NASDAQ indices, multiple popular futures, multiple popular forex pairs, or even multiple popular cryptocurrencies if you have configured the free Coinbase market data connection and connected to it as previously described for the “Kinetick – End of Day (Free)” market data feed. You can also create custom instrument lists of only the instruments you trade, and the instrument list will show up here, allowing you to generate this report for only the instruments you trade.
Above the “Instrument” field are the strategy’s input parameters, which come from the Quagensia Strategy’s “Input Parameters” section. Check the “Clear Output Window First” checkbox if it is not already checked. Note that if you are running this report on multiple instruments at the same time, you will need to uncheck the “Clear Output Window First” checkbox or else the report results for all instruments, except the last instrument in the multi-instrument backtest, will get cleared from the NinjaScript® Output Window. Before you run this report on multiple instruments at once, you should also manually clear the NinjaScript® Output Window by right clicking in the main area of the NinjaScript® Output Window and selecting “Clear”.
For this example, let’s choose to run this report for just one instrument, SPY. SPY is the symbol for the SPDR S&P 500® ETF, which is designed to track the S&P 500®. To run the report on monthly bars, choose “Month” for the Data Series Type, and enter 1 for the Data Series Value. Let’s set the “Start date” of the backtest to January 1, 1996, and the “End date” to September 30, 2022. Let’s set the “Bars required to trade” to 0 only because I am certain that the report when used as-is only tabulates Open to Close percentages on what the backtest sees as the “current bar” during the backtest, so the backtest does not need the ability to look back into the past at previous bars for its calculations.
We are now ready to generate the report. Click the “Run” button, wait a few seconds, and maximize the NinjaScript® Output Window to view the report’s results. Note that the NinjaScript® Output Window needs to be open before running the backtest for the results to be printed there. We simply maximized its window, which was already open before the backtest.
Before you look at the results, note that they are only hypothetical performance results obtained with the benefit of hindsight and are not necessarily representative of the actual trading results that would be achieved by trading this strategy in actual markets. Also, note that we do not offer trading advice, so the example strategy we built for this tutorial and our commentary on its backtest results are meant for educational purposes only and should not be construed as a recommendation to trade using any particular strategy or as a recommendation to buy or sell any particular instrument. Finally, note that trading and investing in the financial markets can involve a high degree of risk of financial losses, including losing your initial investment or more.
These results are now ready to be copied and pasted into Microsoft Excel or your spreadsheet program of choice or saved to a text file to be used by another application. For this example, let’s copy and paste the results into Microsoft Excel and format them so that they are easier to read.
First, open Microsoft Excel and choose “Blank workbook”. Then, copy the report’s output from the NinjaScript® Output Window, select the first column of the Excel 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” 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, the first step of the wizard will ask if the data is fixed width or delimited. Our data fields in this report are delimited by semicolons, so choose the “Delimited” option, click “Next”, uncheck the “Tab” checkbox and any other checkboxes in this group, check the “Semicolon” checkbox, click “Next”, and click “Finish”. Then, increase the column widths as needed. The percentage change data in our report uses the number 0.02 to mean 2%, not 0.02%, so let’s format these two columns as percentages, which also multiplies them by 100 so that the number 2 means 2%, and display two decimal places.
That’s it. We just ran the report as-is and produced a nicely formatted report in Excel. This report shows the average percentage change from the open of the first trading day of the month to the close of the last trading day of the month from January 1996 to September 2022. It is clear from this report that unlike September, October and November were two of the best months to be long and two of the worst months to be short over the last 26 years or so. A trader looking at this report at the end of September might be a little more confident being long this instrument over the next two months and might be a little more concerned about being short this instrument over the next two months.
Now that you’ve formatted the Excel worksheet, you can run this report for other instruments and date ranges even faster. Let’s run this report for QQQ, to see how much faster it is to run this report on a second symbol. In the Strategy Analyzer, change the symbol to QQQ, click “Run”, wait a few seconds, maximize the NinjaScript® Output Window, copy the report, select the cell in the upper lefthand corner of the Excel worksheet, paste the report results into Excel and that’s it. Note how once you format the first report correctly in Excel, you don’t need to do any of the Excel formatting steps for your second report.
It is clear from this report that QQQ has the same seasonal bent as SPY which makes sense given that they are both ETFs composed of US stocks. Whereas SPY tracks the S&P 500®, QQQ is the symbol for the Invesco QQQ ETF, which is designed to track the NASDAQ-100 Index®. Note here that the start date of the report for QQQ is March 1999, whereas for SPY it was January 1996. If we had more time, I would open charts of daily bars for SPY and QQQ and scroll all the way to the left to the first daily bar of each instrument to determine if the first month in each report included daily bars for all the trading days of the month, to avoid including the first month of monthly data if the month is not a complete monthly bar so as to ensure that a partial month does not skew the report’s results incorrectly. Another market data issue of which to be aware, at least for the case of equities like SPY and QQQ, is that dividends and splits may or may not be included in the market data feed on which you ran the report. At the time this video was made, the SPY and QQQ data from the Kinetick market data feed did not include dividends, although if you look at the dividend history of these two instruments, the significant long bias of October and November in this report cannot be explained away by the lack of dividend adjustments in the market data.
To run this report on multiple instruments at once, instead of choosing a single instrument in the Strategy Analyzer, click the instrument drop-down list, hover over an instrument list like I have done for the Dow 30, and choose “Select All”. Also, as previously explained, uncheck the “Clear Output Window First” checkbox and manually clear the NinjaScript® Output Window, then click “Run”. Notice that it takes longer when you run the report for 30 instruments at once. Once the backtest is finished, maximize the NinjaScript® Output Window, copy the report, this time using the keyboard shortcuts Control-A to “Select All” and Control-C to copy the selected report results to the clipboard, paste the report results into Excel and that’s it. Note how your formatting is correctly applied to the results for all the stocks in the Dow 30. When you use this report to analyze individual stocks such as those in the Dow 30, it is especially important to remember that dividends might not be included in the market data on which you ran the report.
Note that this report can be run on “Daily”, “Weekly”, or other bars as well, not just “Monthly” bars.
For instance, 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 trading day and exit at the end of the trading 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.
Before we move on to customizing this report from within Quagensia N Edition, please note that a full explanation of the difference between the two percentage change columns, namely the difference between the arithmetic mean and the geometric mean, is provided in the “Description & Notes” field of the Quagensia Strategy inside of Quagensia N Edition. Lots of other technical details about this report and the trading strategy that created it are in the “Description & Notes” field as well, and it is highly recommended that you read this field carefully before either customizing this report or relying on its results for real-life trading decisions.
We are now in part two of this video, where I will show you how to customize this report without code, to only include the months that more closely matched the current market conditions for a given instrument. You can do this if you have a paid subscription to Quagensia N Edition or are in the free trial period.
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 month’s bars should be included in and excluded from the results.
We originally opened the “Best Month to Trade (Uses Parallel Lists)” Quagensia Strategy by clicking here and choosing “View Strategy”. This is a template strategy that is built into Quagensia N Edition so it cannot be edited directly. To customize this strategy, you first need to create a copy of it. You can do this by selecting “Create New Strategy From a Copy of This Strategy” here.
After creating a copy of the strategy so you can customize it, you need to save it to the “My Algos” folder on your computer before continuing. Change its name here then click the “Save” button. Notice that the “Save As” window already defaults to the “My Algos” folder, so all you need to do is click “Save”. Now it shows up in the “My Algos” folder from within Quagensia and can be customized.
To customize this report without code, scroll down to the yellow “comment” that starts with the message “Attention paid users and users whose free trials have not expired” and follow its instructions. It just tells you to make a copy of the strategy, which we have already done, then customize the set of conditions directly above the instructions you are reading.
Let’s say that the monthly bar for September 2022 has just closed, and you are trying to determine if buying on the open of the first trading day of October and selling on the last trading day of October has historically been a profitable trade, and by how much. To do this, think of the October 2022 monthly bar as the current bar whose percentage change from open price to close price you are trying to predict, and think of the September 2022 monthly bar as the previous bar.
If the September 2022 monthly bar closed down, you could add a condition like this. This will cause the report to only include the results for months whose prior month’s bar closed below its open price.
If the close price of the September 2022 monthly bar was also below its 12-month simple moving average at the time the September monthly bar closed, you could add another condition like this. This will cause the report to only include results for months whose prior month’s bar closed below the 12-month simple moving average at the time the prior month’s bar closed. To learn more about building more complex sets of conditions with ORs and parentheses, check out the 1-hour video titled “Introduction to Quagensia N Edition” on our home page at quagensia.com.
Press this button to save your customizations, generate your customized strategy’s code and send it to NinjaTrader® 8. If your sound is up, you should hear the sound of success. Once you do, maximize the NinjaTrader® 8 Strategy Analyzer window, select the name of your customized strategy from the drop-down list, and fill out the fields the same way as before, except that you should set the “Bars required to trade” field to 13, to account for the 12-period simple moving average that started at the previous bar and calculated its average going backward 12 bars, for a total of 13 bars. Let’s choose SPY again, and click “Run” to generate the report. Next, select all the data you pasted in the Excel worksheet previously, right click, and select “Clear Contents”. Then, copy your customized report results from the NinjaScript® Output Window and paste it into Excel.
Right away, two things relevant to our hypothetical trading scenario stand out. First, it turns out that of the five October monthly bars between October 1997 and October 2021 that also occurred after market conditions that were similar to the current market conditions that we are experiencing now at the close of the September 2022 bar, the average percentage change from the October monthly bar’s open price to its close price is over 2%. So, October was a good month for long positions generally, and October was a good month for long positions in the five years since 1997 whose market conditions were similar to the current market conditions at the close of the September 2022 bar. Either way, October was a good month for longs. So, a trader faced with a decision to go long on the open of the first trading day of October and hold it until the end of October may have more confidence in taking a long position. And a trader facing a decision to go short may be even more concerned with the prospect of doing so now that both reports show that October has simply been a bad month for shorts since 1997.
It is up to you to define how you see the “current market conditions” by building a condition set inside of Quagensia N Edition. And unlike in this demo, you should put more thought into it and try more than one set of conditions to see if October is a good month for longs even when you choose other aspects of the current market conditions to filter on. For instance, if you think that the slope of the 12-period exponential moving average is generally more important than the two conditions we defined, you could run a report where your only condition upon which to filter monthly bars is that the slope of the 12-period exponential moving average has the same sign as that of the 12-period exponential moving average at the close of the September 2022 bar.
The second thing that stands out is that the three November monthly bars since 1997 that matched our criteria were down by an average of over 4%. Granted, a sample of only three bars is hardly statistically significant but remember that November was one of the best months for SPY since 1996 as determined by our report without customizations, so adding our filter turned November from a good month for longs into a bad one. This shows the importance of always customizing reports to match the current market conditions of the instruments you trade and re-running them, rather than just running reports without customizations. Now imagine that our hypothetical trading scenario had been such that the current date was one month later, the October 2022 bar just closed, and we were trying to find out if the month of November has had an upward bias or not since the late 1990s. For this hypothetical scenario, the customized report shows that November monthly bars, that were preceded by market conditions similar to the current ones, actually have exhibited a major downward bias even though generally November has exhibited an upward bias.
One quick caveat: it should be noted that the start date for this customized version of the report was for the February 1997 bar, which is 13 bars after the backtest’s “Start date” we set in the Strategy Analyzer because we set the “Bars required to trade” field to 13. This means that we are technically comparing two different date ranges for the report for SPY with and without the custom conditions to filter out monthly bars, so we should not draw conclusions about the relative differences between the two reports unless we were to go back and re-run the non-customized report starting on the February 1997 bar. We still can, however, look at both reports separately and see if they come to the same conclusion or different ones.
That’s the end of our video. Thanks for watching. If you liked it, please let us know by giving this video a like and subscribing to our channel. And if you loved it, please consider sharing this video.
Download the free trial of Quagensia N Edition from quagensia.com to get all our free no-code trading strategies so that you can use them as-is and customize them without code.
And on behalf of our users, thank you to the content creators who take this strategy and run with it and publish their Quagensia Strategies in their own videos. Content creators, if you let us know when you’ve published high-quality Quagensia-enhanced content, we will consider promoting it for free on our website.
Have a great day.