Best Day of Week to Trade (Uses 2-Dimensional Array and Microsoft Excel) (Point-and-Click NinjaTrader® Strategy)
Original Trading Strategy
Links to the section of the video titled “Using & Customizing the Built-In Strategies in Quagensia N Edition” in which this built-in strategy is covered.
Peer Reviews, Modifications & Responses
Thanks for Sharing!
Trading Strategy Summary
This strategy outputs a report when it is backtested on an instrument using the NinjaTrader® Strategy Analyzer, which you can open from NinjaTrader®’s main window by clicking on “New” on the main menu and then “Strategy Analyzer”.
It does not place trades.
It is meant to be run as a backtest only, not in a live trading environment.
Run this report on daily bars or 24-hour bars for any instrument you want to learn more about before placing any trades on that instrument.
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 “Bars required to trade” field in the NinjaTrader® user interface can be as low as 1, since by default this report considers only the current price bar and the price bar directly before it. If you will be running this report with your own criteria for what price bars will be included in the result, the “Bars required to trade” property 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 “Bars required to trade” property, 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 occurring on or after the “Start date” that you set in the NinjaTrader® Strategy Analyzer, because in the example just given, the first 200 trading bars of data would be skipped before the logic in the “When Bar Updates” section below would be executed for each price bar in the backtest that creates the report.
By default, the report will be displayed in the NinjaScript® Output window, which you can open from NinjaTrader®’s main window by clicking on “New” on the main menu and then “NinjaScript® Output”, or you can open it by clicking on the “NinjaScript® Output” icon in the NinjaScript® Editor window’s toolbar.
You can also write the results to a file is desired.
To get the report into Excel, open the Excel file in the downloadable zip file below, copy the report’s output from the NinjaScript® Output window or from a file 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. By default, this will likely be the semicolon ( ; ), in which case you would 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 and charts should update automatically in which case there is nothing left to do.
The outputted report includes both the arithmetic and geometric averages of the percent differences as well as the price differences between the previous close price and the close price of the bar for the day of the week in question, between the open price and the close price of the bar for the day of the week the in question, and between the previous close price and the open price of the bar for the day of the week 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 a 2-dimensional array to hold the equivalent of an in-memory data table of report data. One dimension of the array represents the columns of data, and the second dimension of the array represents the rows of data.
Creating custom reports using 2-dimensional arrays 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 arrays in Quagensia N Edition. Quagensia N Edition makes it easy to create and use single-dimensional arrays, multi-dimensional arrays, and lists 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
The downloadable zip file linked to below contains Quagensia N Edition (for NinjaTrader®) files and/or auxiliary files that were created by us at Quagensia, Inc.:
Click the link above to download the zip file and unzip it. If this zip file contains point-and-click Quagensia Trading Strategy files for your edition of the Quagensia Desktop Application, put the point-and-click Quagensia Trading Strategy files into your “My Algos” folder as described in the video Downloading & Importing Third-Party Strategies into Quagensia N Edition (for NinjaTrader®) or Downloading & Importing Third-Party Strategies 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.


