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!
See more
See less

Partner 728x90

Collapse

The strategy freezes and freeze chart.

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

    The strategy freezes and freeze chart.

    Hello.

    I am creating a strategy with Umanaged orders.
    I work fine with:
    - Simulated Data Feed;
    - Playback max speed;
    - Strategy Analyzer.

    But, it freezes chart and itself on real-time connection (tested on 3 PCs, 2 connections).
    I simplified the strategy, and now I have multiple versions that reproducing the issue.

    Let me introduce the simplest version with market entries and market exits:

    PHP Code:
    namespace NinjaTrader.NinjaScript.Strategies.Strat_NTForum
    {
        public class 
    sTest_07_Market Strategy
        
    {                
            protected 
    override void OnStateChange()
            {
                if (
    State == State.SetDefaults)
                {                
                    
    Description                        "The strategy description";
                    
    Calculate                        Calculate.OnBarClose;

                    
    IsUnmanaged                        true;
                    
    RealtimeErrorHandling            RealtimeErrorHandling.IgnoreAllErrors;        

                }
                else if (
    State == State.Configure)
                {                                                
                    
    AddDataSeriesBarsPeriodType.Tick);
                }        
            }

            protected 
    override void OnBarUpdate()
            {
                if( 
    State != State.Realtime )
                {
                    return;
                }


                if( 
    BarsInProgress != ) return;
                if( 
    CurrentBars[1]  < ) return;


                if( 
    CurrentBars[1] % == )
                {
                    if( 
    Position.MarketPosition == MarketPosition.Long )
                        { 
    SubmitOrderUnmanaged0OrderAction.SellOrderType.Market100"""" ); }
                    else if( 
    Position.MarketPosition == MarketPosition.Short )                    
                        { 
    SubmitOrderUnmanaged0OrderAction.BuyOrderType.Market100"""" ); }
                }


                
    string entry_signal "";
                if( 
    CurrentBars[1] % == )
                {

                    if( 
    Times[1][0].Second == )
                        { 
    entry_signal "BUY"; }
                    else
                        { 
    entry_signal "SELL"; }                                                                                            
                }


                if( 
    entry_signal == "BUY" )
                {
                    
    double     entry_rice    Closes[1][0] +20 TickSize;                
                    
    SubmitOrderUnmanaged0OrderAction.BuyOrderType.Market10entry_rice"""" );
                }
                else if( 
    entry_signal == "SELL" )
                {                    
                    
    double     entry_rice    Closes[1][0] -20 TickSize;
                    
    SubmitOrderUnmanaged0OrderAction.SellOrderType.Market10entry_rice"""" );
                }                                                    

            }        
        }

    And here is the brief video (0:35): https://screencast-o-matic.com/watch/cYe1qkxlw2
    You can see on the video how the strategy freezing and unfreezing chart.
    The chart markers off.
    No errors in log and trace files.
    What can cause this issue in this minimalist strategy?

    Thank you.
    Last edited by fx.practic; 03-06-2020, 02:25 PM.
    fx.practic
    NinjaTrader Ecosystem Vendor - fx.practic

    #2
    Hello fx.practic,

    Thank you for your reply.

    Your secondary series is a single tick series, and you're only submitting orders to that - not to your primary series. So you're firing at least one order for every other tick that comes in - and every fourth tick, you'd be firing two orders. The market is very volatile right now and we're seeing considerably more ticks come in than usual for most instruments, so you're seeing multiple orders fired off per second.

    I ran this for approximately 1 minute on my chart, and in that time it took 807 orders and froze NinjaTrader. I'm not surprised this is freezing your chart.

    What is the goal you're trying to achieve with this strategy? I'm assuming you're not meaning it to take orders every other tick.

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hello, Kate.
      You are 100% right.

      I have an issue that happened on real-time connections only.
      The original strategy have 5000+ lines and I need to reproduce error as fast as I can.
      With less frequency, I need to wait up to 40 minutes until it freezes.

      And I found that chart freezes each time after "Order Pending" sound.
      The bigger frequency - the more often I hear "Order Pending" with Marker oders.

      Of course, original strategy uses StopMarket (or Limit orders) for entries. But the version with orders have much more lines of code.

      So, I my aim was to isolate the issue and reproduce it as fast as I can.

      Ok, if the orders sending frequency is the reason, what is the reasonable frequency?
      We need it to avoid accidental sending orders, say, on range bars at fast market moves etc.

      Thank you.

      P.S. Here is once more freeze with fast forward after disabling strategy:
      https://screencast-o-matic.com/watch/cYe1rlxl5Z
      Last edited by fx.practic; 03-06-2020, 03:46 PM.
      fx.practic
      NinjaTrader Ecosystem Vendor - fx.practic

      Comment


        #4
        Hello fx.practic,

        Thank you for your reply.

        I'm not entirely certain if the issue here is the same as what's happening in your full script, if you are running the other one for 40 minute until it freezes. With this script you're just locking up the chart with orders because of volatility.

        When I ran it on a less volatile instrument, it did not crash the chart until volatility picked back up around the close.

        With your full strategy, does it just seem to lag when you hear the order pending sound?

        In your full strategy, are you tracking the order objects? I note you're not doing any kind of tracking of the Order objects in this example script, but it's not clear if that's just to make it as concise as possible or whether that's similar to the full strategy.

        Thanks in advance; I look forward to assisting you further.


        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Hello Kate, thank you for a fast response.
          I thought on your first answer, changed the strategy and performed some tests.

          The strategy may send orders with different frequency and have speed measuring features now:
          - approximate average speed of one run OnBarUpdate() method;
          - approximate real Playback speed ratio (strategy compares real-world time and the last 100 bars timestamps).

          In the table you can see very approximate results for sending entry orders between once per bar to once per 50 bars.
          All tests performed on maximum speed.
          Chart and the strategy were never frozen on these tests.
          Frequency,
          each N bars
          OBU(), msec Playback speed ratio, x
          1 260 0.1
          3 140 0.3
          5 116 1
          10 65 2
          20 34 5
          30 22 10
          50 3 15
          These are the videos of two tests:

          Frequency: each 5th bar (~5 minutes): https://screencast-o-matic.com/watch/cYeiowxImm
          Frequency: each 30th bar (~3 minutes): https://screencast-o-matic.com/watch/cYeiDBxIsM


          After these tests I have multiple concerns:

          #01
          Playback Real-time
          never freezes freezes
          if delayed, it still receives and handle bars stops receiving bars
          still can overtake the market any chances to recover
          This is different behaviour.
          Is it expected?

          #02
          Till now I consider Playback 1000x 10 hours more strict test that 1 month of real-time.
          I expected same sequence of events, but different speed. Was I wrong?

          #03
          What exactly causing freezing?
          Is is the time duration between sending 2 consecutive orders?
          Or sending X orders withing Y milliseconds?
          Or a number of executions per second?
          How can strategy avoid freezing?

          #04
          Can a strategy detect that it frozen and “unfreeze” itself?
          (I know: it sounds like fantastic)

          Thanks you.
          Attached Files
          Last edited by fx.practic; 03-09-2020, 03:09 PM.
          fx.practic
          NinjaTrader Ecosystem Vendor - fx.practic

          Comment


            #6
            The example above ↑ was with Market orders.
            Here is example with just submitting Stop orders:
            .
            Attached Files
            Last edited by fx.practic; 03-09-2020, 10:43 AM.
            fx.practic
            NinjaTrader Ecosystem Vendor - fx.practic

            Comment


              #7
              And ChangeOrder() test:
              .
              Playback Real-time
              new bars come and handled,
              whole interface is not responsive
              new bars stop coming
              nothing frozen
              after disabling strategy all missed bars added to the chart
              https://screencast-o-matic.com/watch/cYeQYQxbRs https://screencast-o-matic.com/watch/cYeQYgxFV5
              Attached Files
              Last edited by fx.practic; 03-09-2020, 02:48 PM.
              fx.practic
              NinjaTrader Ecosystem Vendor - fx.practic

              Comment


                #8
                Hello fx.practic,

                Thank you for your replies.

                I've had fairly limited time to do testing on these today, but in my testing with the variation with the Stops, I haven't experienced any freezeups. I even modified it so it sends both a buy and sell order each time so it can get back to flat and send more orders, and didn't experience any freezing. I will continue to do more testing and will follow up with you when I find out more.

                Thanks in advance; I look forward to resolving this for you.
                Kate W.NinjaTrader Customer Service

                Comment


                  #9
                  Once started to measure speed, I measured Playback 1x orders events.
                  Each 10th bar the strategy took one action and measure the speed of OnBarUpdate() run.
                  The strategy for the limit orders in attachment (as an example).

                  #04
                  50 - 80 msec for sending orders - are these numbers correct and expected?
                  *150 msec for Market orders it is open + close position on same bar.


                  Click image for larger version  Name:	Send orders speed.png Views:	0 Size:	720.5 KB ID:	1089878
                  Last edited by fx.practic; 03-10-2020, 11:35 AM.
                  fx.practic
                  NinjaTrader Ecosystem Vendor - fx.practic

                  Comment


                    #10
                    Thank you, Kate.
                    I just want to clarify that freeze happened on real-time connection only.
                    I tested it on 3 PCs.
                    Strange.

                    Ok, and what about 70 msec for the sending orders?
                    Is this expected speed, or it slows down on my exactly PC?
                    fx.practic
                    NinjaTrader Ecosystem Vendor - fx.practic

                    Comment


                      #11
                      I am ready to provide access to my system at any convenient time, if you will have ability to check.
                      Thank you.

                      Upd: I added 500 msec delay between sending orders. Now it freeze less frequently.
                      Last edited by fx.practic; 03-11-2020, 12:25 PM.
                      fx.practic
                      NinjaTrader Ecosystem Vendor - fx.practic

                      Comment


                        #12
                        Hello fx.practic,

                        Thank you for your reply.

                        I am still in the process of testing and gathering information on my end. When I have more information I will let you know.

                        Thanks in advance; I look forward to assisting you further.
                        Kate W.NinjaTrader Customer Service

                        Comment


                          #13
                          I've just tried 500 msec delay between any order events and the strategy freezes again (but much later).
                          Only 1000 msec let it work (30 minutes uptime at the moment).

                          I am agreed, that 180 order per minute is too frequent.
                          Same time, not 180 per minute makes freeze.
                          It's 5-10 orders in a row with very small delay in-between (I am sure). This may happen each day on most instruments.

                          Maybe my PC is too slow?
                          RAM: 16Gb
                          CPU: i5-3770, 3.4GHz, 4 physical cores.
                          SSD
                          Attached Files
                          Last edited by fx.practic; 03-11-2020, 02:53 PM.
                          fx.practic
                          NinjaTrader Ecosystem Vendor - fx.practic

                          Comment


                            #14
                            I have a very similar issues with an unmanged and ignoreAllErrors strategy. Unlike you have have not created a small test strategy yet. Chart hangs occur often in realtime. Freeing the hang usually requires canceling an open intrabar order, then the chart spools the buffered data as your video shows. I have noticed that the same strategy only applied in the control center (no chart open) only consumes 1-3% of cpu bandwidth at peak realtime loads. Open a chart on the same instrument and the load goes to 25-30%. Apply the strategy to the chart and the system locks, with a single cpu at 100% (I have 4 on my box, so I see a constant 25% CPU consumed.

                            Comment


                              #15
                              lavalampmj - thanks a lot for sharing experience!
                              I can confirm than strategy that run in the Strategies grid in Control Centre consumes much less CPU - but only if there no any chart with same instrument and ChartTrader opened.

                              It looks, than orders visualisation grabs too much resources.
                              And I've just tried: in the grid the strategy freezes too.
                              And it froze whole ControlCenter also.
                              Global variable with the latest order event helps me now. I hope. I am ready to pray.

                              By the way, I add the timer object in the strategy.
                              It works well while strategy is frozen. And it clearly show that OnBarUpdate() just not triggered: CurrentBar is the same.
                              fx.practic
                              NinjaTrader Ecosystem Vendor - fx.practic

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by chbruno, Today, 04:10 PM
                              0 responses
                              1 view
                              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
                              5 views
                              0 likes
                              Last Post FAQtrader  
                              Started by rocketman7, Today, 09:41 AM
                              5 responses
                              19 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by frslvr, 04-11-2024, 07:26 AM
                              9 responses
                              127 views
                              1 like
                              Last Post caryc123  
                              Working...
                              X