protected override void OnBarUpdate() { if (CurrentBar < BarsRequiredToTrade) return; // I wish the line below could be called only for back-test charts and live charts, not during back-tests // that are running invisibly in memory, because it is a waste of computer resources. [COLOR="Red"]if (ChartControl != null) [COLOR="Blue"]//meaning that we are on a chart, and will only draw if we are on a chart[/COLOR] {[/COLOR] SolidColorBrush myCustomSolidBrush = ComputationallyExpensiveMethodToGetACustomBrush(); Draw.Dot(this, GetNewUniqueIdForThisDrawingObject(), true, 0, High[0], myCustomSolidBrush, false); [COLOR="red"]}[/COLOR] }
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
How to differentiate between Strategy "Is On Chart" vs."In Simulation (Invisible)"?
Collapse
X
-
Originally posted by EquityTrader View Post
Code:
-
Yes. I tried it and it didn't work. The code you highlighted in red returns false on a back-test results chart, so in the code you wrote below, a dot would not be drawn on the back-test results chart. The code you wrote works great on a non-back-test results screen chart, but sadly, ChartControl == null on a back-test results chart.
Comment
-
Originally posted by EquityTrader View PostYes. I tried it and it didn't work. The code you highlighted in red returns false on a back-test results chart, so in the code you wrote below, a dot would not be drawn on the back-test results chart. The code you wrote works great on a non-back-test results screen chart, but sadly, ChartControl == null on a back-test results chart.
So, if I am getting it right, you want some code to NOT run during an optimization or if the code is not running on a chart, but to run on the backtest results chart?Last edited by koganam; 06-21-2017, 09:58 AM.
Comment
-
koganam,
I really appreciate that! No pressure though. If you don't have time, hopefully I can get Ninja support to respond to this forum thread with the answer.
I would describe my exact specification like this:
I want some code to run in a strategy's OnBarUpdate() method only if it is being displayed on any chart, including both real-time charts and the chart that displays the trades in the back-test results screens. The code should not run in any "non-visual scenario" such as the invisible in-memory back-tests and the invisible in-memory optimizations.
Thanks!
EquityTrader
Comment
-
Originally posted by NinjaTrader_PatrickH View PostHello EquityTrader,
Thank you for your patience.
ChartControl will only return when loaded on a chart window. The Chart Display of the Strategy Analyzer does not trigger ChartControl as it is not the Chart window.
There is not an option that would state whether the Chart Display of the Strategy Analyzer was being viewed for the strategy.
Please let me know if you have any questions.
Comment
-
Thanks, NinjaTrader_PatrickH! This will definitely improve back-test speed for certain types of strategies that do lots of work only if they are on a chart.
Comment
-
Another simple option would be to add a strategy input that you can use to turn the drawing logic on/off.
Comment
-
EquityBoost2,
I like your out-of-the-box thinking on this. This solution is a good idea for quite a few kinds of problems, but wouldn't work for the scenario described in this thread because it doesn't solve the problem of being able to run a single back-test that doesn't do one set of calculations when running in memory, but when loaded into the back-test results chart, the set of calculations do occur.
Your method could definitely be used to, for instance, run a bunch of back-tests and optimizations without the charting calculations being done, and then when one is curious about how the chart of a particularly encouraging back-test results look, they could re-run the specific back-test with the flag to run all the calculations set to true, which run run these CPU-intensive calculations for both the in-memory back-test and the chart.
NinjaTrader_PatrickH has thankfully already sent a feature request to development that will fully solve the problem described in this thread, which is to have some condition that can be checked in code to determine if the NT8 strategy is being run on a chart vs. merely being run in memory to output the basic back-test results summary info that appears in all the other back-test results screens.
Thanks again for your idea.
EquityTrader
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by ZenCortexCLICK, Today, 04:58 AM
|
0 responses
2 views
0 likes
|
Last Post Today, 04:58 AM | ||
Started by sidlercom80, 10-28-2023, 08:49 AM
|
172 responses
2,280 views
0 likes
|
Last Post
by sidlercom80
Today, 04:40 AM
|
||
Started by Irukandji, Yesterday, 02:53 AM
|
2 responses
17 views
0 likes
|
Last Post
by Irukandji
Today, 03:55 AM
|
||
Started by adeelshahzad, Today, 03:54 AM
|
0 responses
4 views
0 likes
|
Last Post
by adeelshahzad
Today, 03:54 AM
|
||
Started by Barry Milan, Yesterday, 10:35 PM
|
3 responses
13 views
0 likes
|
Last Post Yesterday, 11:58 PM |
Comment