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

Our Chart freezes when sending a market order in 10 Ticks timeframe

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

    Our Chart freezes when sending a market order in 10 Ticks timeframe

    Hi NT support team,

    We finished developing our automated Strategy and run it from money account in production (MES 12-21). However we've been having a number of strategy freezes (and the chart also freezes), every time it submitted a trade to the server:
    - The output screen stops right at the order submission time.
    - The chart doesn't draw more (just stalls), and we cannot follow the evolution of the trade.
    - We can still disable the strategy there, and disconnect the connection successfully
    - However at that point some NT processes hang and it cannot reconnect again.
    Of course the order is in the server so it progresses and finishes correctly.

    Our strategy does all the calculation in 1000 Ticks, and moves to 10 Tick timeframe to chase the price and submit a simple market order (this way we avoid they problems we had with stop and limit orders). It seems to me the problem could be there - in the switch from one timeframe (1000 Ticks) to the other (10 Ticks) to submit the trade? This is the function that finally submits it:

    Code:
    else if (State == State.Configure)
    {
    // To manage the order to be submitted in great detail
    AddDataSeries(Data.BarsPeriodType.Tick, 10);
    
    CommonStatic.PS = this;
    DecisionMaker.Initialize();
    
    ScreenOut.Print(this, "FullCycleBaseStrategy.OnStateChange :: DEBUG :: After Configure");
    }
    
    [...]
    
    internal static Order[] EndOfBarEnterLongNOrders10Tick(Strategy strategy, int numOrders)
    {
    var orders = new Order[numOrders];
    
    if (CommonStatic.PS.Close[0] >= DesiredEntryPriceUp)
    {
    int newNumContracts = (NumContracts / numOrders);
    orders[0] = CommonStatic.PS.EnterLong(newNumContracts, "Order0");
    ScreenOut.Print(CommonStatic.PS, "OrderGenerator.EndOfBarEnterLongNOrders10Tick :: DEBUG :: Order0 submitted.");
    
    Activate10TickOrderUp = false;
    VV.OrderTypeToSubmit = FullCycleOrderType.NoOrder;
    }
    return orders;
    }
    And attached you can find the logs/trace for the last order submitted, last Friday - 19 Nov at 14:30:02

    Please advice. Thanks,


    Alberto.
    Attached Files

    #2
    Hello alrafer,

    From the given sample there is not much that could be observed as a reason for a freeze. The custom method does point toward the script being more complex thus requiring further debugging to find the specific reason.

    I would suggest as a starting point to take just the type of order being submitted that freezes and build a new empty strategy which tries to submit that type of order in realtime. Discard all existing logic you have made and just start with a basic order submission and see if that also fails. If it does you can try re installing the platform and testing from a clean user folder. If it does not and that works you could use that as a starting point to form it to be more like the existing script until you see the problem. Once you identify the specific code that causes a problem we could try to go over that directly.

    Please let me know if I may be of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks for your answer Jesse,

      That's an idea yep. The problem used to happen only in real trading (with the money account) but today I made a mistake, enabled the strategy with a SIM account and it also froze when submitted a trade. We can test that way easier, given it's the SIM account.
      We'll do several tests and come back to you with any further questions, if any.

      Best,


      Alberto.

      Comment


        #4
        Hi Jesse,

        Few more bits of info after some testing over the last days.
        - I reinstalled NT, and even if in the beginning it seemed to work OK it started failing again, soon. New NT version (late October one) on Windows 10.
        - The chart freezes after submitting a market order on SIM or Real accounts. Not always, but most of the times.
        - Once the order is submitted and filled, it doesn't seem to get the Stop Loss and Profit Target orders submitted right after it, so it evolves freely and I need to shut down NT and restart it to be able to fully close the position, even if this was shown in the Script Output:

        OrderGenerator.EndOfBarEnterLongNOrders1Tick :: DEBUG :: NumContracts 146, numOrders 1
        orderId='5e06f6377134471fafe443b5f9dcea5c' account='Sim101' name='Order0' orderState=Submitted instrument='MES 12-21' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=146 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=35 time='2021-12-09 14:54:18' gtd='2099-12-01' statementDate='2021-12-09'
        OrderGenerator.EndOfBarEnterLongNOrders1Tick :: DEBUG :: Order0 submitted.
        FullCycleBaseStrategy.OnBarUpdate :: DEBUG :: Order assigned to Trend (Up).
        orderId='5e06f6377134471fafe443b5f9dcea5c' account='Sim101' name='Order0' orderState=Accepted instrument='MES 12-21' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=146 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=35 time='2021-12-09 14:54:18' gtd='2099-12-01' statementDate='2021-12-09'
        orderId='5e06f6377134471fafe443b5f9dcea5c' account='Sim101' name='Order0' orderState=Working instrument='MES 12-21' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=146 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=35 time='2021-12-09 14:54:18' gtd='2099-12-01' statementDate='2021-12-09'
        orderId='5e06f6377134471fafe443b5f9dcea5c' account='Sim101' name='Order0' orderState=PartFilled instrument='MES 12-21' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=146 tif=Gtc oco='' filled=67 averageFillPrice=4687 onBehalfOf='' id=35 time='2021-12-09 14:54:18' gtd='2099-12-01' statementDate='2021-12-09'
        orderId='fce34d7f022146958c0c456f978f671f' account='Sim101' name='Stop loss' orderState=Submitted instrument='MES 12-21' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=4683.5 quantity=67 tif=Gtc oco='f219c6846eeb465b849afcf76db82c19' filled=0 averageFillPrice=0 onBehalfOf='' id=36 time='2021-12-09 14:54:18' gtd='2099-12-01' statementDate='2021-12-09'
        orderId='1074954fcefb4670a868d2483e0d5be0' account='Sim101' name='Profit target' orderState=Submitted instrument='MES 12-21' orderAction=Sell orderType='Limit' limitPrice=4693.75 stopPrice=0 quantity=67 tif=Gtc oco='f219c6846eeb465b849afcf76db82c19' filled=0 averageFillPrice=0 onBehalfOf='' id=37 time='2021-12-09 14:54:18' gtd='2099-12-01' statementDate='2021-12-09'
        BaseStrategy:OnExecutionUpdate :: DEBUG :: Execution.Price: 4687

        orderId='5e06f6377134471fafe443b5f9dcea5c' account='Sim101' name='Order0' orderState=Filled instrument='MES 12-21' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=146 tif=Gtc oco='' filled=146 averageFillPrice=4687.1352739726 onBehalfOf='' id=35 time='2021-12-09 14:54:18' gtd='2099-12-01' statementDate='2021-12-09'
        orderId='fce34d7f022146958c0c456f978f671f' account='Sim101' name='Stop loss' orderState=Accepted instrument='MES 12-21' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=4683.5 quantity=67 tif=Gtc oco='f219c6846eeb465b849afcf76db82c19' filled=0 averageFillPrice=0 onBehalfOf='' id=36 time='2021-12-09 14:54:18' gtd='2099-12-01' statementDate='2021-12-09'
        orderId='1074954fcefb4670a868d2483e0d5be0' account='Sim101' name='Profit target' orderState=Accepted instrument='MES 12-21' orderAction=Sell orderType='Limit' limitPrice=4693.75 stopPrice=0 quantity=67 tif=Gtc oco='f219c6846eeb465b849afcf76db82c19' filled=0 averageFillPrice=0 onBehalfOf='' id=37 time='2021-12-09 14:54:18' gtd='2099-12-01' statementDate='2021-12-09'
        orderId='1074954fcefb4670a868d2483e0d5be0' account='Sim101' name='Profit target' orderState=Working instrument='MES 12-21' orderAction=Sell orderType='Limit' limitPrice=4693.75 stopPrice=0 quantity=67 tif=Gtc oco='f219c6846eeb465b849afcf76db82c19' filled=0 averageFillPrice=0 onBehalfOf='' id=37 time='2021-12-09 14:54:18' gtd='2099-12-01' statementDate='2021-12-09'

        I'll continue to test in the direction you pointed me to, even if it's a little hard given our strategy has a lot of code (a full workflow behind it in many classes).

        Thanks,

        Alberto.

        Comment


          #5
          Quick question Jesse, or Kate: Is there a way to get more debug messages/info when I submit and order like this:

          var Order;

          Order = CommonStatic.PS.EnterLong(newNumContracts, "Order0");
          , other than printing the order state in OrderUpdate(), with ScreenOut.Print(this, Order.ToString()); ?

          Thanks.

          Comment


            #6
            Hello alrafer,

            There is TraceOrders which can be overridden with OnOrderTrace for customizing the output to your liking, but I am not certain this would help in pointing out where the strategy is freezing.

            TraceOrders - https://ninjatrader.com/support/help...aceorders2.htm

            I am in agreeance with Jesse that troubleshooting the freeze should look into what specifically triggers the freeze, and isolating that in a separate script. If we end up with something that is digestible for our staff to pick up and understand that reproduces the freeze we may have additional suggestions, and if we identify behavior that is suspected to be a platform side issue, we would be better able to confirm and get that reported.
            JimNinjaTrader Customer Service

            Comment


              #7
              Thanks for your answer Jim - it looks interesting and I will enable it asap on my test script.

              The problem with that approach - "isolating that in a separate script", is that the freezes seem to be erratic: In the Test account sometimes they happen and sometimes they don't. In the Real money account they happen more often - but I don't want to test on this one for obvious reasons - real money wasted.
              I need to find a way to reproduce the error consistently, which will expedite my progress, enabling me also to follow your suggestion. Working on that atm; the OnOrderTrace might surface up extra clues in the meantime.

              Comment


                #8
                Originally posted by alrafer View Post
                Thanks for your answer Jim - it looks interesting and I will enable it asap on my test script.

                The problem with that approach - "isolating that in a separate script", is that the freezes seem to be erratic: In the Test account sometimes they happen and sometimes they don't. In the Real money account they happen more often - but I don't want to test on this one for obvious reasons - real money wasted.
                I need to find a way to reproduce the error consistently, which will expedite my progress, enabling me also to follow your suggestion. Working on that atm; the OnOrderTrace might surface up extra clues in the meantime.
                Because you set stop and limit prices to -1

                Comment


                  #9
                  Thanks for taking the time to check this and reply fut_practic . However not sure if I follow... Where do you see that -1?

                  Thks again!

                  Comment


                    #10
                    Ok, I got this fixed finally yesterday NinjaTrader_Jesse . We were sending an email notification from OnOrderUpdate() - after exiting - using our own implementation, and the "await" call (see below) never gets a response, therefore freezing the chart. See here:

                    Code:
                    private static async Task SendMessageToEmail(string subject, string emailContent)
                    {
                    CommonStatic.InitializeStatics();
                    var payload = new EmailMessage { Content = emailContent, Subject = "[" + DateTime.Now + "]" + " - " + subject };
                    
                    var cont = new JavaScriptSerializer().Serialize(payload);
                    HttpContent content = new StringContent(cont, Encoding.UTF8, "application/json");
                    await CommonStatic.Client.PostAsync(CommonStatic.Url, content);
                    }
                    Once we swapped this for NT SendMail() everything worked well.

                    Thanks for your support.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by junkone, Today, 11:37 AM
                    0 responses
                    6 views
                    0 likes
                    Last Post junkone
                    by junkone
                     
                    Started by quantismo, 04-17-2024, 05:13 PM
                    5 responses
                    35 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by proptrade13, Today, 11:06 AM
                    1 response
                    6 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by love2code2trade, 04-17-2024, 01:45 PM
                    4 responses
                    34 views
                    0 likes
                    Last Post love2code2trade  
                    Started by cls71, Today, 04:45 AM
                    2 responses
                    10 views
                    0 likes
                    Last Post eDanny
                    by eDanny
                     
                    Working...
                    X