Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cause of delay in executions

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

    Cause of delay in executions

    Hello,

    Below, I've posted some code, stripped of all the logic to determine trade signals. The trade signal logic is done (as shown in code comment) inside the if(FirstTickOfBar) section. This code basically reverses a position. So, you can see ExitShort() at the top, and EnterLong() at the bottom. Essentially, the only thing in between is setting variable values and checking market position (except for a small bit of calculation for time and a bit of simple math in one line).

    Here's the issue: looking at the log, the time between the ExitShort and EnterLong is often anywhere from 5 seconds to 20 seconds. At first I noticed this on live trading with a broker and assumed the issue was a delay in receiving fill/confirmation messages. So, I ran on sim101 and was still getting at least 5 seconds between the two executions.

    I went so far as to strip Ninja down to running just a single chart with the one strategy, same result. On sim101 in particular, it seems like the time should be sub one second for such a simple bit of code.

    Any ideas or suggestions?

    Code:
    ExitShort();
    
    if (Position.MarketPosition == MarketPosition.Long) // code after doesn't run because flat
    
    if (Position.MarketPosition == MarketPosition.Long) // code after doesn't run because flat
    
    if (FirstTickOfBar)DrawTextFixed("tag1", chartNote, TextPosition.TopRight);
    			if(Historical) return;
    			if(CurrentBar < 60 )
    				return;
    			// all logic for trade conditions and variables being set here too
    					
    
    if (Position.MarketPosition == MarketPosition.Flat && enterOkay == true) 
    {
    stopControl = true;
    entryOffset = entryOffset1;//setting offset variables based on current setup bar type
    iniOffset = iniOffset1;
    mdOffset = mdOffset1;
    oneDone = oneDone1;
    
     if ((tradeCondition) == true && ToTime(Time[0])>=startTime && ToTime(Time[0])< endTime && Math.Abs(Close[2]-Close[1])<2*BarsPeriod.Value*TickSize && Close[0]>= High[1]+ entryOffset*TickSize && tradeLong == true)
     {
     orderName = orderLabel;
     theoEntry = High[1] + entryOffset*TickSize;//variable to manage stops against theoretical no-slippage entry
     stopPrice = Low[1] - iniOffset*TickSize;
     SetStopLoss(CalculationMode.Price,stopPrice);//initial stop set to entry plus wiggle room
     SetProfitTarget(orderName,CalculationMode.Price,High[1] + entryOffset*TickSize + firstTarget*TickSize);//targets set from strategy setup user parameters
     EnterLong(lotSize, orderName);
    Last edited by coolmoss; 06-22-2012, 09:39 AM.

    #2
    Hello coolmoss,

    1.Where are you calling this code? [Example: in OnBarUpdate()]
    2.How are you verifying that the delay in between the code?
    3.What bar series type are you using? (Example: Minute, Day, Tick)
    4.What Print()s have you added to find out how your code is running?
    5.Do you see delays if you manually place order?

    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Hi JC,

      1) The posted code is being called from OnBarUpdate. That's all that's used, except for a single line of code in OnPositionUpdate which draws a bit of fixed text.

      2) I'm verifying the time delay from the log tab, the log file, and observation in live trading on the longer delays (eg. a 15 second delay is pretty noticable if you happen to be watching screen at the time).

      3) Range bars, usually something around 8 ticks wide, COBC = false

      4) Could you please suggest where I should locate the print statements in the code I posted. Would it hurt to put a print statement between each "if" section. I don't want to bog things down using too many prints which then muddies up the whole problem.

      5) No delays in manual orders. For that matter, just to be clear, the Exits are darn near instantaneous, and the logs bear this out.

      Just to be clear: these "delays" don't happen all the time, that's what's so screwy. I'd say 1/2 to 1/3 of the reversals occur inside 1 second, the other take anywhere from 5 to 15 seconds or more. And the computer isn't on the edge of it's resources and again, Ninja is doing very minimal stuff.

      Thanks very much for your help!
      Last edited by coolmoss; 06-22-2012, 10:07 AM.

      Comment


        #4
        Hello coolmoss,

        Thanks for the information.

        Could you send me your log and trace files so that I may look into what occurred.

        You can do this by going to the Control Center-> Help-> Mail to Support.

        Please reference the following ticket number in the body of the email: ATTN - JC - http://www.ninjatrader-helpdesk.com/...t&reqid=669407


        4. First, I would turn TraceOrders = true, see the following link http://www.ninjatrader.com/support/h...raceorders.htm. Then I would put a print before, inside, and after each if statement at first to see how your strategy is being processed. For example:

        Code:
        ExitShort();
        Print("After ExitShort() and Time is: "+DateTime.Now);
        To see how your code is executed and the time (of your local PC in seconds).

        Please let me know if I can be of further assistance.
        JCNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        662 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
        574 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