Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ExitShort ExitLong behaviour

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

    ExitShort ExitLong behaviour

    Hello, Im seeing some kind of problem with a strategy executed in real time on the simulated NT account...
    This is the code:
    Code:
    [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](/*some short condition*/[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](Position.Quantity > [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New] ExitLong([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"TO_ExitLong"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"TO_EnterLong"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]((ToTime(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]) > [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]103000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] && ToTime(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]) < [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]163000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]))[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New] EnterShort([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"TO_EnterShort"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](/*some long condition*/[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](Position.Quantity > [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New] ExitShort([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"TO_ExitShort"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"TO_EnterShort"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]((ToTime(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]) > [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]103000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] && ToTime(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]) < [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]163000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]))[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New] EnterLong([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"TO_EnterLong"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
    [/SIZE][/FONT]
    The problem is that the long condition is executing 2 orders of buy and the short part just closes that 2 positions... (the script never go short)
    ExitShort is not acting well, why is that ?

    Last edited by stormze; 05-27-2009, 02:41 PM.

    #2
    Note: this started happening since I manually closed one of the orders that the script submitted

    Comment


      #3
      stormze,

      If you want to reverse there is no need to place ExitShort then EnterLong orders like that. Just call EnterLong and just call EnterShort. If you were in an opposing position it will automatically close that position first and then get you into your long/short.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        I know but I only want to reverse on some circustances and just close the actual position on others.
        Apparently when Im long 1 contract and I do a close, instead of selling that contract, is buying another one

        Comment


          #5
          If you were long and you called ExitLong() it will close the position. If in addition you called EnterShort() you will for sure get the additional short. You will need to debug your orders to see which are being placed with TraceOrders = true.

          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Ok I will try to collect some logs with TraceOrders = true
            But may be there is a bug here, I think what happened is the following:

            - Script executed EnterShort of 1 contract
            - I manually closed that position and went to flat
            - Script executed an ExitShort of 1 contract but it didnt realized that it was already flat and bought 1 contract
            - Script executed an EnterLong of 1 contract and bought another contract being long 2 contracts... and so on

            Comment


              #7
              Could happen since your code is never checking for a flat. Plus inflight executions can occur. If the execution has not been reported back yet and you still submit a new order it will go through.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Ah interesting...
                I tryed to check for a flat on my code with

                if(Position.Quantity > 0)
                close actual position

                Is that wrong or some other better way to do it ? Note that all orders are submitted to only one ticker but its not the main ticker

                Comment


                  #9
                  You can use Position.MarketPosition for checking if you're flat or not - http://www.ninjatrader-support.com/H...tPosition.html
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Ok I still have the problem.
                    EnterLong of 1 contract is buiyng me 2 contracts being flat, and I can't change that behaviour
                    Is acting like if it were short 1 contract.
                    I tryed reseting the Sim101 db restarting NT but nothing.
                    What can I do

                    Comment


                      #11
                      stormze,

                      You need to use TraceOrders = true to see what is going on. If you really are flat it will never buy 2 if the order was submitted as 1. Changes you make to the code need to be compiled by pressing F5 in the compiler and changes are only reflected AFTER you start a new instance of the strategy.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        I dont see anything unusual with TraceOrders = true, prior EnterLong is baing executed I see a "Close position" order generated automatically, I want to prevent this or reset the counter it has. How NT knows that it need to close a position ???
                        Yea I also reload the strategy for every change...

                        5/28/2009 1:22:01 PM,Position,Instrument='ES 06-09' Account='Sim101' Avg price=895.5 Quantity=2 Market position=Long Operation=Update Currency=Unknown,
                        5/28/2009 1:22:01 PM,Execution,Execution='a399113f8e2041e18abb6b5828 e69295' Instrument='ES 06-09' Account='Sim101' Exchange=Default Price=895.5 Quantity=1 Market position=Long Operation=Insert Order='bb5f8897c86b42a19f78711279b930b1' Time='5/28/2009 1:22:01 PM',
                        5/28/2009 1:22:01 PM,Order,Order='bb5f8897c86b42a19f78711279b930b1/Sim101' Name='TO_EnterLong' New State=Filled Instrument='ES 06-09' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=1 Fill price=895.5 Error=NoError Native error='',
                        5/28/2009 1:22:01 PM,Order,Order='bb5f8897c86b42a19f78711279b930b1/Sim101' Name='TO_EnterLong' New State=Working Instrument='ES 06-09' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',
                        5/28/2009 1:22:01 PM,Order,Order='bb5f8897c86b42a19f78711279b930b1/Sim101' Name='TO_EnterLong' New State=Accepted Instrument='ES 06-09' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',
                        5/28/2009 1:22:01 PM,Position,Instrument='ES 06-09' Account='Sim101' Avg price=895.5 Quantity=1 Market position=Long Operation=Insert Currency=Unknown,
                        5/28/2009 1:22:01 PM,Execution,Execution='a12a22d9449a4f3ca052efb15f 3a92df' Instrument='ES 06-09' Account='Sim101' Exchange=Default Price=895.5 Quantity=1 Market position=Long Operation=Insert Order='f242023ab619414aa912c98857ffc9d4' Time='5/28/2009 1:22:01 PM',
                        5/28/2009 1:22:01 PM,Order,Order='f242023ab619414aa912c98857ffc9d4/Sim101' Name='Close position' New State=Filled Instrument='ES 06-09' Action=BuyToCover Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=1 Fill price=895.5 Error=NoError Native error='',
                        5/28/2009 1:22:01 PM,Order,Order='f242023ab619414aa912c98857ffc9d4/Sim101' Name='Close position' New State=Working Instrument='ES 06-09' Action=BuyToCover Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',
                        5/28/2009 1:22:01 PM,Order,Order='f242023ab619414aa912c98857ffc9d4/Sim101' Name='Close position' New State=Accepted Instrument='ES 06-09' Action=BuyToCover Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',
                        5/28/2009 1:22:00 PM,Order,Order='bb5f8897c86b42a19f78711279b930b1/Sim101' Name='TO_EnterLong' New State=PendingSubmit Instrument='ES 06-09' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',
                        5/28/2009 1:22:00 PM,Order,Order='f242023ab619414aa912c98857ffc9d4/Sim101' Name='Close position' New State=PendingSubmit Instrument='ES 06-09' Action=BuyToCover Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',

                        Comment


                          #13
                          stormze,

                          It is evident your signal tracking has gone awry. You will need to debug your strategy and find exactly where it happens. You have a lot of Enter/Exits mixing and matching everywhere. You will need to check them by hand.
                          Josh P.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Brevo, Today, 01:45 AM
                          0 responses
                          2 views
                          0 likes
                          Last Post Brevo
                          by Brevo
                           
                          Started by aussugardefender, Today, 01:07 AM
                          0 responses
                          3 views
                          0 likes
                          Last Post aussugardefender  
                          Started by pvincent, 06-23-2022, 12:53 PM
                          14 responses
                          238 views
                          0 likes
                          Last Post Nyman
                          by Nyman
                           
                          Started by TraderG23, 12-08-2023, 07:56 AM
                          9 responses
                          384 views
                          1 like
                          Last Post Gavini
                          by Gavini
                           
                          Started by oviejo, Today, 12:28 AM
                          0 responses
                          6 views
                          0 likes
                          Last Post oviejo
                          by oviejo
                           
                          Working...
                          X