Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NTOderStatus Problem

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

    NTOderStatus Problem

    I design trading systems run by others, and in this case it's an autotrading broker. We been running trades using NtDirect for some time and without too much problem as long as I get the logic done correctly. One problem we've had is high memory use which was determined to be the result of the string size in the NTOrderStatus function. I have modified the function to use the minimum string size which gets me the information I need. I've placed a copy of what I'm using in the box below.
    Code:
    { ** Copyright (c) 2005, NinjaTrader LLC [email protected] }
    DefineDLLFunc:  "NtDirect.dll", int, "Connected", int;
    DefineDLLFunc:  "NtDirect.dll", lpstr, "OrderStatus", lpstr;
    DefineDLLFunc:  "NtDirect.dll", int, "SetAllocReturnString", int;
    DefineDLLFunc:  "NtDirect.dll", int, "SetMaxReturnStringLength", int;
    
    inputs: 
    	OrderId(string);
    	//NTOS(stringref);
    
    SetAllocReturnString(1);				{ alloc memory for returned string, TS will free that memory 	}
    SetMaxReturnStringLength(2);			{ limit the max length of return string to 500 					}
    
    if Connected(0) = 0 then begin
    	//NTOrderStatusA = "OK";
    	
    NTOrderStatusA = "None";
    if OrderStatus(OrderID) = "Wo" then NTOrderStatusA = "Working" else
    	if OrderStatus(OrderID) = "Fi" then NTOrderStatusA = "Filled" else
    		if OrderStatus(OrderID) = "Pa" then NTOrderStatusA = "PartFilled" else
    			if OrderStatus(OrderID) = "Ca" then NTOrderStatusA = "Cancelled" else
    				if OrderStatus(OrderID) = "Pe" then NTOrderStatusA = "Pending";
    
    
    end;
    Today we had a failure involving the use of the above function and some code shown below. I was running the same code on my computer as the broker, but his computer did not issue the same trades. The only way this could happen is if the OrderStatus was not correct. The actual order status is called in another section of code controlled by a timer. Since it's working on one computer is there anything in the above function that could fail by virtue of being on a different machine? The broker must also have this function by virtue of having imported the ELD. I should also mention that we are running numerous different strategies but this is the only one that used the modified OrderStatus function shown above, which is what's making me suspect it.

    Strategy Code Excerpt:
    Code:
    case 1://both long and short active
    //LONG FIRST TRADE
    if time = 833
    	and barstatus(1) = 2
    	and NTLE2Sent = false
    	then begin
    		value1 = NTCommand("PLACE",NTAcct,"Buy",NTContracts,"Limit",LEP,0,"Day","",NTLE2,"","");
    		fileappend(NTLogFile,formattime("hh:mm:ss tt",computerdatetime)+S5+"Buy"+S5+numtostr(NTContracts,0)+" @ "+numtostr(LEP,2)+" Limit"+S5+NTLE2+newline);
    		NTLE2Sent = true;
    		end;
    //WHEN INITIAL ORDER BEGINS TO FILL, PLACE EXIT AND REVERSAL ORDERS		
    if 	time > 833
    	and instr(NTOSNTLE2,"Filled") > 0
    	and NTLX2Sent = false
    	then begin
    		value1 = NTCommand("PLACE",NTAcct,"Sell",NTContracts,"Limit",SEP,0,"Day","",NTLX2,"","");
    		fileappend(NTLogFile,formattime("hh:mm:ss tt",computerdatetime)+S5+"Sell"+S5+numtostr(NTContracts,0)+" @ "+numtostr(SEP,2)+" Limit"+S5+NTLX2+newline);
    		NTLX2Sent = true;
    		end;

    #2
    Atomic,

    Unfortunately I am not sure here at the moment. Could you give me a little more information on the setup you are using?

    The actual order status is called in another section of code controlled by a timer.
    I am wondering if this is something that could be the root cause. I.e. some state occurred related to the timer being out of sync with some other events.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Here is the code section that acquires the order status:
      Code:
      //NT ORDER SECTION
      UpdateTime = UpdateIntervalTime;
      if LBOC and time > 833
      and (Sec - LastTime >= UpdateTime or barstatus(1) = 2)
      and (TrdPredict_Sht >= Trade_Pg_Sht or TrdPredict_Lng >= Trade_Pg_Lng or TradeEveryDay) 
      then begin
      	NTFills =
      		+NTFilled(NTLE1)
      		+NTFilled(NTLE2)
      		+NTFilled(NTSX1)
      		+NTFilled(NTShtXit)
      		-NTFilled(NTSE1)
      		-NTFilled(NTLX1)
      		-NTFilled(NTLX2)
      		-NTFilled(NTLngXit);
      		
      		NTSE1Fills = NTFilled(NTSE1);
      		NTLE1Fills = NTFilled(NTLE1);
      		NTLE2Fills = NTFilled(NTLE2);
      		
      		NTOSNTLE1 = NTOrderStatusA(NTLE1);
      		NTOSNTLE2 = NTOrderStatusA(NTLE2);
      		NTOSNTSE1 = NTOrderStatusA(NTSE1);
      		NTOSNTSX1 = NTOrderStatusA(NTSX1);
      		NTOSNTLX1 = NTOrderStatusA(NTLX1);
      		NTOSNTLX2 = NTOrderStatusA(NTLX2);
      		NTOSNTShtXit = NTOrderStatusA(NTShtXit);
      		NTOSNTLngXit = NTOrderStatusA(NTLngXit);
      		
      		MPreal = 0;
      		if TrdPredict_Sht >= Trade_Pg_Sht and TrdPredict_Lng < Trade_Pg_Lng then MPreal = MP_Sht;
      		if TrdPredict_Sht < Trade_Pg_Sht and TrdPredict_Lng >= Trade_Pg_Lng then MPreal = MP_Lng;
      		if TrdPredict_Sht >= Trade_Pg_Sht and TrdPredict_Lng >= Trade_Pg_Lng then MPreal = MP_Sht + MP_Lng;
      		
      		value1 = text_setstring(TxtID1,numtostr(NTFills,0)+"("+numtostr(MP_Sht + MP_Lng,0)+")");
      		value1 = text_setlocation(TxtID1,date,minutestotime(timetominutes(time)+9),open);
      		
      		LastTime = Sec;
      		
      end;
      Sec is just a function that returns the second of the day. I'm polling the NT orderstatus about once every five seconds. I use this same method in many other strategies without issue. For the time being, I've gone back to the the original orderstatus function to see if that works. If it does, then I'd conclude the problem is with the modified function, buy why would it be a problem on one computer and not on another?

      Comment


        #4
        If it does, then I'd conclude the problem is with the modified function, buy why would it be a problem on one computer and not on another?
        Unfortunately I am not sure here. Maybe PC clock / time-zone settings?
        Adam P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by DanielTynera, Today, 01:14 AM
        0 responses
        2 views
        0 likes
        Last Post DanielTynera  
        Started by yertle, 04-18-2024, 08:38 AM
        9 responses
        40 views
        0 likes
        Last Post yertle
        by yertle
         
        Started by techgetgame, Yesterday, 11:42 PM
        0 responses
        10 views
        0 likes
        Last Post techgetgame  
        Started by sephichapdson, Yesterday, 11:36 PM
        0 responses
        2 views
        0 likes
        Last Post sephichapdson  
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,615 views
        0 likes
        Last Post aligator  
        Working...
        X