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.
      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 aligator, Today, 02:38 PM
          0 responses
          5 views
          0 likes
          Last Post aligator  
          Started by Stett0002, Yesterday, 11:55 PM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_ShawnB  
          Started by KasLB, Today, 05:12 AM
          2 responses
          17 views
          1 like
          Last Post KasLB
          by KasLB
           
          Started by LeitoGTR, Yesterday, 06:41 PM
          2 responses
          13 views
          0 likes
          Last Post LeitoGTR  
          Started by Prisalice, Today, 07:07 AM
          1 response
          10 views
          0 likes
          Last Post NT-Roland  
          Working...
          X