Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

7 years NinjaTrader - the most important question

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

    7 years NinjaTrader - the most important question

    Hello,

    I´m working for 7 year now with this great software and there is one problem more important than any question about coding or improvement of an indicator or script.

    Situation (like yesterday):

    * limitentry order working
    * NT frozen (it occurs with very high volume, but for whatever reason)
    * during that time when NT is frozen the limitorder is triggered and there is a trade running

    What about the stop?

    a.) Is it better (or to avoid a naked trade) to use ATM (from dom or charttrader) with setstoploss than to have setstoploss from a script? And if working with script (instead of ATM) does the setstoploss from script have the same "quality" as the stop from ATM (dom or charttrader)? (With an ATM (dom, chartrader) is the stop maybe on NinjaTrader Brokerage servers with the limitentry, so that when limitentry is filled then stop is always on exchange?)

    b.) if working with a script (instead of ATM) is it the same if using in the script setstoploss or exitlongstop(exitshortstop)? Both have same "quality"?

    c.) where should be setstoploss or exitlongstop in the script to avoid or to reduce the risk of a naked trade? In initialize or onExecution?

    I have used the last years all methods, but I´m not clear about this situation and I couldn´t find an answer in help guide or forum concerning this situaiton.


    THANK YOU!
    Tony
    Last edited by tonynt; 12-09-2015, 07:24 AM. Reason: title was not correct

    #2
    Hello Tony,

    Thank you for your note.

    a.) It is not necessarily better to have an ATM strategy from the SuperDOM or Chart Trader.
    The SetStopLoss and SetProfitTarget would use the position quantity.
    The stop and limit would be submitted to the brokers server. You can find information on where you orders reside at the following link: http://www.ninjatrader.com/support/f...ead.php?t=5349

    b.) ATM Strategies are not necessarily the same as SetStopLoss or ExitLongStop. ATM Strategies can involve Stop Strategies. In the case of ExitLongStop and SetStopLoss, you would need to implement any trailing stop or breakeven in your code (unless you use SetTrailStop).

    c.) I would set SetStopLoss in Intialize(), this would ensure that the stop is submitted on execution of the entry order. However, you still run the case where the order could execute on the broker and exchange server but NinjaTrader has already locked up and thus the SetStopLoss never sees the execution.
    For the ExitLongStop, you would want this to be set in another method other than Initialize() as it will not work in Initialize().

    With all this said I would troubleshoot the lock up/freezing on high volume. I would recommend improving the performance of NinjaTrader by implementing our performance tips from the following link: http://www.ninjatrader.com/support/h...ance_tips2.htm

    Some key items to focus on when it comes to performance in your workspaces are the following:
    • The DaysToLoad/BarsToLoad setting for your charts can be reduced to improve performance. This option is viewed when right clicking in your chart > selecting Data Series. For information on working with Price Data please visit the following link: http://www.ninjatrader.com/support/h...price_data.htm
    • The indicators on the chart have two options that can be set to improve performance. The CalculateOnBarClose option can be set to True to improve performance, and the MaximumBarsLookBack can be set to TwoHundredFiftySix (which is the default setting).
    • When right clicking in the chart and selecting Properties, you will find an option called Update Display Interval. This can be set to a higher value on charts you may not be viewing at all times to help improve performance. This will only delay the visual update and not the actual data or calculations of indicators or strategies.

    There is no one option to improve performance, and you may only need to use one of these settings on one chart.

    Please let me know if I may be of further assistance

    Comment


      #3
      Hello Patrick,

      thank you for your reply. (I know about where the stops reside and about moving stops)

      * So, I understand that there is no sure way that stop is with entry because stop can not be submitted with the limitentry to brokers server, correct?

      * What I dont see (or not understand, sorry) in your reply is if setstoploss in initialize is more safe than exitlongstop/exitshortstop in onExecution?

      * isn´t there one stop (I dont remember where I read this) that is earlier or more safe, or a stop that is working later only?

      * isn´t there a possibility to add to a script so if script detects a naked trade that it closes/flattens immediately? (for this functionality is it important if setstoploss or exitlongstop - so maybe this recognizes only setstoploss?)

      Thank you
      Tony
      Last edited by tonynt; 12-03-2015, 09:08 AM. Reason: translation error

      Comment


        #4
        Tony,

        Thank you for your follow up.

        1. The Stop Loss would only be submitted to the broker upon an execution report back from the broker that the limit entry had filled in this example.

        2. Initialize() will ensure the Stop Loss is submitted upon execution of the entry. So this would apply to the first item here and could be considered "safer" over other methods of submitting the Stop Loss.

        3. This would be the SetStopLoss() in the Initialize() method.

        4. This would involve would involve unsupported code in NinjaTrader 7 and would not be recommended as the performance would not be documented.
        In NinjaTrader 8, you can adopt the account position for the instrument the strategy is applied to and manage it from there.

        Comment


          #5
          Hello,

          one idea about the naked trade. What about a workround like

          if (entryorderlong...filled && stop != working) then exitlong().

          Does this make sense to get out of a naked trade as soon as possible automatically by script?

          But can I work this way with a setstoploss(). I know I can with exitlongstop from onExecution but referring to your information here the setstoploss from Initialize is more safe then exitlongstop from onExecution.

          Thank you
          Tony

          Comment


            #6
            Hello tonynt,

            What you can do is assign the stop loss to an IOrder object. In OnExecution(), you'll want to set the IOrder object to null.

            If SetStopLoss() was never called in the first place, the IOrder object will still be null.

            Example:
            Code:
            private IOrder theStopLoss = null;
            
            protected override void OnOrderUpdate(IOrder order)
            {
                 if (theStopLoss == null && order.Name == "Stop loss" && order.OrderState == OrderState.Working)
                      theStopLoss = order;
            }
            
            protected override void OnExecution(IExecution execution)
            {
                 if (theStopLoss != null && execution.Order.orderState == OrderState.Filled)
                      theStopLoss = null;
            }
            Then, just use a condition to check if a stop loss does not exist and you are in a long position. If this is the case, then exit.

            Example:
            Code:
            if (Position.MarketPosition == MarketPosition.Long && theStopLoss == null)
                 ExitLong();
            More information about IOrder objects, OnOrderUpdate(), and OnExecution() can be found in the following links below:


            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Hello,

              thank you for your reply. But this I can not do with SetStopLoss() which I can bring in best in "Initialize". Correct? This was the beginning of the thread - using a Setstoploss() or exitlingstop/exitshortstop. And from the replies here I understood that the "safer" way for a stop is with SetStopLoss() in Iniitialize.

              So, seems I have to decide if SetStoploss() in Initialize or Iorder exitlongstop with this I want to react to a naked position. Correct?

              Or does in your reply "If SetStopLoss() was never called in the first place, the IOrder object will still be null." means that I can use SetStopLos() and IOrder in same script and as stop for same longposition??

              Thank you
              Tony
              Last edited by tonynt; 12-05-2015, 10:12 AM. Reason: Clearifying

              Comment


                #8
                Hello tonynt,

                Thank you for your response.

                You could use both in a script. The code would be a bit different though as the Stop Loss would not be assigned an IOrder object that we could grab in OnExecution().

                So you would instead pull the execution.Name and if it equals "Stop loss".

                Comment


                  #9
                  Hello,

                  thank you for your reply. What means please "..and if it equals "Stop loss"?

                  And a question about "Then, just use a condition to check if a stop loss does not exist and you are in a long position. If this is the case, then exit."...
                  this should not be done in onExecution, right? Because when NT is frozen at the time of limitentry (= onExecution??) then the flat condition will not be checked and thefore no exit, correct? So the check should be in onBarUpdate, no?

                  We soon have resolved this important question.

                  Thank you
                  Tony
                  Last edited by tonynt; 12-07-2015, 12:39 PM. Reason: translating error

                  Comment


                    #10
                    Hello tonynt,

                    Thank you for your response.

                    Exactly, it's going to be something that is really unavoidable. You can implement logic to hopefully catch a naked position, but each event whether OnExecution() or OnBarUpdate() require an update from the data provider.

                    Initialize() would run off an execution, which would occur when the entry is filled. So this would be the "quickest" means. In this specific case, I would say the SetStopLoss() in Initialize() is the best means.

                    You may also wish to review the Risks of Electronic Trading: http://ninjatrader.com/support/helpG...trading_wi.htm

                    Comment


                      #11
                      Hello Patrick,

                      sorry when I could not translate accurately maybe what I mean.

                      When one wants to catch a naked trade in onExcution this might be missed and also in Initialize (as you write " Initialize would run off an execution") because during execution NT is frozen - otherwise there would not be a discussion about and the problem would not exist, no? If NT is not frozen all is fine, but if frozen then there is a,) no stop and b.) check and catch of naked does not work (from execution-related codes). Correct?

                      So, of course it makes sense to bring in the stoploss as quick as possible but the check of naked position should be in a non-execution related region, no? If this understanding is logical, where should the check for naked position be - in onbarupdate or onorderupdate? (I assume in onbarupdate as there is recognized a naked situation when NT is working again with every new bar, or if strategy is running COBCfalse then with every income tick)

                      ??

                      Best
                      Tony
                      Last edited by tonynt; 12-07-2015, 01:43 PM. Reason: clearifying, translation

                      Comment


                        #12
                        It does not matter in the case that it froze. As no event is going to get triggered.

                        Comment


                          #13
                          What means "As no event is going to get triggered."

                          Comment


                            #14
                            If NinjaTrader is frozen/locked up, how can an event (OnBarUpdate, OnExecution, OnPositionUpdate, etc.) be called? That is what I meant.

                            So no matter what, if the system is froze, there would not be a means to check the position to see if it truly was without protection.

                            Comment


                              #15
                              Hello,

                              thank you for your support!

                              Referring to your informations that I can not find a solution in the script (sounds logically!!!), in the meantime I setup with NinjaTrader Brokerage a 2nd access with CQG-Trader to my account. I´m running CQG-Trader on another machine and another internet connection.

                              The last question concering this topic would now be:

                              when entry-limit is filled (from exchange or NT-brokerage-server) while NT is frozen and therefore no stop is sent and no stop is working and because of this I close this trade from CQG-trader

                              and when NT is getting back to normal CPU usage does it send the stops ?? (for positions that are not there anymore?) so that there might be then an entry from the stops? Is there a difference if stop is in the script with SetStopLoss or ExitlongStop (with difference I mean if maybe one is sent without checking status and the other maybe checks if positions!=flat or the referring position is true)

                              Thank you
                              Tony
                              Last edited by tonynt; 12-09-2015, 11:29 AM. Reason: clearifying

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by CarlTrading, Yesterday, 11:51 AM
                              0 responses
                              18 views
                              0 likes
                              Last Post CarlTrading  
                              Started by CarlTrading, Yesterday, 11:48 AM
                              0 responses
                              23 views
                              0 likes
                              Last Post CarlTrading  
                              Started by CaptainJack, 03-25-2026, 09:53 PM
                              0 responses
                              27 views
                              0 likes
                              Last Post CaptainJack  
                              Started by CaptainJack, 03-25-2026, 09:51 PM
                              0 responses
                              15 views
                              0 likes
                              Last Post CaptainJack  
                              Started by Mindset, 03-23-2026, 11:13 AM
                              0 responses
                              21 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Working...
                              X