Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OCO orders

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

    #16
    Hello,

    Thank you for the answer and useful tips. I familiar with these examples.
    Zachary, I do not ask you to recommend me how to implement the code. I am not new in programming!

    I think, you don't clearly get the point of the question.

    My question is how to use one part (= looking for the sygnal) of logic with CalculateOnBarClose = true and another part (=managing orders) of logic with CalculateOnBarClose = false at the same time inside OnBarUpdate() method?
    Last edited by akushyn; 04-13-2016, 12:22 PM.

    Comment


      #17
      Hello akushyn,

      You would not be able to specify CalculateOnBarClose to true for one portion of OnBarUpdate() and another portion to false in OnBarUpdate().

      However, what you can do is this:

      Set CalculateOnBarClose to false.
      Place any logic that you would like to occur only at the first tick of a bar within an if (FirstTickOfBar). This would be akin to running CalculateOnBarClose = true.

      Code:
      if (FirstTickOfBar)
      {
           // do stuff
      }
      Anything outside of that FirstTickOfBar if statement will evaluate on every tick (CalculateOnBarClose = false).

      For more information about FirstTickOfBar, please take a look at this help guide link: https://ninjatrader.com/support/help...ttickofbar.htm
      Zachary G.NinjaTrader Customer Service

      Comment


        #18
        Originally posted by NinjaTrader_ZacharyG View Post
        Hello akushyn,

        You would not be able to specify CalculateOnBarClose to true for one portion of OnBarUpdate() and another portion to false in OnBarUpdate().

        However, what you can do is this:

        Set CalculateOnBarClose to false.
        Place any logic that you would like to occur only at the first tick of a bar within an if (FirstTickOfBar). This would be akin to running CalculateOnBarClose = true.

        Code:
        if (FirstTickOfBar)
        {
             // do stuff
        }
        Anything outside of that FirstTickOfBar if statement will evaluate on every tick (CalculateOnBarClose = false).

        For more information about FirstTickOfBar, please take a look at this help guide link: https://ninjatrader.com/support/help...ttickofbar.htm
        Thank you for the quick reply.
        I just want you to specify about the FirstTickOfBar.

        Right now, I use property CalculateOnBarClose set to true, so I use last tick of bar.
        * Is there a way to get last tick of previous bar , cause I use values of High, Close, Low series of the last closed bar?

        Comment


          #19
          Hello akushyn,

          With CalculateOnBarClose = false, you will be able to access the previous High, Close, Low, etc. in the FirstTickOfBar if statement by specifying a barsAgo index of 1 (i.e. High[1], Close[1], etc).

          Do remember that this will only apply when running in real-time. When your script is evaluating historically, it will run as if CalculateOnBarClose = true.
          Zachary G.NinjaTrader Customer Service

          Comment


            #20
            Originally posted by NinjaTrader_ZacharyG View Post
            Hello akushyn,

            With CalculateOnBarClose = false, you will be able to access the previous High, Close, Low, etc. in the FirstTickOfBar if statement by specifying a barsAgo index of 1 (i.e. High[1], Close[1], etc).

            Do remember that this will only apply when running in real-time. When your script is evaluating historically, it will run as if CalculateOnBarClose = true.
            Hello, Zachary and thank you for the answer.
            I left the logic with FirstTickOfBar for further improvements, cause such approach impossible to back test.

            I'e played a bit with orders and the logic to find entry signal works fine.
            But sometimes when I receive StopLoss and then new signal appear I get Terminated strategy message. (see attached pics)

            The strategy tries to Sell above the market with strange price.
            I debug a lot and found that this is the "ENTRY PRICE" of the last StopLoss (see attached prints of the Output window)

            So, to eliminate such crashes I need to handle it somehow (set to null object position, empty values etc) .

            The question is , how to check that the order has been closed by StopLoss?
            I want to implement if statement in OnExecute method to check such situation.

            What could you advise me to do?
            Attached Files

            Comment


              #21
              Hello akushyn,

              Thank you for your patience.

              If you wish to check if the stop loss has been executed, you can check for the stop loss in OnExecution().

              Example:

              Code:
              protected override void OnExecution(IExecution execution)
              {
                   if (execution.Order.Name == "Stop loss")
                        // do something
              }
              Please, let us know if we may be of further assistance.
              Zachary G.NinjaTrader Customer Service

              Comment


                #22
                Originally posted by NinjaTrader_ZacharyG View Post
                Hello akushyn,

                Thank you for your patience.

                If you wish to check if the stop loss has been executed, you can check for the stop loss in OnExecution().

                Example:

                Code:
                protected override void OnExecution(IExecution execution)
                {
                     if (execution.Order.Name == "Stop loss")
                          // do something
                }
                Please, let us know if we may be of further assistance.
                Thank you, Zachary! Will try and tell you the result )

                Sometimes, when I replay the market I get gaps of the price during placing the entry order.
                How to avoid crash in such situations?

                Lets green bar represents a signal bar.
                To enter the market, I place buy stop order on the price = High + Ticksize.
                When next bar appear, the open price is above the entry price of the order.

                The question, is it OK to place buy order below the price?
                If answer No, so how could I overcome it?

                In more details what I mean, I've explained , graphically in attached picture.
                Attached Files

                Comment


                  #23
                  Hello akushyn,

                  You would be able to place a buy limit order below the market rather than a buy stop/buy stop limit order below the market. Alternatively, you can place a buy market order if you wish to enter at the current market price. You can check if the current market price is greater than your buy stop price before attempting to enter with a buy stop.

                  A more advanced method would be disabling RealtimeErrorHandling and programming your own order rejection handling.

                  To avoid the strategy from being disabled when your stop order is being placed below the market, what you could do is provide logic to instead place a buy limit or buy market order if the order is rejected. You'll need to disable RealtimeErrorHandling though: http://ninjatrader.com/support/helpG...orhandling.htm

                  Please, remember that setting this property value to "TakeNoAction" can have *serious* adverse affects on a running strategy unless you have programmed your own order rejection handling in the OnOrderUpdate() method.

                  Please, let us know if we may be of further assistance.
                  Zachary G.NinjaTrader Customer Service

                  Comment


                    #24
                    Originally posted by NinjaTrader_ZacharyG View Post
                    Hello akushyn,

                    You would be able to place a buy limit order below the market rather than a buy stop/buy stop limit order below the market. Alternatively, you can place a buy market order if you wish to enter at the current market price. You can check if the current market price is greater than your buy stop price before attempting to enter with a buy stop.

                    A more advanced method would be disabling RealtimeErrorHandling and programming your own order rejection handling.

                    To avoid the strategy from being disabled when your stop order is being placed below the market, what you could do is provide logic to instead place a buy limit or buy market order if the order is rejected. You'll need to disable RealtimeErrorHandling though: http://ninjatrader.com/support/helpG...orhandling.htm

                    Please, remember that setting this property value to "TakeNoAction" can have *serious* adverse affects on a running strategy unless you have programmed your own order rejection handling in the OnOrderUpdate() method.

                    Please, let us know if we may be of further assistance.
                    Thank you! I guess I got your thought.

                    What do you think?
                    Could it be a good idea to implement catching exception of the rejection smth like this below

                    Place buy stop limit order
                    1) if rejected - catch the situation and place buy limit on the same price
                    2) if Ok - then TODO smth

                    Code:
                    			try
                    			{
                    				entryLongOrder = EnterLongStopLimit(0,true, 1, limitPrice, stopPrice, name);
                    			}
                    			catch (RejectionException)
                    			{
                    				entryLongOrder = EnterLongLimit(0,true, 1, limitPrice, name);
                    			}
                    In that case, I need to know the name of the Exception which responsible for the rejection state of the order. And as I understand correctly, we could avoid disabling RealtimeErrorHandling.

                    Comment


                      #25
                      Hello akushyn,

                      I would suggest taking a look at the example provided in the RealtimeErrorHandling documentation: https://ninjatrader.com/support/help...orhandling.htm

                      If the OrderState is Rejected, submit an EnterLongLimit() order. Take a look at the OnOrderUpdate() method in that help guide link.
                      Zachary G.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by llanqui, Yesterday, 03:51 PM
                      6 responses
                      26 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by tradingnasdaqprueba, Today, 03:42 AM
                      8 responses
                      32 views
                      0 likes
                      Last Post tradingnasdaqprueba  
                      Started by manueldecastro, Today, 01:16 PM
                      0 responses
                      1 view
                      0 likes
                      Last Post manueldecastro  
                      Started by AlgoDreamer, Today, 12:39 PM
                      2 responses
                      8 views
                      0 likes
                      Last Post AlgoDreamer  
                      Started by ninza33, Today, 12:31 PM
                      1 response
                      4 views
                      0 likes
                      Last Post NinjaTrader_LuisH  
                      Working...
                      X