View Full Version : NTMARKETPOSITION = Trouble / Bug
BIGRED
02-27-2008, 11:50 PM
I have spent the last 2 days grinding through what I have thought was coding problems on my TS EL strategy.
By taking it apart and putting it back together, I found that ntmarketposition does not work properly.
My code makes use of....
NTMARKETPOSITION("") =0
NTMARKETPOSITION("") =1,
NTMARKETPOSITION("") =-1
By replacing NTMARKETPOSITION with the TS function, marketposition, I was able (it seems) to get the strategy to work as it should.
NinjaTrader_Josh
02-27-2008, 11:55 PM
Can you please be a little more descriptive about the problem you are facing? Not sure what you mean at the moment. Also see if using NTMarketPosition("") instead of NTMARKETPOSITION("") helps.
BIGRED
02-28-2008, 12:07 AM
Josh,
I did not go through the narrowing down process to be 100% sure of the problem. It feels like it reports nothing but 0.
If I was short and I had a buy signal, no auto trades. If I took it flat manually, it would cause an automated buy. If I was short the reverse would happen.
I was typing one handed and therefore the caps for NTMarketPosition.
I had it in the code as NTMarketPosition("").
Thanks,
Don
NinjaTrader_Josh
02-28-2008, 01:03 AM
Try just printing NTMarketPosition() on every bar without running logic.
BIGRED
02-28-2008, 01:22 AM
Josh,
I created an EL indicator.
The value of NTMarkettPositon("") = the net market position in size not in a 1 or -1 value.
In my case my net position size is 10000. Being a reversal system, the indicator is either 10,000 or -10,000. I say net because I begin with a manual 10,000 position and then auto trade 20,000 long and 20,000 short and so on.
Don
NinjaTrader_Josh
02-28-2008, 01:31 AM
Right. That is what it is suppose to do.
BIGRED
02-28-2008, 01:35 AM
Sorry for the trouble...
In EL (similar name), it operates differently.
I guess I have learned that I will do a print command or create an indicator for every function before using it!
Thank you
Don
BIGRED
02-28-2008, 09:32 AM
This morning the indicator was only producing a zero result.
Restarted the computer, Ninja and TS. Same thing.
Reinstalled NT, no difference. NTMarketPosition("") is only putting out a value of "0" no matter the market position.
Don
NinjaTrader_Ray
02-28-2008, 10:10 AM
What NT version are you using?
Try passing in the account number and see if it makes a difference.
BIGRED
02-28-2008, 02:46 PM
Ray,
I am running 6.5.0.9
That didn't work
While now the indicator is moving to correct values (used regedit and did fresh install of NT) , when used in this way....
Not as programmed in EL but to explain the issue
If NTMarketPosition("sim101") <= -10000 then begin;
Buy 10000 at market
It continues to buy over and over.
Thanks
Don
NinjaTrader_Ray
02-28-2008, 02:49 PM
That would be expected behaviour. Each call to any function to place an order *will* place an order. If you only want to place one, then you need to code for that.
BIGRED
02-28-2008, 03:07 PM
How can it place more than one order if it is being restricted by the current positon size? The order is conditional. The condition is being short 10,000 or more.
NinjaTrader_Ray
02-28-2008, 03:12 PM
Then the condition must continously be true for the order placement method to be continously called, maybe you are running the strategy on historical bars in which case it could place a tonne of orders before the first order is actually filled?
In any case, you will need to debug to see what is happening but what is certain is the order function is being called many times.
BIGRED
02-28-2008, 03:17 PM
If the chart is on a long signal and my position has grown to 70k and keeps going, something is wrong with NTMarketPosition.
No argument it is being called many times, but if the code says to only allow a trade to take place if the position is less than 10,000 and the position size is 70000, then 80000 and so on, the function is not doing what is intended.
NinjaTrader_Ray
02-28-2008, 03:50 PM
Lets not mix apples and oranges.
- Orders are placed since the order function is called many times --> This works as expected
- What you are saying is that the NTMarketPosition() is not updating correctly. That is not the question you asked me.
Please create a strategy that has the following code:
Print(NTMarketPosition("Sim101"));
- Start NT
- Enable Automated Trading Interface
- Start TS
- Open a chart, does not matter what instrument as long as the market is trading
- Connect NT to whatever feed you are using
- In the Control Center Order Panel, select the same instrument that you have a chart open for
- Place an market order to buy
- Verify there is an open position in the Control Center Position tab
- Apply the strategy to the chart
- You should see in the EL output window the correct position size that is displayed in the NT Positions tab
--> If this is not the case let me know
BIGRED
02-28-2008, 04:21 PM
I get zeros.
BIGRED
02-28-2008, 04:37 PM
Maybe some relationship to another problem...I am posting under beta application...
NT will not start without it being re-installed each time I close the program.
Don
NinjaTrader_Ray
02-28-2008, 07:39 PM
Could very well be. For sure it sounds like your PC does not like NT installed on it. I will leave it to Dierk to see if he has any other ideas on the other thread regarding the re-installation issue.
BIGRED
02-28-2008, 07:42 PM
(shrugs shoulders) its a new computer (3 months old).
Going to play with one of my others - Although a win2k machine.
BIGRED
02-29-2008, 06:34 AM
Problem is related to NT in my HP Vista computer. The issue is not happening in the Win2k machine. NTMarketPosition is working as it should.
Don
moscu
02-29-2008, 09:15 AM
NinjaTrader_Ray:
I am seeing the same problem that BIGRED. Sometimes I get filled and the order status changes but the NtMarketPosition(Account) stills returns 0 when it should return something <> 0 to indicate the position.
I have the following function in EL:
AtsNTMarketPosition = 0;
If NtConnected(0) Then Begin
Value1 = NtMarketPosition(Account);
If Value1 < 0 Then
AtsNTMarketPosition = -1
Else If Value1 > 0 Then
AtsNTMarketPosition = 1;
End;
It is supposed to return 1/-1/0. When I create a new order I save the order id to a variable and I monitor the status with the function
Status = NtOrderStatus(OrderId).
WHen the status changes:
Status = "Filled" Or Status = "PartFilled" Or Status = "Cancelled" Or Status = "Rejected"
At this moment I call the NtFilled(OrderId) function and correctly reports the amount of contracts filled but the NtMarketPosition returns 0.
At this point I mark the order as filled but since the position is 0 my code send another other. Of course at this point the market position is correctly returned. This problem is intermittent. For example today I got filled 3 orders one filled ok the other two were filled twice. Yesterday I had not problems at all. I seen this problem when I run in NT simulated account as well as now running IB simulated account. No all the orders have this problem and I seeing it happening in all the versions I used. Basically the problem is that when NtStatus changes the MarketPosition needs to be updated at the same time. I could use the NtFilled to workaround but it would just make the whole thing to complex.
Here is the log I print when I run my strategy from TS:
DATE TIME TICK COMPUTERTIME ORDERID LOG
02/29/2008 , 1012 , 68 , 10:11:34 AM , JCP-1080229-1012-68 , PLACE,,100,0.00,0.00,,JCP-1080229-1012-68,SE H1 , MP=0 , Command-Returns=0
02/29/2008 , 1012 , 77 , 10:11:35 AM , JCP-1080229-1012-68 , PROCESSING, status=PendingSubmit , order=SELL-0.00-0.00-100.00 , position= 0 , curent shares= 0
02/29/2008 , 1012 , 78 , 10:11:35 AM , JCP-1080229-1012-68 , PROCESSING, status=PendingSubmit , order=SELL-0.00-0.00-100.00 , position= 0 , curent shares= 0
02/29/2008 , 1012 , 79 , 10:11:35 AM , JCP-1080229-1012-68 , REMOVING, status=Filled , order=SELL-0.00-0.00-100.00 , position= 0 , curent shares= 0 , filled= 100
02/29/2008 , 1012 , 82 , 10:11:35 AM , JCP-1080229-1012-68 , PLACE,,100,0.00,0.00,,JCP-1080229-1012-68,SE H1 , MP=0 , Command-Returns=0
02/29/2008 , 1012 , 82 , 10:11:35 AM , JCP-1080229-1012-68 , REMOVING, status=Filled , order=SELL-0.00-0.00-100.00 , position= 0 , curent shares= 100 , filled= 100
02/29/2008 , 1016 , 23 , 10:15:00 AM , JCP-1080229-1016-23 , PLACE,,100,0.00,0.00,,JCP-1080229-1016-23,SX H Prof 1 , MP=-1 , Command-Returns=0
02/29/2008 , 1016 , 25 , 10:15:03 AM , JCP-1080229-1016-23 , REMOVING, status=Filled , order=BUY-0.00-0.00-100.00 , position= -1 , curent shares= 100 , filled= 100
02/29/2008 , 1018 , 11 , 10:17:07 AM , JCP-1080229-1018-11 , PLACE,,100,0.00,0.00,,JCP-1080229-1018-11,SX H Bailout , MP=-1 , Command-Returns=0
02/29/2008 , 1018 , 12 , 10:17:09 AM , JCP-1080229-1018-11 , REMOVING, status=Filled , order=BUY-0.00-0.00-100.00 , position= 0 , curent shares= 0 , filled= 100
Moscu
BIGRED
02-29-2008, 09:58 AM
And today... NTMarketPosition is working on the HP computer.
moscu
08-26-2008, 12:17 PM
Today I have the problem where the order is filled but the NTDirect DLL fails to update the status.
I sent an order at to BUY MEE at 11:01:08 AM when the price was 64.35.
The order was an stop at 64.39 for 400 shares
Here is the fill as reported by IB "Trades" window (The audit trail shows the same times also):
MEE;STK;;;;;BOT;100;64.43;11:01:21;20080826;ISLAND ;
MEE;STK;;;;;BOT;200;64.44;11:01:21;20080826;NYSE;
MEE;STK;;;;;BOT;100;64.44;11:01:21;20080826;NYSE;
Notice from the NT log that the first partial fills are reported relativelly on time "11:01:33" but the last fill of 100 shares is reported on 11:03:14 that is almost 2 min later.
8/26/2008 11:03:14,Position,Instrument='MEE' Avg price=64.4425 Quantity=400 Market position=Long
8/26/2008 11:03:14,Order,New State=Filled Instrument='MEE' Action=Buy price=0 Stop price=64.39 Quantity=400 Type=Stop Filled=400 Fill price=64.44
8/26/2008 11:03:14,Execution,Execution='MEE/0001f028.48b42502.01.01' Instrument='MEE' Exchange=Nyse Price=64.44 Quantity=100 Market position=Long
8/26/2008 11:01:33,Order,New State=PartFilled Instrument='MEE' Action=Buy price=0 Stop price=64.39 Quantity=400 Type=Stop Filled=300 Fill price=64.44
8/26/2008 11:01:33,Order,New State=PartFilled Instrument='MEE' Action=Buy price=0 Stop price=64.39 Quantity=400 Type=Stop Filled=300 Fill price=64.44
8/26/2008 11:01:33,Execution,Execution='MEE/0001f028.48b42501.01.01' Instrument='MEE' Exchange=Nyse Price=64.44 Quantity=200 Market position=Long
8/26/2008 11:01:33,Order,New State=PartFilled Instrument='MEE' Action=Buy price=0 Stop price=64.39 Quantity=400 Type=Stop Filled=100 Fill price=64.43
8/26/2008 11:01:33,Order,New State=PartFilled Instrument='MEE' Action=Buy price=0 Stop price=64.39 Quantity=400 Type=Stop Filled=100 Fill price=64.43
8/26/2008 11:01:33,Execution,Execution='MEE/0000e69b.48b3f6f7.01.01' Instrument='MEE' Exchange=Island Price=64.43 Quantity=100 Market position=Long
8/26/2008 11:01:33,Order,New State=PartFilled Instrument='MEE' Action=Buy price=0 Stop price=64.39 Quantity=400 Type=Stop Filled=100 Fill price=64.43
8/26/2008 11:01:26,Order,New State=Accepted Instrument='MEE' Action=Buy price=0 Stop price=64.39 Quantity=400 Type=Stop Filled=0 Fill price=0
8/26/2008 11:01:25,Order,New State=PendingSubmit Instrument='MEE' Action=Buy price=0 Stop price=64.39 Quantity=400 Type=Stop Filled=0 Fill price=0
8/26/2008 11:01:25,ATI,AT, 'PLACE;XXXX123;MEE;BUY;400;STOP;0;64.39;DAY;;BUY-MEE-1080826-1101-35-STOP-64.39;;' processing
NinjaTrader_Dierk
08-26-2008, 12:35 PM
NT reports order fills as the IB API sends them to NT. No delay is imposed. Please contact IB support to understand why their traces show something different than what the IB API actually does.
moscu
09-15-2008, 11:03 PM
I just want to post a new find that I have for those of you having the same problem. I have create to function that mimics the TS functions MarketPosition and CurrentShares with NT calls as follows:
here is the version of MaketPosition
Inputs:
Account(string);
AtsNTMarketPosition = 0;
If NtConnected(0) Then Begin
Value1 = NtMarketPosition(Account);
If Value1 < 0 Then
AtsNTMarketPosition = -1
Else If Value1 > 0 Then
AtsNTMarketPosition = 1;
End;
here is the version of CurrentShares:
Inputs:
TradeAccount(string);
Variables:
Current_Shares(0);
Current_Shares = 0;
If NtConnected(0) Then Begin
Current_Shares = AbsValue(NtMarketPosition(TradeAccount));
End;
AtsNtCurrentShares = Current_Shares;
They call the same NT function therefore they should return similar data. But they do not the MarketPosition returns 0 instead or 1/-1 when the version of CurrentShares is returning a value > 0. Looking at my version the only thing I can see is the use of Value1 in MarketPosition. This might be getting over written some how. So I changed my function to:
Inputs:
Account(string);
Variables:
MP(0);
AtsNTMarketPosition = 0;
If NtConnected(0) Then Begin
MP = NtMarketPosition(Account);
If MP < 0 Then
AtsNTMarketPosition = -1
Else If MP > 0 Then
AtsNTMarketPosition = 1;
End;
This creates a variable MP which is locally initialized to 0.
I hope this help to somebody.
Moscu