Announcement

Collapse
No announcement yet.

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.

      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.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          50 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          126 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          69 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X