Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NtDirect.dll SetAllocReturnString(1)

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

    NtDirect.dll SetAllocReturnString(1)

    I am in the process of converting some of the NT functions to methods, and in reviewing the code, I have this in the NTOrderStatus function:

    Code:
    SetAllocReturnString(1);				{ alloc memory for returned string, TS will free that memory 	}
    	SetMaxReturnStringLength(13);			{ limit the max length of return string to 500
    I have several questions:
    1. The NTOrderStatus function is autodetect as far as series or simple so I'm not sure of it's exact behavior when it's running. I believe it should be simple, which means it should run only when called by the ELD, and not on every tick, which would be the case with a series function. Is it correct that it should only run when called?

    2. Assuming it's only run when called, do the SetAllocReturnString and SetMaxReturnStringLength need to run on each call or only the first time it's called?

    3. What is the significance of the SetAllocReturnString parameter? Is 1 the proper value?

    4. From experience, I know that this will cause a memory leak in TradeStation. What ever the NtDirect.dll programmer thought was supposed to happen, does not happen. This is the main reason I've shortened the return string length to 13. It soaks up less memory.

    5. If I move the NTOrderStatus function to a method block inside the ELD, how should it be configured? Do the lines of code above need to run every time the method is called, or can the be put in a once block?

    Here is my development code which I ran today, and it does work and does status the order.
    Code:
    {DefineDLLFunc:  "NtDirect.dll", int, "Connected", int;
    DefineDLLFunc:  "NtDirect.dll", int, "Command", lpstr, lpstr, lpstr, lpstr, int, lpstr, double, double, lpstr, lpstr, lpstr, lpstr, lpstr;
    
    inputs: Cmd(string), Account(string), Action(string), Quantity(numericsimple), 
    		OrderType(string), LimitPrice(numericsimple), StopPrice(numericsimple), TimeInForce(string), Oco(string),
    		OrderId(string), Template(string), Strategy(string);
    
    var: GSN(getsymbolname);
    //if rightstr(GSN,2) = ".D" then GSN = leftstr(GSN,strlen(GSN)-2);
    if instr(GSN,"ES") = 2 then GSN = "@ES" else GSN = "XXXXX";
    
    if Connected(0) = 0 and getappinfo(airealtimecalc) = 1 then
    NTCommand = Command(Cmd,  Account, GSN, Action, Quantity, OrderType, LimitPrice, StopPrice, TimeInForce, Oco,
    				OrderId, Template, Strategy);}
    
    DefineDLLFunc:  "NtDirect.dll", int, "Connected", int;
    DefineDLLFunc:  "NtDirect.dll", int, "Command", lpstr, lpstr, lpstr, lpstr, int, lpstr, double, double, lpstr, lpstr, lpstr, lpstr, lpstr;
    DefineDLLFunc:  "NtDirect.dll", lpstr, "OrderStatus", lpstr;
    DefineDLLFunc:  "NtDirect.dll", int, "SetAllocReturnString", int;
    DefineDLLFunc:  "NtDirect.dll", int, "SetMaxReturnStringLength", int;
    
    //METHOD TO SUBMIT ORDER				
    method	int NTCmd(string Cmd,string Account, string Action, int Quantity, string OrderType, double LimitPrice, double StopPrice,string OrderId)
    var: string SmblName;
    begin
    
    if connected(0) <> 0 or getappinfo(airealtimecalc) <> 1 then return -1;
    SmblName = getsymbolname;
    if instr(SmblName,"ES") = 2 then SmblName = "@ES" 
    else if instr(SmblName,"NQ") = 2 then SmblName = "@NQ"
    else if instr(SmblName,"YM") = 2 then SmblName = "@YM"
    else if instr(SmblName,"EMD") = 2 then SmblName = "@EMD"
    else if instr(SmblName,"TF") = 2 then SmblName = "@TF"
    else SmblName = "XXXXX";
    
    return Command(Cmd,Account,SmblName,Action,Quantity,OrderType,LimitPrice,StopPrice,"Day","",OrderId,"","");
    end;
    
    //METHOD TO CHANGE ORDER
    method int NTChg(string NTOID, int Qty, double LimPr, double StPr)
    begin
    
    return Command("Change", "", "", "", Qty, "", LimPr, StPr, "", "", NTOID, "", "");
    end;
    
    //METHOD TO STATUS ORDER
    method string NTOS(string OID)
    begin
    
    return OrderStatus(OID);
    end;
    
    once begin
    	SetAllocReturnString(1);				{ alloc memory for returned string, TS will free that memory 	}
    	SetMaxReturnStringLength(13);			{ limit the max length of return string to 500 					}
    end;
    
    input:
    	NTEnable(false);
    	
    	
    var:
    	double MA(close),
    	string NTOID("");					
    
    
    if date <> date[1] then begin
    	MA = open;
    	NTOID = "";
    	
    	end else begin
    	
    	MA = 0.02*close + 0.98*MA;
    	plot1(MA,"MA",red,default,0.50);
    	
    	if barstatus(1) = 2 
    	and low > MA
    	and NTOID = ""
    	and getappinfo(airealtimecalc) = 1
    	then begin
    	NTOID = numtostr(Sec,0);
    	value1 = NTCMD("PLACE","Sim101","Buy",1,"Limit",low,0,NTOID);
    	end;
    	
    	if barstatus(1) = 2
    	
    	and (NTOS(NTOID) = "Working" or NTOS(NTOID) = "PartFilled")
    	then begin
    	value2 = NTChg(NTOID,0,low,0);
    	end;
    	
    	if barstatus(1) = 2 then print(time:0:0,"	",NTOS(NTOID),"	",value1:0:0,"	",value2:0:0);
    	
    	
    end;
    Thank you for any assistance.

    #2
    Hi Atomic, thanks for the post on those items - let us try to clarify.

    1. It should be a simple one, correct.
    2. Should only be need to get called one time on startup.
    3. This will determine if memory should be allocated, int 1 would equal true so all you need here.
    4. We're not aware of a memory leak scenario, if you have a simplified setup we would be happy to give it a run here. This parameter blocks the memory needed and returns a pointer to it, the smaller the value, the less memory is needed.
    5. The lines would be using default, so only include them if you want to change to other values. They are class variables so during startup / initialization once would be fine.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      Hi Atomic, thanks for the post on those items - let us try to clarify.

      1. It should be a simple one, correct.
      2. Should only be need to get called one time on startup.
      3. This will determine if memory should be allocated, int 1 would equal true so all you need here.
      4. We're not aware of a memory leak scenario, if you have a simplified setup we would be happy to give it a run here. This parameter blocks the memory needed and returns a pointer to it, the smaller the value, the less memory is needed.
      5. The lines would be using default, so only include them if you want to change to other values. They are class variables so during startup / initialization once would be fine.
      Thanks very much. This may help clear up the problem I've had with memory leak. I'll try to set up some code to demonstrate the memory leak.

      Comment


        #4
        Hi, did you get answers?
        I have C++ exceptions soetimes when calling NTOrderStatus...

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by algospoke, 04-17-2024, 06:40 PM
        6 responses
        48 views
        0 likes
        Last Post algospoke  
        Started by arvidvanstaey, Today, 02:19 PM
        4 responses
        11 views
        0 likes
        Last Post arvidvanstaey  
        Started by samish18, 04-17-2024, 08:57 AM
        16 responses
        61 views
        0 likes
        Last Post samish18  
        Started by jordanq2, Today, 03:10 PM
        2 responses
        9 views
        0 likes
        Last Post jordanq2  
        Started by traderqz, Today, 12:06 AM
        10 responses
        21 views
        0 likes
        Last Post traderqz  
        Working...
        X