Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Check account value every Minute on a 1hour strategy?

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

    Check account value every Minute on a 1hour strategy?

    Hey guys,

    I am using a strategy on a 1 hour timeframe.
    However, I want to check the P&L and the account value every 1 Minute.
    Is this the point where I have to dig into "Multi-Timeframe-Strategies" or is there another solution for that issue?!

    Thanks for your response

    Cheers cNuuuuuu

    #2
    Hello cNuuuuuu,

    Thank you for your note.

    Yes, you would need to look into adding an additional data series to have the OnBarUpdate() be called for every minute. You can separate out the BarsInProgress in the OnBarUpdate() to see which update is coming through the script -
    http://www.ninjatrader.com/support/h...nstruments.htm

    http://www.ninjatrader.com/support/h...inprogress.htm

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Hey Cal,

      I almost expected that answer So far I was always delaying to work into MTF-strategies. But now I have a good reason to start with! Thanks for your two links!

      Comment


        #4
        Hey Cal,

        I tested successfully the following code with an primary period of 5 Minutes and an additional PeriodType of 1 Minute with Realtime data. Every Minute a Print statement is shown in the output. After 5 Minutes two statements are shown as desired.

        However, when changing the PeriodType to 20 seconds (instead of 1 Minute), no print statements are shown in the output. Therefore I am concluding that the the OnBarUpdate is not called (?)... Or is NT not printing statements for timeframes < 1Min?!
        I was intending to check the account value every 10 or 20 seconds. Will this work? Or where is my mistake?

        Thank you very much for your help!

        Code:
                protected override void Initialize()
                {    
                //    Add(PeriodType.Second, 20);
                    Add(PeriodType.Minute, 1);
        
                    TraceOrders = true; 
                    CalculateOnBarClose = true;
                }
        
                protected override void OnBarUpdate()
                 {
            
                    if (BarsInProgress == 1)
                        {
                        Print(Time[0].ToString() + " - Instrument: "+Instrument.FullName+" - Primary Bar Trigger");        
                        }
            
        
                    if (BarsInProgress == 0)
                        {            
                        Print(Time[0].ToString() + " - Instrument: "+Instrument.FullName+" - 5 Minute Bar Trigger");
                        }    
                }

        Comment


          #5
          cNuuuuuu,

          Who are you connected to do data? This is displayed in the lower left hand corner of the Control Center?

          Are you getting historical data for this timeframe on the chart?

          Are there any errors in the log tab of the Control Center when trying to run this strategy?
          Cal H.NinjaTrader Customer Service

          Comment


            #6
            Hey Cal,

            I am connected to Interactive Brokers paying 45$ USD to get RT data for NYSE stocks.

            As you can see from screenshot 1, I am able to receive 10second bars, but I am not able to load historical bars at this high timeframe. However, for 1 Minute I can also load historical data...

            No Error Messages in the Log (screenshot 2)

            Any ideas?!
            Attached Files
            Last edited by cNuuuuuu; 02-25-2015, 11:28 AM.

            Comment


              #7
              Ha, I found the solution

              Due to the fact, that I can't load historical bars and "min bars required" is set by default to 20. I should have been a bit more patient
              Setting "min bars required" to 0 immediately produces the desired print outs (screenshot 1).

              Just a general question:
              My general idea was to check every 30 seconds whether the daily loss is above a certain threshold. Logically, the strategy should slow down, if I increase the frequency more. Is it possible to measure, by how much the strategy is slowed down for instance if I use 10 seconds, 5 seconds or 1 second or tick by tick?!
              Attached Files

              Comment


                #8
                cNuuuuuu,

                When you say slow down do you mean by volume wise and therefore the number of ticks you get? OnBarUpdate() is event driven by ticks regardless of the time.

                Say you are using a 30S chart. You get a tick at 25S of the current bar. That bar won't close til you get another tick of data, which could be another 6 or more seconds.

                If you run the strategy with CalculateOnBarClose set to false then you would receive an OnBarUpdate() when ever a tick is received.
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  Hey Cal,

                  sorry, maybe my question was not accurate enough.
                  FYI: CalculateOnBarClose is set to true. I was just wondering in general if due to the account checking every 20,10 or 5 Seconds the strategy may decrease in speed or that Interactive Brokers is not supporting such permanent queries...

                  Or in other words, just as an example: It is obvious that a 5000 line code will take a bit longer than a 10 line code. If I would use this on a tick by tick basis, this calculation should take more time... So how can I measure, whether a certain Code slows down my strategie?!

                  Comment


                    #10
                    Hello cNuuuuuu,

                    Thank you for your response.

                    More lines of code can potentially slow performance. But the data being calculated on should not slow the feed, but may slow the performance if a large amount of data is being processed on each tick (which is not the case with CalculateOnBarClose = True).

                    Please look at our performance tips for more information: http://www.ninjatrader.com/support/h...ance_tips2.htm

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by andrewtrades, Today, 04:57 PM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by chbruno, Today, 04:10 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post chbruno
                    by chbruno
                     
                    Started by josh18955, 03-25-2023, 11:16 AM
                    6 responses
                    436 views
                    0 likes
                    Last Post Delerium  
                    Started by FAQtrader, Today, 03:35 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post FAQtrader  
                    Started by rocketman7, Today, 09:41 AM
                    5 responses
                    19 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Working...
                    X