PDA

View Full Version : NTMarketposition for IB


jonno
02-02-2006, 02:22 PM
I am using Tradestation8 --> IB and wish to check that *IB* does not have a position before I send an order.

I noticed that the NTMarketposition function uses the TRADESTATION "marketposition" command. That will not return the marketposition for Interactive Brokers !

Is there a command that I can use to get the IB marketposition.

Thanks

NinjaTrader_Ray
02-02-2006, 02:57 PM
The function calls a method on the NT DLL called marketposition and is not to be confused with the EL reserved word "marketposition". NTMarketPosition will return what you are looking for.

jonno
02-02-2006, 03:29 PM
whilst i havent tried it yet im concerned it will not work, because you have used a TS reserved word which the easylanguage compiler recognises.

for example when i open up the function, the "marketposition" command is highlighted in blue - this means that tradestation has automatically recognised it as a built in TS reserved word.

NinjaTrader_Dierk
02-02-2006, 04:01 PM
No, it works fine. Check out e.g. NTSample strategy.

jonno
02-02-2006, 09:49 PM
ok thanks.

jonno
02-13-2006, 07:40 AM
Dierk
I had a problem in testing today with NTmarketposition returning zero, for a position that i held in IB.

it was for "IWM" stock symbol.

i was using a print statement to verify that NTmarketposition was returning the correct value. it read as:

print(date,time,NTmarketposition("IWM",""));

the default account was set to be my live IB account which held the position. i am ASSUMING that the account code can be left blank on this call if you are using the default account.

the print statement returned the following output:

1060213.001438.00imktpos=-1 -100.00 0.00

(the -100 is the TS strategy). the 0.00 is what NTmarketposition returned

one thing to mention: i am not receiving market data into IB for IWM. however placing orders via the NT ATI works 100% OK if no checks are being made with regards to NTmarketposition.

can you please let me know if i am doing something wrong or whether perhaps this is a bug in NT ATI

thanks

jonno
02-13-2006, 07:44 AM
apologies, i had the wrong piece of code pasted for that routine. it should have been:
.............
NTContracts=NTmarketposition(NTProductCode,"");

print(date,time,"imktpos=-1 ",TSContracts,NTContracts);

{please note that NTProductCode = "IWM"}

NinjaTrader_Ray
02-13-2006, 08:44 AM
Jonno,

NTMarketPosition does not take the stock symbol as an argument. Not sure if this is causing the issue.

print(NTMarketPosition(""));

should print out the correct position for the instrument loaded in the TS chart that your strategy is applied to.

Ray

PS - Forgot to add that you are correct in your understanding of the default account use.

jonno
02-13-2006, 02:30 PM
Ray
ray you are right, i had actually changed the P1 parameter in the NTmarketposition function/DLL to be passed in as a string as opposed to the chart based TS EL symbol retrieve that was being done. sorry i also forgot to mention that! no more surprises i promise. :-)

can i request an enhancement that the NTmarketposition function allows you to explicitly pass the product code?

I am trying to do symbol substitution, where when i get a signal on the russell via an applied strategy, i am sending orders for IWM. part of this *requires* position checks on IWM which does not seem possible from the ER2 chart.

i would think that plenty of users will find it useful to be able to pass the product code to the NTmarketposition function call as opposed to hard coded symbol retrieve.

thanks
angus

NinjaTrader_Ray
02-14-2006, 12:17 AM
Angus,

Thanks for your suggestion. Will add to list for consideration.

Ray

NinjaTrader_Ray
02-14-2006, 03:36 AM
Actually, the underlying DLL function is implemented with symbol/account name. Its just the NTMarketPosition wrapper function that handles it for convenience.

Open up the NTMarketPosition function in EL and create a new one that takes the symbol name as an input.

Ray

jonno
02-23-2006, 03:05 PM
i tried that id did not work. appreciate if u can look at this and let me know if i have done something wrong. if not, can u pls let me know when it will be fixed? i am having to resort to TradeBolt in the meantime.

here is the modified wrapper:

{ ** Copyright (c) 2005, NinjaTrader LLC ninjatrader@ninjatrader.com }
DefineDLLFunc: "NtDirect.dll", int, "MarketPosition", lpstr, lpstr;
inputs: Account(string),ProductCode(string);

NTMarketPosition = MarketPosition(ProductCode, Account);

-------------------------------------------------------------------------------------------------------

here is a little test indicator that i applied to a chart:

value1 = NTMarketPosition("IWM",""); {def acct = live account in NT options setup}
{ it also does not work if i explicitly define my
account number as parameter 2 string}
print(date,time,symbol," ",value1);

---------------------------------------------------------------------------------------------------------

here is the print output:

1060224.001300.00IB:KSH6 0.00 <=== you can see that it is not picking up the IB position that currently exists in my live account
1060224.001300.00IB:KSH6 0.00
1060224.001300.00IB:KSH6 0.00

----------------------------------------------------------------------------------------------------------

NinjaTrader_Ray
02-24-2006, 12:34 AM
Is Automated Trading Enabled via the File--> menu?

jonno
02-24-2006, 01:36 AM
yes

NinjaTrader_Ray
02-24-2006, 03:05 AM
The MarketPosition function will only return information for positions created through the ATI. The ATI does write all position information to a files (See the file interface section) indpendant if they were created through the ATI or not. This might be an alternate approach.

Ray

NinjaTrader_Ray
02-24-2006, 03:06 AM
I will update the DOC to clarify this limitation.

Ray

jonno
02-24-2006, 03:19 AM
ray can u give any time estimate on when this would be fixed ?

NinjaTrader_Ray
02-24-2006, 03:29 AM
Hi Jonno,

Not at this time. This is on the list for as a feature request. This limitation is be design although not desired design.

Ray