PDA

View Full Version : Problem With ATI Interface and Using NTCommand


Widgetman
11-20-2006, 04:20 AM
Hi,
I am working on some custom Easy language scripts with the ATI interface to Ninjatrader. In using the NTCommand listed below I ran into a issue. It seems that if I send a Market or Limit order with the NTCommand my stop is ignored. In the log I see the order come in as a market order, and the stop I passed in shows up in the stop field, but when my Strategy receives the order it uses the stop setup in the strategy option under the strategy box not the stop I passed in. Is there a way around this ? Any comments or help would be appreciated.
Thanks


SendCommandSuccess = NTCommand("PLACE","AcctName","SELL",1,"MARKET",0,(localmax + .0002),"GTC","",orderidstring,"StradegyName","");

NinjaTrader_Ray
11-20-2006, 04:26 AM
Widgetman,

Not sure I follow exactly. To be sure:

- Does your initial entry order also call a NT strategy template which then auto submits your stop and targets?

- If yes, once the stop/target is in place, what further action do you want your EL strategy to do

Ray

Widgetman
11-20-2006, 05:13 AM
Hi Ray,
Thanks for the quick response. The issue I am having is I want to pass in the stop which is represented below. In the NTCommand below I am sending a sell market order with no limit price, and a stop of (localmax + .0002). This would vary on a stop for the euro from .0005 to .0008 depending on some other variables in my equations. The issue I have is when the order comes in I see the sell market order with the correct stop that I sent in the log. After it fills I then see a Buylimit order pop up with a limit and stop of what I assume is set by the strategy template. It seems to overide my ATI stop. In the Ninja strategy I manually set the target to 8 pips, and my stop to 1 pip since I can not set it to 0. I also use the custom stop strategy option and set step 1 to values of 6 1 6. I have played with those numbers in different ways and it did not seem to matter. My question is how do I tell the strategy I created to use the stop I passed in with the NTCommand via the ATI instead of the hard stop I must enter in the strategy template.

NinjaTrader_Ray
11-20-2006, 06:05 AM
I see.

For clarification:

- Order is placed which references a strategy
- Order is filled strategy submits stops/targets
- You then want to modify the price of the automatically submitted stop order to a new price

If that is correct, you need to call the NTCommand()

Instead of "PLACE" pass in "CHANGE", pass in "STOP1" if you are modifying the 1st stop order, pass in a new stop price and pass in the unique strategy id that you used when you create the initial entry order.

Ray

Widgetman
11-20-2006, 06:34 AM
Hi Ray,
Listed below is what I think you mean. If I am passing in a strategy name and I also get a unique orderID before I send the order why do I still need a unique strategy id ?
Can that strategy id be anything and how does that correlate to the name of the actual strategy I created in the DOM ?
Thanks

NTCommand(string command, string account, string action, int quantity, string orderType, double limitPrice, double stopPrice, string timeInForce, string oco, string orderId, string strategy, string strategyId)



// Send This Command To Place Order
SendCommandSuccess = NTCommand("PLACE","AcctID","SELL",1,"MARKET","","","GTC","",orderidstring,"StrategyName","StrategyID");

// Send This Command To Change Stop Of STrategy ???
SendCommandSuccess = NTCommand("PLACE","AcctID","CHANGE","","","",(localmax + .0002),"GTC","",orderidstring,"StrategyName","StrategyID");

NinjaTrader_Ray
11-20-2006, 08:00 AM
Should look something like the code below. You need a unique strategy id since NT needs to know which strategie's stop1 order to change.



// Send This Command To Change Stop Of STrategy
SendCommandSuccess = NTCommand("CHANGE","AcctID","","","","",(localmax + .0002),"GTC","","STOP1","","YourStrategyId");

NinjaTrader_Ray
11-20-2006, 08:04 AM
Actually,

I believe it should look like this. I have excluded order qty value since I believe it is ignored if empty string.

SendCommandSuccess = NTCommand("CHANGE","","","","","0",(localmax + .0002),"","","STOP1","","YourStrategyId");

Widgetman
11-21-2006, 08:22 AM
Hi Ray,

Thanks for the help. I tried what you said and passed in a strategy ID. Listed below is what I tried. What I saw happen is I got a message back in the log stating 'No Such order'. I also noted that even though I got a new orderid before I sent the market order Once it filled the order id was different. My question is how do I get back the order ID that actually filled from the market order sent. It appears that the two are different.

orderidstring = NTNewOrderId();

SendCommandSuccess = NTCommand("PLACE","ACCTID","SELL",1,"MARKET",0,(localmax + .0002),"GTC","","","STRATEGY","STRATEGY");

