SetAllocReturnString(1); { alloc memory for returned string, TS will free that memory } SetMaxReturnStringLength(13); { limit the max length of return string to 500
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.
{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;
Comment