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

Basic oneachtick loop question

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

    Basic oneachtick loop question

    When the following code runs oneachtick, does the order execution loop run each iteration on each incoming tick or does it run to completion upon the first tick and satisfaction of the entry criteria? I ask because sometimes the loop stops entering limit orders when the first order in the loop is filled and the Positions[13].MarketPosition != MarketPosition.Flat. Regards and many thanks.

    if (Positions[13].MarketPosition == MarketPosition.Flat
    && BarsInProgress == 13
    && Bars.TickCount >1
    && Bars.TickCount >1 && Bars.TickCount <1000)


    {
    {
    for (int zbuhl = 0, zbuhlx = 10; zbuhl < zbuhlx; zbuhl++)
    {
    if (10 >= 1)
    {
    myEntryOrderZB LONG = EnterLongLimit(13,true,1,CurrentDayOHL(Opens[13]).CurrentOpen[0],"ZB UH LONG LIMIT"+ zbuhl);
    SetStopLoss("ZB LONG LIMIT"+zbuhl, CalculationMode.Price,PriorDayOHLC(Closes[13]).PriorClose[0], false);
    SetProfitTarget("ZB LONG LIMIT"+zbuhl, CalculationMode.Price,((CurrentDayOHL(Opens[13]).CurrentOpen[0] + ((Math.Max(0,5, (ATR(Closes[13],11)[1]*0.90)))))));
    barNumberOfOrderZB = CurrentBars[0];
    gapZBtradetoday = true;
    orderList.Add(myEntryOrder);
    }
    }
    }
    }

    #2
    With OnEachTick, OnBarUpdate is called for each incoming tick.

    If 1,000 ticks come in, your OnBarUpdate will be called 1,000 times.

    If any one of those OnBarUpdate calls submits an order, then after submitting
    that order, when that OnBarUpdate returns, the framework naturally gets a
    chance to process other things.

    Well, it could be that an order submitted during your OnBarUpdate call when
    TickCount=127 becomes filled just before OnBarUpdate w/TickCount=231
    is called. During the OnBarUpdate call w/TickCount=231, the MarketPosition
    for the instrument series of the filled order will correctly reflect that it is not Flat.

    And yes, this could all happen on the same bar -- which is ok, because you're
    asking your OnBarUpdate to process each tick.

    Comment


      #3
      Hello elliot5,

      Thank you for your reply.

      bltdavid has some good insight here. I'd like to add that I would recommend turning on the Trace Order function and adding some prints to understand exactly what's happening within the loop. You're using the Managed approach, which means some orders may be being ignored if they violate internal handling rules. Turning on Trace Orders will print the orders that are being submitted to the NinjaScript Output window along with information if they are being ignored for some reason.

      if (State == State.SetDefaults)
      {
      TraceOrders = true;
      }

      Once you then recompile the strategy, you can open a new NinjaScript Output window under New > NinjaScript Output. This will print a log of any orders submitted by the strategy during while it's running, along with any ignored orders. You can then look through and see what may be occurring.

      Here is a link to our help guide that goes into more detail on tracing orders:

      https://ninjatrader.com/support/help...aceorders2.htm

      If you turn this on do you see orders being ignored from the loop?

      Thanks in advance; I look forward to assisting you further.
      Kate W.NinjaTrader Customer Service

      Comment


        #4
        Great response guys. I will dedicate the output window to tracing the orders and report back. Am i correct in thinking then that the loop will run all its cycles upon one incoming tick?

        Comment


          #5
          Hello elliot5,

          Thank you for your reply.

          Yes, it should be running through the complete loop for each tick. You could verify this by printing the current value of zbuhl within the loop so it's printed for each iteration.

          Please let us know if we may be of further assistance to you.
          Kate W.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by RubenCazorla, Today, 09:07 AM
          1 response
          5 views
          0 likes
          Last Post RubenCazorla  
          Started by Irukandji, Today, 09:34 AM
          0 responses
          3 views
          0 likes
          Last Post Irukandji  
          Started by TraderBCL, Today, 04:38 AM
          3 responses
          25 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by WeyldFalcon, 08-07-2020, 06:13 AM
          11 responses
          1,423 views
          0 likes
          Last Post jculp
          by jculp
           
          Started by BarzTrading, Today, 07:25 AM
          2 responses
          29 views
          1 like
          Last Post BarzTrading  
          Working...
          X