Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to differentiate between Strategy "Is On Chart" vs."In Simulation (Invisible)"?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Originally posted by EquityTrader View Post
    koganam,

    I am not using any location filter, because unfortunately neither "if (CurrentBar == null) ..." nor "if (Category == Category.Backtest) ..." solve the problem described in my previous posts.

    This is precisely what I am trying to get an answer for. That is, what location filter can I use, since the two above don't solve my problem.

    EquityTrader
    So then, are you saying that you actually tried this code, and it did not do what you are seeking?
    Code:
    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.
    if (ChartControl != null) //meaning that we are on a chart, and will only draw if we are on a chart
    {
    	SolidColorBrush myCustomSolidBrush = ComputationallyExpensiveMethodToGetACustomBrush();
    
    	Draw.Dot(this, GetNewUniqueIdForThisDrawingObject(), true, 0, High[0], myCustomSolidBrush, false);
    }
    }

    Comment


      #17
      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


        #18
        Originally posted by EquityTrader View Post
        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.
        OK. I am now really intrigued. NT Support will likely take it from here, but I am going to write some more elaborate code myself to see if I can resolve this for us in the meantime.

        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, 08:58 AM.

        Comment


          #19
          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


            #20
            Originally posted by NinjaTrader_PatrickH View Post
            Hello 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.
            I have forwarded this to development as a feature request to have a means to detect the Chart Display is in use. It has been assigned id SFT-2476.

            Comment


              #21
              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


                #22
                Another simple option would be to add a strategy input that you can use to turn the drawing logic on/off.

                Comment


                  #23
                  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 caacapital, Today, 10:10 AM
                  1 response
                  14 views
                  0 likes
                  Last Post NinjaTrader_ShawnB  
                  Started by DiverG20, Today, 10:23 AM
                  0 responses
                  21 views
                  0 likes
                  Last Post DiverG20  
                  Started by SuneSorgenfrei, Today, 09:29 AM
                  0 responses
                  19 views
                  0 likes
                  Last Post SuneSorgenfrei  
                  Started by dodoei, Today, 07:24 AM
                  0 responses
                  14 views
                  0 likes
                  Last Post dodoei
                  by dodoei
                   
                  Started by thecashguys, Today, 06:13 AM
                  0 responses
                  13 views
                  0 likes
                  Last Post thecashguys  
                  Working...
                  X