• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Mutiple entries not working in strategy develpment

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

    Mutiple entries not working in strategy develpment

    Hi all,

    I am trying to create a strategy using the ATR Trailing indicator found here https://ninjatraderecosystem.com/use...d/atrtrailing/

    my code is as follows

    ---------------------

    protected override void OnBarUpdate()
    {


    if (CurrentBar < ATRPeriod) return;

    if (( IsFlat || IsLong ) && ( Low[0] > _atrTrail.Lower[0] ) && _atrTrail.Upper[0] != 0)
    {
    this.EnterShortStopMarket(lots, _atrTrail.Upper[0], "Short 1");
    this.EnterShortStopMarket(lots, _atrTrail.Upper[0], "Short 2");
    }

    if ( (IsFlat || IsShort) && (High[0] < _atrTrail.Lower[0] ) && _atrTrail.Lower[0] != 0 )
    {

    EnterLongStopMarket(lots, _atrTrail.Lower[0], "Long 1");
    EnterLongStopMarket(lots, _atrTrail.Lower[0], "Long 2");
    }
    }

    ------------------------

    For some reason the 2nd order is only submitted in short direction and only once
    All orders thereafter are only Long 1 and Short 1

    I have
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.UniqueEntries;

    The idea is to use some form of profit target for one order and use a protective trailing stop for the 2nd one

    Any help is greatly appreciated.


    Ioannis


    #2
    Hello Ioannis,

    With UniqueEntries I would expect both orders (also this only prevents a new order after the position is taken).

    May I test the script?

    To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter a unique name for the file in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.
    http://ninjatrader.com/support/helpG...-us/export.htm

    Once exported, please attach the file as an attachment to your reply.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      Find below the strategy code as an attachment.

      The idea behind having two entries is to have a profit target for one and let the other run - hence the ATRTarget1 variable..

      Of course I have not been able to implement the idea as only one entry was executed.

      Rgrds

      Ioannis

      Attached Files

      Comment


        #4
        Any updates on the support side on why the platform is not working as it should? Still waiting for an answer !

        Comment


          #5
          Hello Ioannis,

          I'm still looking into this and I've forwarded an inquiry to our development as I'm not seeing the order is ignored from TraceOrders, nor do I see the order initialized in OnOrderUpdate().

          I will keep you in on the loop once I have more information.

          I appreciate your patience.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hello,

            more than 20 days have passed, since the last message from support. Do we have an update? I suppose it is a programming issue with the platform?

            Comment


              #7
              Hello Ioannis,

              This is still being discussed between our support and our development to determine if the behavior is expected due to the internal order handling rules.

              "Methods that generate orders to enter a position will be ignored if: A position is open and an order submitted by a non market order exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction."

              I apologize for the amount of time it is taking to resolve this inquiry and I really do appreciate your patience.
              Last edited by NinjaTrader_ChelseaB; 09-11-2019, 09:14 AM.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hello Chelsea,

                assuming it is an "expected behavior" what would be the way around the problem?

                There surely must be a way to code this simple strategy .

                Regards

                Ioannis

                Comment


                  #9
                  Hello Ioannis,

                  If it does turn out to be expected, you may need to wait until the first working order fills before placing the second.

                  Or use the unmanaged approach.

                  Once I have more information I will let you know.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello Ioannis,

                    Our development has let us know they are deeming this expected and have updated the help guide to reflect this.

                    "-A position is open and two or more Entry methods to reverse the position are entered together. In this case the second Entry order will be ignored."
                    https://ninjatrader.com/support/help...antedPositions

                    The work around would be to wait until the first entry fills and then submit the second entry in OnOrderUpdate() or OnExecutionUpdate() (or on the next OnBarUpdate()).
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello Chelsea,

                      I have coded the strategy according to your instructions, by using OnExecutionUpdate to submit the 2nd order in sequence and indeed the 2nd order submits fine.

                      Now I have the problem that the strategy occasionally skips the stop and reverse initial order so it sometimes keeps the initial position through the stop price! As I go through the trades, the stop level is respected by the strategy only after target for the 1st order is hit - i.e. it is only applied to the 2nd entry.

                      I have attached photos of the skips.

                      Perhaps advise why.

                      rgds

                      Ioannis
                      Last edited by im197; 10-02-2019, 06:23 AM.

                      Comment


                        #12
                        Hello Ioannis,

                        Do you have trace orders enabled and are you printing the order object or looking at the orders tab?

                        Are the orders being submitted?

                        Are the orders being cancelled or rejected?

                        Are you submitting a market order after the first stop order fills?
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello Chelsea,

                          I set up order trace to true and I don't see any orders being rejected. I am submitting the 2nd order after the 1st one has been executed.

                          I am not submitting a stop order for any of the positions as I expect the stop and reverse to take place with the initial enter on stop order.

                          I attach the strategy code.

                          Looking forward to an eventual solution

                          Attached Files

                          Comment


                            #14
                            Hello im197,

                            Lets focus on a specific order.

                            At what time is the order submitted?

                            Do you see the order submission in the TraceOrders?

                            What happens to the order in the prints to the output window of the order object or on the Orders display in the Strategy Analyzer?

                            To save the output from the output window, right-click the output window -> select Save As.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi Chelsea,

                              this is what I see in the date the 1st skip is observed

                              5/22/2019 11:00:00 PM Strategy 'ATRTrailStrat/-1': Entered internal SubmitOrderManaged() method at 5/22/2019 11:00:00 PM: BarsInProgress=0 Action=SellShort OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=3325 SignalName='Short 1' FromEntrySignal=''
                              Market going up, trail stop @ 3325
                              5/23/2019 1:00:00 PM Strategy 'ATRTrailStrat/-1': Entered internal SubmitOrderManaged() method at 5/23/2019 1:00:00 PM: BarsInProgress=0 Action=SellShort OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=3325 SignalName='Short 1' FromEntrySignal=''
                              5/23/2019 1:00:00 PM Strategy 'ATRTrailStrat/-1': Ignored SubmitOrderManaged() method at 5/23/2019 1:00:00 PM: BarsInProgress=0 Action=SellShort OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=3325 SignalName='Short 1' FromEntrySignal='' Reason='Invalid order price, please see log tab'
                              Market going up, trail stop @ 3325

                              I have attached the code.

                              I am running this on strategy analyzer on FESX 240 mins from 1/1/2019 to today, with default settings, with exit on session close to false. I am sure you can replicate it.
                              Attached Files
                              Last edited by im197; 10-02-2019, 09:15 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by martyn73, Today, 08:56 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post martyn73  
                              Started by TazoTodua, Today, 06:16 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post TazoTodua  
                              Started by bubblegum, Today, 01:02 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post bubblegum  
                              Started by RB104, Yesterday, 06:06 PM
                              1 response
                              13 views
                              0 likes
                              Last Post NinjaTrader_ShawnB  
                              Started by jtrading82, 05-25-2018, 09:59 AM
                              9 responses
                              981 views
                              0 likes
                              Last Post NinjaTrader_ShawnB  
                              Working...
                              X