Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

ExitLong() is being “skipped”

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

    ExitLong() is being “skipped”

    This is strange, but I am sure there is a logical explanation for it. When I call ExitLong(), the order is not submitted and there is no sign of the call in the log. I have verified that it is being called. Here is the exact code:

    Code:
    [FONT=Calibri][SIZE=3]//Original Entry[/SIZE][/FONT]
    [COLOR=black][FONT=Courier New]activeOrder = EnterLongLimit([/FONT][/COLOR][COLOR=purple][FONT=Courier New]0[/FONT][/COLOR][COLOR=black][FONT=Courier New], [/FONT][/COLOR][COLOR=blue][FONT=Courier New]true[/FONT][/COLOR][COLOR=black][FONT=Courier New], 2, Bars[[/FONT][/COLOR][COLOR=purple][FONT=Courier New]0[/FONT][/COLOR][COLOR=black][FONT=Courier New]], “Test1”);[/FONT][/COLOR]
     
    [COLOR=black][FONT=Courier New]// Setting the stop in OnOrderUpdate().  I do make sure the tokens match and this is the right order[/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]stopLossOrder = ExitLongStop([/FONT][/COLOR][COLOR=purple][FONT=Courier New]0[/FONT][/COLOR][COLOR=black][FONT=Courier New], [/FONT][/COLOR][COLOR=blue][FONT=Courier New]true[/FONT][/COLOR][COLOR=black][FONT=Courier New], Position.Quantity, stopVal, [/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"Stop Loss"[/FONT][/COLOR][COLOR=black][FONT=Courier New], “Test1”);[/FONT][/COLOR]
     
    [COLOR=black][FONT=Courier New]// At some point I will take profits on the position like this:[/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]ExitLong(1, [/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"First Target"[/FONT][/COLOR][COLOR=black][FONT=Courier New], “Test1”);[/FONT][/COLOR]
     
    [COLOR=black][FONT=Courier New]// Once my next target is reached, I close out like this:[/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]managedExitOrder = ExitLong([/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"Second Target”)[/FONT][/COLOR][COLOR=black][FONT=Courier New], “Test1”);[/FONT][/COLOR]
    This is the order that gets skipped. I have found that if I add the correct Qantity like this:
    Code:
    [COLOR=black][FONT=Courier New]managedExitOrder = ExitLong(Position.Quantity, [/FONT][/COLOR][COLOR=maroon][FONT=Courier New]Second Target"[/FONT][/COLOR][COLOR=black][FONT=Courier New], “Test1”);[/FONT][/COLOR]
    The above seems to work, but I want to know why my first attempt does not get executed. I am getting some strange results in other areas, and I think it may be because of something similar to this.

    Also, is the returned IOrder object that comes back in the original EnterLongLimit() valid for the life of the position? Should I continue to reference the original EnterSignal on all these orders?

    Thanks,

    -Scott

    #2
    Your original attempt probably didn't work because of an extraneous parenthesis.

    Code:
    [COLOR=black][FONT=Courier New]managedExitOrder = ExitLong([/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"Second Target”[SIZE=5][COLOR=Red])[/COLOR][/SIZE][/FONT][/COLOR][COLOR=black][FONT=Courier New], “Test1”);[/FONT][/COLOR]

    No you should not rely solely on the IOrder to determine your EnterLongLimit().

    These are some notes you should read over regarding IOrder taken from the NT6.5 help guide.
    • An IOrder object returned from calling an order method is dynamic in that its' properties will always reflect the current state of an order
    • An IOrder object passed in from the OnOrderUpdate() method is volatile in that its' properties remain static and do not change. DO NOT hold on to these references for the purpose of checking its' properties outside of the OnOrderUpdate() method. Check the IOrder object returned from the original call to the order method.
    • IOrder objects are NOT unique per order and therefore do not compare IOrder objects to each other to determine equality
    • To check for equality check the <IOrder>.Token property which is a guaranteed unique identifier for an order
    • The property <IOrder>.OrderId is NOT a unique value since it can change throughout an order's lifetime
    You can check out this reference sample for more help in using IOrders. http://www.ninjatrader-support.com/v...ead.php?t=3917
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Josh,

      Thanks for the reply...

      Sorry for the delay in getting back to this thread. My strategy has grown over the last couple of weeks. I found I needed to write a much better order handling routine to accommodate the strategy. In the process, I was able to fix the bugs I had with regards to this thread.

      I'd also like to suggest to anyone creating a new strategy to use OnOrderUpdate() to handle and process incoming messages. It makes complex strategies where you are adjusting stops, canceling orders, etc..., much easier and efficient.

      Thanks for the help...

      -Scott

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Haiasi, 04-25-2024, 06:53 PM
      2 responses
      16 views
      0 likes
      Last Post Massinisa  
      Started by Creamers, Today, 05:32 AM
      0 responses
      4 views
      0 likes
      Last Post Creamers  
      Started by Segwin, 05-07-2018, 02:15 PM
      12 responses
      1,785 views
      0 likes
      Last Post Leafcutter  
      Started by poplagelu, Today, 05:00 AM
      0 responses
      3 views
      0 likes
      Last Post poplagelu  
      Started by fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,407 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Working...
      X