Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ExitLongLimit Conditions

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

    ExitLongLimit Conditions

    Hello,

    to work with conditions for limits in scripts I can find in the helpguide the example for exitlonglimit(exitshortlimit) with cross of SMA and this is clear how to add to the script. But what has one to do for having the exitlonglimit

    a.) with High[0] && Close[0]

    b.) GetCurrentAsk() = DonchianChannel

    I can not derive this from the example with SMA.

    Thank you
    Tony

    #2
    Hello,

    It sounds like you are on the right track. ExitLongLimit() has several constructor overloads (several sets of parameters it can take). The simplest one, which you've referenced, only takes a single argument, which must be a "double," and that will be used as the limit price.

    So, you can pass any variable, collection index, or method that will return a double to pass in to the constructor. High[0] and Close[0] both return a double, so you could just do ExitLongLimit(High[0]) or ExitLongLimit(Close[0]) to place the order at the current High or the current Close (the current price, if we're using 0 as the index).

    I'm a bit confused by your example B. Can you please clarify what you are trying to do there? GetCurrentAsk() is a method with a return value, so you will not be able to assign a value to it the way that you currently have it coded in that example.

    I look forward to your reply.
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Hello Dave,

      thank you for your reply.

      In example b.) I mean how to use the "normal" exit condition like
      GetCurrentBid() >= Instrument.MasterInstrument.Round2TickSize(Donchia nChannel(BarsArray[5], 21).Upper[0])

      as a limit?


      Thank you
      Tony

      Originally posted by NinjaTrader_Dave View Post
      Hello,

      It sounds like you are on the right track. ExitLongLimit() has several constructor overloads (several sets of parameters it can take). The simplest one, which you've referenced, only takes a single argument, which must be a "double," and that will be used as the limit price.

      So, you can pass any variable, collection index, or method that will return a double to pass in to the constructor. High[0] and Close[0] both return a double, so you could just do ExitLongLimit(High[0]) or ExitLongLimit(Close[0]) to place the order at the current High or the current Close (the current price, if we're using 0 as the index).

      I'm a bit confused by your example B. Can you please clarify what you are trying to do there? GetCurrentAsk() is a method with a return value, so you will not be able to assign a value to it the way that you currently have it coded in that example.

      I look forward to your reply.

      Comment


        #4
        Hello,

        That particular snippet returns a boolean value (true or false). What you are doing there is evaluating whether or not the current Bid is greater than or equal to that indicator value, which the code would return as either true or false. So you could not pass this in to an order-entry method. ExitLongLimit() needs a double (a number with decimal places, such as 23.45, etc.).

        The way you would use the code you shared would be to determine when to place the limit order, rather than where to place it. For example, you could do something like this:

        if(GetCurrentBid() >= Instrument.MasterInstrument.Round2TickSize(Donchia nChannel(BarsArray[5], 21).Upper[0])
        {
        ExitLongLimit(High[0])
        }

        In that code, you would be saying "if the current Bid is greater than or equal to this indicator value, then place a limit order at the current High to exit my position."
        Dave I.NinjaTrader Product Management

        Comment


          #5
          Hello,

          thank you again for your accurate help. All clear.

          I want to do another question in this concern please: is it possible to place a "normal" entrylimit but to give a second chance for an entry if limit is not filled?

          So, the optimum is that it is filled at the limit. But if eg the entrylonglimit(X) is not filled eg because late placing the order then I´ll be happy with entrylonglimit(X+1 Tick)

          a.) what do I have to add in the script for having this solution

          and if this might not be possible I want to ask

          b.) how I can cancel a limit-order that was not filled at its price? (because if a.) is not possible then I send a market order if the limit was not filled and with this the limitentry should be cancelled - but when writing these lines now I think this will not be a problem with 2 entries because I can avoid double entry with entry handling. Correct?)

          I hope I could translate and explain my idea.

          Thank you
          Tony

          Comment


            #6
            Hello,

            You should be able to accomplish either of these setups. For either idea, you could first assign your limit order to an IOrder object, then check both the price and the Filled property of that IOrder object:

            Code:
            IOrder entry = EnterLongLimit(limitPrice);
            
            if (Close[0] < limitPrice && entry.Filled == false)
            {
               CancelOrder(entry);
            
               if (entry.OrderState == OrderState.Cancelled) EnterLongLimit(entryPrice - 2 * TickSize);
            }
            For the second idea, you could replace the second limit entry with a market entry in the same place. By checking for the successful cancellation before submitting the new order, you can avoid any potential overfills or unexpected behavior.
            Dave I.NinjaTrader Product Management

            Comment


              #7
              Hello,

              thank you for your great support.

              But I´m getting confused with the logic in your solution: "...EnterLongLimit(entryPrice-2*TickSize)"?

              The limit will be probably not filled when price goes up (in the long example). So wouldn´t this be "+2*TickSize"?

              And with "By checking for the successful cancellation..." you refer only to my 2nd solution or this is necessary also for the code you posted here?

              Thank you for clearifying this.

              Tony

              Comment


                #8
                Hello,

                My first thought was +2 rather than -2, but wouldn't a Buy Limit order be placed below the market, meaning that if price passes through it, we would need to extend the limit window downward rather than upward? Regardless, it sounds like you've got the right idea for what you are looking for.

                I would recommend checking for the cancellation before placing the new order using either idea that we're talking about -- or any situation in which you are replacing one entry order with another. Otherwise, the following sequence can easily happen:

                1) The first order cancellation is sent
                2) The second entry order is placed
                3) The first and second order get filled before the cancellation has been processed for the first order
                4) The cancellation returns an error, and you are now in a double-sized position

                Checking for the cancellation can avoid the headache of trying to track this scenario down if you get an overfill.
                Dave I.NinjaTrader Product Management

                Comment


                  #9
                  Hello Dave,

                  thank you for your support.

                  A question concering checking for cancellation. For "normal" entries (not the special situation here above with missing the limit) should one do for every entryorder in onExecution

                  if (entryOrder != null && entryOrder == execution.Order)
                  {if (execution.Order.OrderState == OrderState.Filled)
                  entryOrder = null;
                  cancelOrder(entryOrder); ????

                  Or is this not necessary? Is it enough to do "entryOrder=null;" or one needs to add "cancelOrder(entryOrder)"?

                  Thank you
                  Tony


                  {

                  Comment


                    #10
                    Under normal circumstances, simply checking to see if the IOrder object is null should do the job for you. I would only explicitly cancel the order if you know for a fact that it has not been filled, and you want to replace it.
                    Dave I.NinjaTrader Product Management

                    Comment


                      #11
                      Dave,

                      in the meantime I tested with sim datafeed different codings referring the Iorder handling and I have a last question please: when I set the limit to enterlonglimit=High[0] and the price continues rising then immediately, the same second, I see in the orders tab the enterlonglimit order is cancelled.

                      I have nothing in the script to do so if price is not filled and even not when flat! Why is the entryorder immediately cancelled please?

                      Thank you
                      Tony

                      Originally posted by NinjaTrader_Dave View Post
                      Under normal circumstances, simply checking to see if the IOrder object is null should do the job for you. I would only explicitly cancel the order if you know for a fact that it has not been filled, and you want to replace it.

                      Comment


                        #12
                        That is interesting. When this happens, do you see any error messages in the Log tab of the Control Center? If you can replicate this issue with a NinjaScript Output Window open, do any messages appear in the Output Window?
                        Dave I.NinjaTrader Product Management

                        Comment


                          #13
                          Dave,

                          no error in log tab. I did some entries in sim and cut the relevant lines from output window for one example (order appeared, then working, then cancelled):

                          **NT** Enabling NinjaScript strategy 'tkaxLxES/95a7f134f43d4b2d874e544197735ec5' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=UniqueEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True CalculateOnBarClose=True MaxRestarts=4 in 5 minutes
                          04.06.2015 18:56:06 Entered internal PlaceOrder() method at 04.06.2015 18:56:06: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=4495,25 StopPrice=0 SignalName='iLa' FromEntrySignal=''
                          04.06.2015 18:56:06 Entered internal PlaceOrder() method at 04.06.2015 18:56:06: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=4495,25 StopPrice=0 SignalName='iLb' FromEntrySignal=''
                          04.06.2015 18:56:06 Entered internal PlaceOrder() method at 04.06.2015 18:56:06: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=4495,25 StopPrice=0 SignalName='iLc' FromEntrySignal=''
                          04.06.2015 18:56:06 Cancelled expired order: BarsInProgress=1: Order='da9bbdef1deb47a0a93892904f930abb/Sim101' Name='iLa' State=Working Instrument='NQ 06-15' Action=Buy Limit price=4495,25 Stop price=0 Quantity=1 Strategy='tkaxLxES' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='da9bbdef1deb47a0a93892904f930abb' Gtd='01.12.2099 00:00:00'
                          04.06.2015 18:56:06 Cancelled expired order: BarsInProgress=1: Order='5698c1bb04154ade9b67d2c10dd034c3/Sim101' Name='iLb' State=Working Instrument='NQ 06-15' Action=Buy Limit price=4495,25 Stop price=0 Quantity=1 Strategy='tkaxLxES' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='5698c1bb04154ade9b67d2c10dd034c3' Gtd='01.12.2099 00:00:00'
                          04.06.2015 18:56:06 Cancelled expired order: BarsInProgress=1: Order='7f1d9aba66ea4f65ad987ff7fb3cc965/Sim101' Name='iLc' State=Working Instrument='NQ 06-15' Action=Buy Limit price=4495,25 Stop price=0 Quantity=1 Strategy='tkaxLxES' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='7f1d9aba66ea4f65ad987ff7fb3cc965' Gtd='01.12.2099 00:00:00'



                          Thank you
                          Tony

                          Comment


                            #14
                            Thank you for that. What's interesting there is that the internal PlaceOrder() notes refer to BarsInProgress = 0, which would be your primary data series to which the strategy is applied, but the cancellation orders refer to BarsInProgress = 1, indicating that is being processed on a secondary data series added to the script.

                            Can you please show me a snippet of your code that shows all of your order entry and exit logic, so that I can investigate further? If you wish to keep it private, feel free to email platform support and reference ticket # 1328919.
                            Dave I.NinjaTrader Product Management

                            Comment


                              #15
                              Hello Dave,

                              thank you for your reply. I sent to you an email about.

                              Thank you for your support.
                              Tony

                              Originally posted by NinjaTrader_Dave View Post
                              Thank you for that. What's interesting there is that the internal PlaceOrder() notes refer to BarsInProgress = 0, which would be your primary data series to which the strategy is applied, but the cancellation orders refer to BarsInProgress = 1, indicating that is being processed on a secondary data series added to the script.

                              Can you please show me a snippet of your code that shows all of your order entry and exit logic, so that I can investigate further? If you wish to keep it private, feel free to email platform support and reference ticket # 1328919.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by alifarahani, Today, 09:40 AM
                              6 responses
                              38 views
                              0 likes
                              Last Post alifarahani  
                              Started by Waxavi, Today, 02:10 AM
                              1 response
                              18 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by Kaledus, Today, 01:29 PM
                              5 responses
                              15 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by Waxavi, Today, 02:00 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by gentlebenthebear, Today, 01:30 AM
                              3 responses
                              17 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X