Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

orders in OnMarketData continue to submit

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

    orders in OnMarketData continue to submit

    Greets!

    I moved eL1 of my order entry code to OnMarketData (from OnBarUpdate) for a more controlled entry.

    All entry conditions stay in OnBarUpdate and are then passed to OnMarketData via 'touch_price' to initiate the entry.

    On the first instance of use, after the eL1 is working, the 'touch_price' continues to initiate entrys (that are ignored due to the 1 entry /direction) but after the eL1 is stopped out, the next trigger bar event conditions do not show a new 'touch_price' generated by the OnBarUpdate being detected by the OnMarketData.

    The other entrys still in OnBarUpdate continue to function as normally expected.

    Code:
     
    #region Region_OnMarketData
    // 
    protected override void OnMarketData(MarketDataEventArgs e)
     
    {
    //Update bid / ask / spread variables
    UpdateBidAskSpread(out cAsk, out cBid, out cSpread); 
     
    if ( e.Price == touch_price )
    { Print("Last = "+e.Price); 
    if ((iOrderL1 == null || Historical) && iQuantity1 != 0)
    { iOrderL1 = EnterLongLimit(0, true, iQuantity1, Closes[0][0] + 1*TickSize, sENTRY1L); 
    LL_EntryBar0_OMD_L1 = CurrentBars[0];
    Print("Entered LL_Order from OnMarketData PreviousBar#= "+CurrentBars[0]+", Time of bar= "+Times[0][0]+", bar closed "+Closes[0][0]+", BarHI= "+Highs[0][0]+", BarLO= "+Lows[0][0]);
     
    }
     
    }
     
    }
    #endregion
    Is there extra code, other than what I have been using for iOrderl1 for several months without a problem in OnBarUpdate, that is needed to properly wrap up the working and closeing of the order and entry? I dont see anything mention in the F1 help

    Thanks,
    Jon

    #2
    Hi Jon,

    Is there extra code, other than what I have been using for iOrderl1 for several months without a problem in OnBarUpdate, that is needed to properly wrap up the working and closeing of the order and entry?
    Your condition for entry requires that the order object is null. Once your orders reach a terminal state (filled or cancelled), then you need to reset the IOrders back to null.


    Code:
    protected override void OnOrderUpdate(IOrder order)
    {
        if (entryOrder != null && entryOrder == order)
        {
             Print(order.ToString());
            if (order.OrderState == OrderState.Filled || order.OrderState == OrderState.Cancelled)
                  entryOrder = null;
        }
    }
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Ryan,

      This code is used for all the entries, including the eL1 that was in OnMarketData. I am using OnExecution, not OnOrderUpdate. Does it have to be in OnOrderUpdate also? It hasnt until now and worked just fine.

      #region Region_OnExecution

      protectedoverridevoid OnExecution(IExecution execution)
      {
      #region orderL1
      if (iOrderL1 != null)
      {
      if (iOrderL1.Token == execution.Order.Token)
      {
      //-----------------------------------------------------

      // PENDING ORDERS (PendingSubmit / Working / Accepted)

      //-----------------------------------------------------

      if (
      execution.Order.OrderState == OrderState.PendingSubmit ||
      execution.Order.OrderState == OrderState.Working ||
      execution.Order.OrderState == OrderState.Accepted
      )
      {
      //Log This

      ////LogFile.LogToFile(Historical, "OnExecution : Long - Orderstate PendingSubmit / Working / Accepted", true);

      }
      //----------------------------

      // Filled Order Response?

      //----------------------------

      if (execution.Order.OrderState == OrderState.Filled)
      {
      //clear the order variable

      iOrderL1 = null;
      }
      //----------------------------

      //Rejected Long Order?

      //----------------------------

      if (execution.Order.OrderState == OrderState.Rejected)
      {
      //clear the order variable

      iOrderL1 = null;
      //Log This

      ////LogFile.LogToFile(Historical, "OnExecution : Long - Rejected", true);

      }
      }
      }
      #endregion

      The line order.OrderState == OrderState.Cancelled is not covered in my current code so I will add that. I just had another order start in OnBarUpdate but not in OnMarketData even though the touch_price was printed out from OnBarUpdate. I put touch_price as
      private
      double touch_price = 0;

      in 'publicstruct Strategy' ... but it only worked once, and not at all on another strategy I set for test ... I wonder if it should be in '
      protected
      overridevoid OnStartUp()

      Thanks,
      Jon
      Last edited by Trader.Jon; 03-28-2011, 10:14 AM.

      Comment


        #4
        Yes, best practice is to place in OnOrderUpdate() which fires during every order state change. OnExecution() only fires during a fill.

        The .token convention is no longer used in version 7. Any test for equality is done with the objects directly.

        Best place for variable declaration is the variables region.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_RyanM View Post
          Yes, best practice is to place in OnOrderUpdate() which fires during every order state change. OnExecution() only fires during a fill.

          The .token convention is no longer used in version 7. Any test for equality is done with the objects directly.

          Best place for variable declaration is the variables region.
          Thanks, I will have alook at that ... I had another trigger bar fire orders in OnBarUpdate but the touch_price didnt show until 2 bars later in OnMarketData so there is something not correct.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          663 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          376 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          110 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          575 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          580 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X