SendCommandSuccess = NTCommand("CHANGE","ACCTID","",0,"",0,(localmax + .0002),"GTC","","STOP1","STRATEGY","STRATEGYID");

NinjaTrader_Ray
11-21-2006, 08:59 AM
Looks like you are not generating a unique strategy id.

strategyIdString = "SomeRandomUniqueValue"

ndCommandSuccess = NTCommand("PLACE","ACCTID","SELL",1,"MARKET",0,(localmax + .0002),"GTC","","","STRATEGY",strategyIdString);

SendCommandSuccess = NTCommand("CHANGE","ACCTID","",0,"",0,(localmax + .0002),"GTC","","STOP1","",strategyIdString);

Widgetman
11-21-2006, 10:12 AM
Hi Ray,

I did generate a unique strategy ID called Monky69

I set the strategy ID in both NTCommand strings to "Monky69" which is the last parameter of 12 in the NTCommand String. It came back and told me no such order. Please post me a NTCommand string that you thinks works so I can try it if you have time.



-Thanks

NinjaTrader_Ray
11-21-2006, 10:19 AM
Widgetman,

You can use the Automated Trading OIF builder via Tools menu. This generates a string representation of what the Command function should look like.

Ray

Widgetman
11-21-2006, 10:30 AM
Ray,

That was a excellent idea. I built a sell command in the OIF builder and listed below is what it generated. My question now is your help file online shows 12 parameters in the NTCommand Function. The OIF string listed below shows 13. Which is correct ?



PLACE;SIM101;6E 12-06;SELL;1;MARKET;0;0;DAY;OCO1;IDName;Mann;Monky69

NinjaTrader_Ray
11-21-2006, 10:34 AM
12 is correct. OIF requires the insrument string. The NTCommand function itself is a wrapper around the DLL function Command which is actually built from 13 parameters. The wrapper just takes care of the instrument parameter for you.

Ray

Widgetman
11-22-2006, 02:55 AM
Hi Ray,

Listed below is a log of a order that fired earlier from a cuctom system I am developing. I tried the things you suggested and found that no matter what I call the strategy ID variable the order to change a stop after I get a filled market order is rejected. I was wondering if there was any scripts available in easy language that I could look at. I am sure it is something I may be doing wrong, but I want to eliminate the possibility that the ATI interface may not work quite right with a Easy Language type interface. Any suggestions or help you could privide would be appreciated. I currently do development for a few customers of yours and I want to continue to support them in the future.

-Thanks

// Here Is The Command Lines I Am Sending In Easy Language

SendCommandSuccess = NTCommand("PLACE","ACCTID","SELL",1,"MARKET",0,(localmax + .0002),"GTC","","Order1","Strategy","StrategyID");

OrderStatus = NTOrders("AcctID");

print("Order Status Is ",OrderStatus:0:4);

SendCommandSuccess = NTCommand("CHANGE","","",0,"",0,(localmax + .0002),"","","Order1","Strategy","StrategyID");





