Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

For Sharp Minds: run time error without any programming cause

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

    For Sharp Minds: run time error without any programming cause

    Hi All,

    The script is capable to reverse positions under unmanaged approach method. This is the logic flow when a reverse triggers:

    - Cancelling any working order which intends to increase the Old Position
    - Cancelling any working order which would intend to Exit the New Position
    - Enter Exit Old Position order
    if this order is filled
    {
    Cancel the the stop loss order for the Old Position
    Enter order for the New Position
    }

    Note: all the required programming steps for correctly internal managing the state of orders are Ok.

    When Script runs, it opens OK, reverses perfectly from Long to Short, BUT when it comes to reverse from Short to Long, a weird error happens. The Long position is entered and filled, but its StopLoss doesn't. From that point the Script seems to continue OK, but it really doesn't. Obviously all reverse routine for Short and Long are exactly the same, like mirror images. The error obviously involves the next StopLoss order. The only thing that I suspect is that may be there's some electronic ban or interference for new orders sent while other are marked to be cancelled despite are different ( should I confirm orders's states before launching new orders ? This could really slowdown the filling dynamics of the script in a competitive market like E-mini S&P500). Here's an extract from Log file where this could be seen.

    HERE BEGINS THE REVERSE COMMENTED
    20/12/2013 15:59:56|1|32|Order='9e24d5759f4b4ad1835aaa9d686d0 a4d/Sim101' Name='Exit Short' New state=PendingSubmit Instrument='ES 03-14' Action=BuyToCover Limit price=1813.25 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
    20/12/2013 15:59:56|1|32|Order='9e24d5759f4b4ad1835aaa9d686d0 a4d/Sim101' Name='Exit Short' New state=Accepted Instrument='ES 03-14' Action=BuyToCover Limit price=1813.25 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
    20/12/2013 15:59:56|1|32|Order='9e24d5759f4b4ad1835aaa9d686d0 a4d/Sim101' Name='Exit Short' New state=Working Instrument='ES 03-14' Action=BuyToCover Limit price=1813.25 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
    20/12/2013 15:59:56|1|32|Order='9e24d5759f4b4ad1835aaa9d686d0 a4d/Sim101' Name='Exit Short' New state=Filled Instrument='ES 03-14' Action=BuyToCover Limit price=1813.25 Stop price=0 Quantity=1 Type=Limit Filled=1 Fill price=1813.25 Error=NoError Native error=''
    20/12/2013 15:59:56|1|16|Execution='3034d6b0edba4c5a8753c3212 4aaa738' Instrument='ES 03-14' Account='Sim101' Exchange=Default Price=1813.25 Quantity=1 Market position=Long Operation=Insert Order='9e24d5759f4b4ad1835aaa9d686d0a4d' Time='20/12/2013 15:59:56'
    20/12/2013 15:59:56|1|64|Instrument='ES 03-14' Account='Sim101' Avg price=1813.25 Quantity=0 Market position=Short Operation=Remove Currency=Unknown
    20/12/2013 15:59:56|1|32|Order='29c4f85ecc9746eab2a5ff842c129 d29/Sim101' Name='Enter Stop Short' New state=PendingCancel Instrument='ES 03-14' Action=BuyToCover Limit price=0 Stop price=1821.5 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error=''
    20/12/2013 15:59:56|1|32|Order='e30ef0e89df348419e477f4526e3a e0c/Sim101' Name='Enter Long' New state=PendingSubmit Instrument='ES 03-14' Action=Buy Limit price=1813.25 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
    20/12/2013 15:59:56|3|128|Error on calling 'OnExecution' method for strategy 'CRBSsimpleUmanaged/fa8e29a86fb7413c872c9f38f4e10f39': Referencia a objeto no establecida como instancia de un objeto.
    20/12/2013 15:59:57|1|32|Order='e30ef0e89df348419e477f4526e3a e0c/Sim101' Name='Enter Long' New state=Accepted Instrument='ES 03-14' Action=Buy Limit price=1813.25 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
    20/12/2013 15:59:57|1|32|Order='e30ef0e89df348419e477f4526e3a e0c/Sim101' Name='Enter Long' New state=Working Instrument='ES 03-14' Action=Buy Limit price=1813.25 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
    20/12/2013 15:59:57|1|32|Order='29c4f85ecc9746eab2a5ff842c129 d29/Sim101' Name='Enter Stop Short' New state=Cancelled Instrument='ES 03-14' Action=BuyToCover Limit price=0 Stop price=1821.5 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error=''
    20/12/2013 15:59:57|1|32|Order='e30ef0e89df348419e477f4526e3a e0c/Sim101' Name='Enter Long' New state=Filled Instrument='ES 03-14' Action=Buy Limit price=1813.25 Stop price=0 Quantity=1 Type=Limit Filled=1 Fill price=1813.25 Error=NoError Native error=''
    20/12/2013 15:59:57|1|16|Execution='93bb90f952b2424db8da684c4 aaf3aa6' Instrument='ES 03-14' Account='Sim101' Exchange=Default Price=1813.25 Quantity=1 Market position=Long Operation=Insert Order='e30ef0e89df348419e477f4526e3ae0c' Time='20/12/2013 15:59:57'
    20/12/2013 15:59:57|1|64|Instrument='ES 03-14' Account='Sim101' Avg price=1813.25 Quantity=1 Market position=Long Operation=Insert Currency=Unknown
    20/12/2013 16:14:30|1|128|Exit on close handling for strategy 'CRBSsimpleUmanaged' started.

    Any ideas or suggestion about this?

    Thanks in advanced

    #2
    I suspect of any of this possible reasons ( Tell me what you'd discard immediately ):

    1. Because any of conditional orders ( such as Stops ) should be reset to null before submit ( Despite that they're obviously reset before this point in the script )
    2. Because it's necessary to confirm that an Old Stop order has been cancelled before submit New reversed Position order
    3. Because the EnterLong new order might have returned some error-state before being accepted
    4. Because the simulation times set in Options could affect this?

    To test this it's necessary to "live",so from Sunday on I´ll let it know
    Thanks

    Comment


      #3
      Hello pstrusi,

      The message that you get "Object reference not set to an instance of an object." so I don't think there is any interference with this but you are just referencing on object that is valid or has not been set yet.

      It is always a good idea to check the state of your orders including your Stop Loss orders to make sure that you cancel them yes.

      Note that using the Unmanaged Approach you will not want to use the EnterLong method.

      There are no options inside of the Sim101 account that would affect this as it is a programming issue.

      Since this happens in the OnExecution() event you may want to use a Try Catch statement to see what object you are referencing to be able to get this resolved. Here is an example of how to use a try catch statement that you may view.
      JCNinjaTrader Customer Service

      Comment


        #4
        Thanks JC,

        Effectively I've found a situation which there was a change in an order which was not already available , so you're right, the solution it's always to check the status of an order before doing something with it, despite that the logic flow tells that's no necessary.

        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