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

On Execution

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

    On Execution

    In my strategy I have two IOrder:
    entryOrder and entryOrder2. I have a problem in the bold line of the OnExecution part.
    The bold part should be linked to the second IOrder but apparently I do not know how to
    link the entryOrder2 in those lines. It is making problem that sometimes IOrder which is the first order, is canceling the profit target. Can you tell me what should I add to bold lines in order to relate them to EntryOrder2.



    if (entryOrder2 != null && entryOrder2 == execution.Order)
    {
    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
    {
    // Stop-Loss order 4 ticks below our entry price
    stopOrder2 = ExitLongStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + initialStopDistance * TickSize, "MyStop2", "MyEntry2");

    // Target order 8 ticks above our entry price
    targetOrder2 = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + profit * TickSize, "MyTarget2", "MyEntry2");

    #2
    Hello flexi,

    Thanks for your post.

    The code:
    if (entryOrder2 != null && entryOrder2 == execution.Order)

    ensures that this code will trigger when the entryOrder2 order receives a fill.

    The execution.Order object will now only refer to that order.


    Do you have TraceOrders set to true that show the first order is causing the target or stop with that signal name to cancel?

    What signal name is the first order using?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      When I disable the entryOrder and entryOrder2
      is only order it opens position but can not take
      profit or exit with stop. Interesting is that only
      when the first position entryOrder is active then
      then the stop and the profit on entryOrder2 is functioning. So that
      is why I am assuming that the entryOrder is activating
      the profit and the stop on entryOrder2.

      Comment


        #4
        Hello flexi,

        Please let me see your output or let me test your script.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          In my original strategy there are three IOrders:
          entryOrder
          entryOrder2
          entryOrder3


          I will sugest to backtest it once from 1/1/2014 to 9/4/2014 which returns good results.

          But if you test it from 1/1/2013 to 9/4/2014 you will see that the profit of entryOrder2 is blocked. It does not happen always.

          Please test the code and any suggestion is welcomed.
          Attached Files

          Comment


            #6
            I tested it on ES at RTH on 15 min. chart.

            Comment


              #7
              Hi flexi,

              You are checking that stopOrder2 and stopOrder3 are null and in the same conditional you check the stopOrder.StopPrice instead of the stopOrder2.StopPrice or stopOrder3.StopPrice.

              This is the same issue as seen in this thread.
              http://www.ninjatrader.com/support/f...ad.php?t=68627
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by dcriador, Today, 12:06 PM
              0 responses
              6 views
              0 likes
              Last Post dcriador  
              Started by dcriador, Today, 12:04 PM
              0 responses
              5 views
              0 likes
              Last Post dcriador  
              Started by cutzpr, Today, 08:54 AM
              0 responses
              11 views
              0 likes
              Last Post cutzpr
              by cutzpr
               
              Started by benmarkal, Today, 08:44 AM
              0 responses
              17 views
              0 likes
              Last Post benmarkal  
              Started by Tin34, Today, 03:30 AM
              2 responses
              28 views
              0 likes
              Last Post Tin34
              by Tin34
               
              Working...
              X