Print Most Recent Price Bar Statistics (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 prints out common price bar statistics for the most recent price bars of an instrument to the NinjaScript® Output window.
You can quickly and easily use this strategy for a faster way to obtain price bar statistics than manually interacting with the price bars in a NinjaTrader® chart then manually entering open, high, low, and close price values into a calculator to calculate the statistics manually.
You can also easily add your own price bar statistics to this strategy without code by simply clicking choices on a screen as you would verbally describe your price bar statistics by following the instructions in the message near the bottom of this Quagensia Strategy.
WARNING: Always carefully note the Date and Time of the most recent bar whose statistics are printed to the NinjaScript® Output window. This will sometimes be for the second to last bar on the chart instead of the last bar. At the time we created this Quagensia Strategy we were unaware of a solution to this problem that would ensure that the last bar, rather than the second to the last bar, is always the most recent bar whose statistics are printed. The problem is that sometimes when a NinjaScript® strategy is backtested in the Strategy Analyzer or applied to a chart, the last bar for which the “OnBarUpdate() method” of the NinjaScript® strategy is called is the second to the last bar on the chart, not the last bar on the chart. This problem may be fixed in a future version of NinjaTrader®, and this strategy may already reliably print statistics for the last bar in your version of NinjaTrader® that you are using right now, in which case you may disregard this message. In our experience gathered from testing this strategy on US equities from a computer whose time zone is set to Chicago time, we noticed that the problem is more likely to occur in the evening after the end of the regular session, and the problem is least likely to occur in the morning before the open of the regular session, so if possible you may want to use this strategy in the morning before the next trading day begins rather than in the evening right after the end of the trading day for which you are interested in printing price bar statistics. We also recommend applying this strategy to a chart to print the statistics rather than running a backtest to print the statistics.
The “Print Most Recent Price Bar Statistics” strategy helps you create *other* Quagensia Strategies that allow you to test some interesting price action that you see at the right edge of a price chart that your intuition tells you is probably bullish or bearish.
You can determine if some price action was bullish, bearish, or non-predictive in the past for a particular instrument or for all similar instruments, for instance every stock in the S&P 500, by quickly creating a Quagensia Strategy based on the price bar statistics you copy and paste from the “Print Most Recent Price Bar Statistics” strategy’s price bar statistics in the NinjaScript® Output window. Then you can generate the custom Quagensia Strategy’s NinjaTrader® code and send it to NinjaTrader® with the click of a button, and run a backtest of your strategy from within the NinjaTrader® Strategy Analyzer.
This strategy is meant to reduce the time it takes to create a Quagensia Strategy whose entry or exit logic uses common price bar statistics by printing them out to the NinjaScript® Output window. You can then copy and paste the statistical values of interest from the NinjaScript® Output window to a text box in Quagensia or you can use the statistical values of interest to help you determine a good minimum and maximum value for the statistic that you decide would identify another price bar in the backtest as being similar to a price bar at the right edge of the chart whose statistics this strategy prints to the NinjaScript® Output window.
You can open the NinjaScript® Output window 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.
Note that the outputted data is formatted in the ideal way for consumption by a trading strategy within NinjaTrader® rather than being formatted in a way that numbers are formatted in the part of the world where you live. For instance, the number 1,234.56 is ideally formatted for someone in the US and the number 1.234,56 is ideally formatted for most people in Europe, but NinjaTrader® code needs this number to be written like 1234.56, i.e. without thousands separators of any kind and using the period ( . ) character as the decimal separator.
This strategy does not place orders. It merely prints out information to save you time by avoiding manual calculations. It is meant to be run as a backtest only, not in a live trading environment.
Here is an example of what this strategy prints out for each of the most recent price bars of an instrument on a NinjaTrader® chart:
11/12/2021 3:00:00 PM (Date and Time (Local Culture Format) (Excludes Fractions of a Second))
2021-11-12 15:00:00.1234567 (Date and Time (Quagensia Format, for Pasting into Quagensia) (Includes Fractions of a Second))
Open: 465.12
High: 467.37
Low: 464.11
Close: 466.7
Volume: 28598988
Median ((H + L)/2): 465.74
High – Low: 3.26
Close – Prev Close: 2.93
Close – Open: 1.58
Open – Prev Close: 1.35
Close – Low: 2.59
High – Close: 0.67
Open – Low: 1.01
High – Open: 2.25
Pct Diff (Low to High) ((H – L)/L) (0.10 is 10%): 0.0070242
Pct Chg (Prev Close to Close) (0.10 is 10%): 0.00631779
Pct Chg (Open to Close) (0.10 is 10%): 0.00339697
Pct Chg (Prev Close to Open) (0.10 is 10%): 0.00291093
Close as Pct of High – Low, from Low (0.10 is 10% Between the Low and High, Closer to the Low): 0.79447853
Close as Pct of High – Low, from High (0.10 is 10% Between the High and Low, Closer to the High): 0.20552147
Open as Pct of High – Low, from Low (0.10 is 10% Between the Low and High, Closer to the Low): 0.30981595
Open as Pct of High – Low, from High (0.10 is 10% Between the High and Low, Closer to the High): 0.69018405
True Range (Max Diff Between H, L, and Prev Close): 3.6
ATR(14): 3.75097153
Ratio of True Range to ATR(14): 0.95975135
Add your custom price bar statistic here, and add many more price bar statistics beneath this one: 2.93
If you will only be running this strategy as-is, i.e. if you will be not be adding your own custom price bar statistics to the output, the “Bars required to trade” field in the NinjaTrader® user interface can be as low as 1 + the “ATR Period” input parameter. If you will be running this strategy with your own custom price bar statistics, 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 the results outputted by this strategy.
Copyright © 2023 Quagensia, Inc. All rights reserved.
How to Get the Quagensia Strategies
This point-and-click trading strategy is built into Quagensia N Edition (for NinjaTrader®).
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.