11/22/2006 10:37StrategyCancelling any remaining strategy orders
11/22/2006 10:37ExecutionExecution='6E 12-06/0001f4e5.44231579.01.01' Instrument='6E 12-06' Account='ACCTID' Exchange=Globex Price=1.2959 Quantity=1 Market position=Short Operation=Insert Order='268711972' Time='11/22/2006 10:37:30 AM'
11/22/2006 10:37OrderOrder='268711972/ACCTID' Name='Stop1' New State=Filled Instrument='6E 12-06' Action=Sell Limit price=1.2939 Stop price=1.2959 Quantity=1 Type=StopLimit Filled=1 Fill price=1.2959 Error=NoError Native error=''
11/22/2006 10:37OrderOrder='268711972/ACCTID' Name='Stop1' New State=Working Instrument='6E 12-06' Action=Sell Limit price=1.2939 Stop price=1.2959 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''
11/22/2006 10:37OrderOrder='268711973/ACCTID' Name='Target1' New State=PendingCancel Instrument='6E 12-06' Action=Sell Limit price=1.2971 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
11/22/2006 10:36OrderOrder='268711973/ACCTID' Name='Target1' New State=Working Instrument='6E 12-06' Action=Sell Limit price=1.2971 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
11/22/2006 10:36OrderOrder='268711973/ACCTID' Name='Target1' New State=Accepted Instrument='6E 12-06' Action=Sell Limit price=1.2971 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
11/22/2006 10:36OrderOrder='268711972/ACCTID' Name='Stop1' New State=Accepted Instrument='6E 12-06' Action=Sell Limit price=1.2939 Stop price=1.2959 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''
11/22/2006 10:36OrderOrder='5dc96e54f510485087e2a23587ad3b5e/ACCTID' Name='Target1' New State=PendingSubmit Instrument='6E 12-06' Action=Sell Limit price=1.2971 Stop price=0 Quantity=1 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
11/22/2006 10:36OrderOrder='fd70704700e14dc8960f046b4409a159/ACCTID' Name='Stop1' New State=PendingSubmit Instrument='6E 12-06' Action=Sell Limit price=1.2939 Stop price=1.2959 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''
11/22/2006 10:36PositionInstrument='6E 12-06' Account='ACCTID' Avg price=1.2963228 Quantity=1 Market position=Long Operation=Insert Currency=UsDollar
11/22/2006 10:36ExecutionExecution='6E 12-06/0001f4e5.4423152a.01.01' Instrument='6E 12-06' Account='ACCTID' Exchange=Globex Price=1.2963 Quantity=1 Market position=Long Operation=Insert Order='268711971' Time='11/22/2006 10:36:22 AM'
11/22/2006 10:36OrderOrder='268711971/ACCTID' Name='Entry' New State=Filled Instrument='6E 12-06' Action=Buy Limit price=0 Stop price=1.2957 Quantity=1 Type=Market Filled=1 Fill price=1.2963 Error=NoError Native error=''
11/22/2006 10:36OrderOrder='268711971/ACCTID' Name='Entry' New State=Working Instrument='6E 12-06' Action=Buy Limit price=0 Stop price=1.2957 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
11/22/2006 10:36OrderOrder='268711971/ACCTID' Name='Entry' New State=Accepted Instrument='6E 12-06' Action=Buy Limit price=0 Stop price=1.2957 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
11/22/2006 10:36ATIOIF 'CHANGE;;6EZ6;;0;;0;1.2957;;;Order1;StrategyName;S trategyID' invalid order ID/Name 'Order1'
11/22/2006 10:36ATIAT 'CHANGE;;6EZ6;;0;;0;1.2957;;;Order1;StrategyName;S trategyID' processing
11/22/2006 10:36OrderOrder='2d8d02814066430091795881d4eac66b/ACCTID' Name='Entry' New State=PendingSubmit Instrument='6E 12-06' Action=Buy Limit price=0 Stop price=1.2957 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
11/22/2006 10:36OrderSubmitting order with strategy

NinjaTrader_Ray
11-22-2006, 03:02 AM
Your are submitting too fast.

Do this:

Submit the Place command. Wait a minute (to be safe), the strategy will have submitted the stop and targets.

Then issue a change to the STOP1.

SendCommandSuccess = NTCommand("CHANGE","","",0,"",0,(localmax + .0002),"","","STOP1","","StrategyID");

Widgetman
11-22-2006, 03:05 AM
Thanks Ray for all the support. I suspected I may too fast but I am not sure if I can delay in easy language. Would it be safe to use the NTOrderStatus function to wait for the filled word to be returned ?

NinjaTrader_Ray
11-22-2006, 03:44 AM
Yes that would be safe.

Widgetman
11-23-2006, 02:03 AM
Hi Ray,

Thanks for all the help. I finally got a change command to work but discovered that when working with tick charts and currencies the change order can not be processed until the next bar due to limitation in the easy language Engine. This means that until tick = 0 for the current bar I must wait to update variables and process changes. This results in a delay of the change order going in. I am going to experiment some more with the state machine and see if I can improve it.

Widgetman
11-23-2006, 02:19 AM
Hi Ray,

I forgot to ask why is it the NTCommand that sends a order over initially has a place for a stop yet the strategy ignores it. In the same command I am passing over the strategy name to use with the order so it seems like it would use the stop from the order rather than a default. That would eliminate the delay issues I see with Easy language as a interface to the ATI.



-Thanks

NinjaTrader_Ray
11-23-2006, 02:33 AM
The ATI is flexible.

1) You can submit an entry order and have this order execute an ASM strategy that automatically submits stops and targets

2) You can submit any order type you want and manage the trade exclusively from an external application

This is why the NTCommand() needs the parameters it has to support this level of flexibility.



Ray

Widgetman
11-24-2006, 12:09 AM
Hi Ray,
Thanks for letting me know that. the problem I have with that approach is I calculate a dynamic stop based on the movement of the last wave in my futures I am trading so the stop would be different each time. Will the ASM take the value I pass in with the order command and use that as a stop ? Right now I am passing in a strategy name which as a hard stop and target programmed into it. I then look for the filled status to come back and send another order to change the stop. Like I stated earlier this is delayed due to the easy language engine only being able to do certain things on the close of a bar which means my change order is 1-2 bars later.

NinjaTrader_Ray
11-24-2006, 02:34 AM
Your approach right now is correct. The only other option is NOT to use ASM strategy and submit all stops and targets yourself.


Ray