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

Change CalculationMode for sometime (during active orders)

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

    Change CalculationMode for sometime (during active orders)

    Hi NinjaTrader Team!

    First thanks for making such a good product possible. It's the best programming engine I've seen so far.

    Now to my question:
    I coded an trading strategy for creating orders based on bars close. So calculation mode is set to OnBarClose wich works fine so far. Now, when I submitted an EntryOrder I need to keep track of price changes, for example for trade cancelation when the signal is no longer valid (if not already executed).

    How could I achive that?
    Is there something like a OnTick Event I could subscribe on during the time I have any working orders?
    I don't want to change the hole calculationMode to OnPriceChanged if there is a better or simple solution.

    Thanks in advance,
    Johnny

    #2
    Hello Johnny90,

    Welcome to the NinjaTrader support forums.

    Generally, in this case, you would need to change to using OnEachTick or OnPriceChange. If you are just trying to keep track of something you may be able to use OnMarketData instead of changing the calculation mode. This would only work in realtime though, so if you needed historical results based on this information you would either not be able to or would have to make separate logic for TickReplay.




    This override could be used to observe the live data which is called frequently so you could also use this to execute logic frequently.

    Alternatively, if you change the Calculation mode, you can also use IsFirstTickOfBar to simulate OnBarClose while working tick by tick.




    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks Jesse, that's enough so far.

      One off-topic thing: On manual trading with IB I'm able to attach a stop loss order to the entry order. So if the entry order is executed the stop loss order is immediately active. When I use the SetStopLoss() method I'm just wondering: Is the order immediately send to the broker's side or gets the order send to the broker after the entry order is triggered?

      Best regards,
      Johnny

      Comment


        #4
        Hello Johnny,

        When using SetStopLoss, the stop loss would be sent as upon the entry filling. As this is part of the managed approach the stop would be handled internally without other logic needed in the script. This can be configured once at the start of the script be to have a set value away from the entry or you can use this in your logic where you would like.

        You can find further information about SetStopLoss and the other "Set" methods in the help guide:
        https://ninjatrader.com/support/help...ub=setstoploss

        Stop loss orders are submitted in real-time on incoming executions from entry orders
        I look forward to being of further assistance.
        Last edited by NinjaTrader_Jesse; 12-19-2018, 08:08 AM.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks Jesse,
          so is there a way to attach the stop order to the entry order if the Broker supports this?

          Best regards,
          Johnny

          Comment


            #6
            Hello Johnny90,

            Thank you for the reply.

            Is there a specific feature that you are referring to with your broker that you can provide the name of?

            In NinjaScript, the Managed order entry system uses "Signal Name" and "From Entry Signal" to link entries and exits together so this could be used to logically associate orders. This is described in parent page to the link I had provided in the last post, https://ninjatrader.com/support/help...d_approach.htm (How to close a position section)

            There is a small sample that shows how the signal name can be used to exit and link the exit with a specific entry.


            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Hi Jesse,
              yes the managed approach works fine the difference is that in IBs TWS I'm able to attach the stop loss to the entry order and send both to the Broker. In case of connection loss the stop order gets activated on the Brokers side immidiatly after the order ist triggered.
              But when using SetStopLoss () and a connection loss occurs during the time the order gets triggered the position is not secured until the Connection is reetablished am I right?

              Best regards,
              Johnny

              Comment


                #8
                Hello Johnny90,

                the stop order gets activated on the Brokers side immediately after the order is triggered.
                In this case what you are describing would not necessarily be a feature that NinjaTrader would have, this would likely be more of a broker-specific feature that IB offers. Do you know the name of this specific order type in TWS where the order is activated upon filling the entry at the broker end with IB? I would like to review this and submit a feature request where I can.

                You are also correct if your connection were to be interrupted before the entry fills the script would be unable to do other actions until it reconnects. The entry is submitted to the broker but NinjaTrader is working as a radio waiting to receive feedback from the broker for further actions. If you are disconnected, you cannot have this feedback. If the disconnect happened after the stop submitted, that would reside with the broker in most cases so that would still protect a position but the platform would have no control or other feedback while disconnected. This is, of course, a situation to use the emergency trade desk number (if offered) to manage your account.

                If the connection is a major concern or ongoing problem we generally suggest using a VPS (virtual private server) that has a reliable connection so that you do not need to severely consider this in your logic. You can remote into the server to manage NinjaTrader from any PC that supports remote desktop which is an added benefit of this use case.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Hi Jesse,
                  I don't know how this feature is called but I attached a small screenshot from my TWS mobil where you can see that the stop loss can get attached to the entry order. The status is then blue(working order received by broker but condition not met) and when the entry order is filled the stop loss order turn to green(order active and running). This works even the connection is lost or I close the TWS mobile instance so I guess both orders are send to the broker. In TWS desktop there's the same functionality. Would be very great to have this feature in NT strategies.

                  Thanks for the help so far,
                  Michael

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by bortz, 11-06-2023, 08:04 AM
                  47 responses
                  1,602 views
                  0 likes
                  Last Post aligator  
                  Started by jaybedreamin, Today, 05:56 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post jaybedreamin  
                  Started by DJ888, 04-16-2024, 06:09 PM
                  6 responses
                  18 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Started by Jon17, Today, 04:33 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post Jon17
                  by Jon17
                   
                  Started by Javierw.ok, Today, 04:12 PM
                  0 responses
                  12 views
                  0 likes
                  Last Post Javierw.ok  
                  Working...
                  X