PDA

View Full Version : Tradestation Interface to Ninjatrader example


Widgetman
06-01-2006, 04:01 AM
Hi,

I am trying to get a simple example working in easy language that will fire 1 order off through the ATI, and not send any more orders until that position is flat and there are no positions. Would anyone have a example I could look at which is written for easy language? Any help would be greatly appreciated.

Thanks

NinjaTrader_Ray
06-01-2006, 04:39 AM
Did you look at the sample script provided with NT installation? See Help Guide.

Widgetman
06-01-2006, 05:22 AM
Hi,

Yes I did try the small example provided. What I found was the example sent many orders which varied from 1 to 5 before the first order could get filled. Is there a way to tell the ATI to only send one order and a stop if it has another order pending ?



Here is a sample of what I tried



NotInTrade = NTMarketPosition("MyAcctId");

if LastBarOnChart and NTConnected(1) and (NotInTrade = 0) then



begin





Success = NTBuyMarket("",1); // Send Market Order

NotInTrade = 1; // Set Flag Immediately To Indicate I Sent An Order

Success = NTSellStop("",1,InsideBid -.0010); // Send Stop

end;

NinjaTrader_Ray
06-01-2006, 05:31 AM
How about createa variable? I am no EL expert but in plain english:

var placed = false;

if (placed == false)
placeOrder

Widgetman
06-01-2006, 05:44 AM
Well in the code snippet I showed earlier I have a variable called NotInTrade that is suppose to reflect the current position state. If I get a order filled it was my assumption that NotInTrade = NTMarketPosition("MyAcctId") would not return 0

This should stop theIF statement which checks for NotInTrade = 0from sending any more trades. I even went to the trouble of setting the flag just after I send a market order to a 1 which would stop the loop from firing again. I still see more than one trade from being sent and it also sends more orders on the next trigger condition even if I currently have some orders filled. Am I missing something here on how NTMarketPosition works ?

NinjaTrader_Ray
06-01-2006, 07:50 AM
Widgetman,

My apologies. I just tested the script and experience the same results as you. I will forward to development for further investigation. NTMarketPosition() should return a value other than zero if not flat. We will have this resolved with our next update.

Ray

Widgetman
06-01-2006, 09:13 AM
Hi Ray,
Thanks for all the help. I really would like to use your system to interface my custom trading system. Any ideas as to how long it would take to get fixed ? I also am a Engineer so if there is anything i can do to help with the testing process please let me know.
-Thanks

NinjaTrader_Ray
06-01-2006, 11:51 AM
Thanks for the offer. Should be fairly straightforward to resolve. Likely have another update within a week.

Ray

NinjaTrader_Ray
06-03-2006, 12:55 AM
Widgetman,

The problems I experienced were due to changes I personally made to the NTMarketPosition() function some time ago for testing purposes. The function works as expected.

Please reimport and override all NT functions. Import the ELD from C:\Program Files\NinjaTrader 5\bin\AutoTrade\NINJATRADER.ELD.

This will ensure that you have the correct functions. Then try the NT sample script again.

Ray

Widgetman
06-03-2006, 04:23 AM
Hi Ray,
I downloaded the latest beta version off of your site last Thursday and re-installed it. I also have imported the latest ELD that was installed after running the beta. It is dated 12/21/2005. Is the the correct file I need to test ?

Widgetman
06-03-2006, 04:48 AM
Hi Ray,
I also wanted to ask if there was a way to get a print statement in the easy language interface to show what the NTMarketPosition() value currently was so I could trace through the sequence, and see if I can actually see the value change from 0. Please let me know when you get a chance.
-Thanks

NinjaTrader_Ray
06-03-2006, 07:58 AM
Sure, just add Print(NTMarketPosition("")); at thetop of the NTSample script.

Widgetman
06-03-2006, 09:29 AM
Hi,
What is the date on the ELD file you have working ? I would like to make sure I am using the same one.
-Thanks

NinjaTrader_Ray
06-04-2006, 12:03 PM
March 25th, 2006

Widgetman
06-04-2006, 11:53 PM
Hi Ray,

Can you tell me where I can get a copy of the newer version of the ELD. I just installed the beta version once again, and the ELD file in the bin folder/autotrade is dated 12/21/2005. Maybe you can post a link here to DL it. Thanks for all the help.

Widgetman
06-05-2006, 12:41 AM
Hi Ray,

I went to the trouble of uninstalling the beta version and then installed the regular version. It seems the ELD in your regular install is dated march 25, 2006. The beta version installs the ELD dated Dec 21, 2005. I am guessing that your beta also would like to install the latest version. I will copy over the old ELD file and try my test again. Hopefully I can get it to work.

-Thanks

Widgetman
06-05-2006, 02:35 AM
Hi Ray,

I was able to get the sample script working as you indicated it would. I did however find a few quirks with it that I think need to be addressed. I listed them below and tried to explain in detail excatly what I found. Overall I think you have a good product with a lot of potential for Tradestation users. I personally am working with Multicharts which runs tradestation scripts 100%.


1 I noticed on several occasions that with fast moving indicies I would see a second or third order sneak in under the sample script example before the first order got filled. This is due to the fact that until the order fills the NTMarketPosition status is still a 0. maybe it would be possible to somehow indicate a order was sent and being processed ?

2 I tried to send the orders listed below seperate. The first was a limit buy and the second is a stop. I found that this caused several stop orders and limit orders to be sent until one of then filled. Again I suspect this is due to NTMarketPosition flag not being set until a order fills.

Suggestions:

Modify the NTmarketPosition to accomodate for the order pending status. Don't send any other orders unless the first order fills or is cancelled. Also somehow handle a stop order sent if the two orders are not sent in the same command.

NinjaTrader_Ray
06-05-2006, 02:57 AM
Hi Widgetman,

So that you are not offended, I want to let you know thatI did edit your last post and remove the link you provided to our competitor. I am sure you can understand that.

Your observations are correct. We do provide methods for identifying orders and checking the status of orders. Of course, this would need to be incorporated into your scripts. This then would provide you the level of tolerance you may be looking for. I am working with another TS user who is coding some wrapper functions that would simulate how the TS Trade Manager works.

Ray

Widgetman
06-05-2006, 04:02 AM
Hi Ray,

I am not offended that you removed part of my post. I assue you though they are no competition to you right now. I would however like to see a example of how you would actually use the NTOrderStatus to prevent other orders from firing. Is it possible to do something like

If NTOrderStatus = "Filled" then

begin

Proceed with routines here

end

The reason I ask is I am not sure easy language processes commands based on strings very well. Any example script would be appreciated. I also was gonna try to figure out how to send a NTCommand over to set the stops, strategy, and limits all in one order. Maybe that will work better.

NinjaTrader_Ray
06-05-2006, 05:25 AM
You are on the right path. You would need to pass in a unique order id, then check NTOrderStatus(orderId) = Filled

Widgetman
06-05-2006, 10:15 AM
Hi Ray,

Thanks for the help. I tried the NTCommand function and was able to get a better resolution that I was looking for by also using the NTFilled function. I did notice however that the stop I set in my order entry does not stay active in the order when it gets filled. Listed below is my command I sent. Why would a stop show up under the order tab, but not br set in the actual IB order entry ?





if LastBarOnChart and NTConnected(1) then

begin

FilledStatus = NTFilled("MyOrderId");

if (NTMarketPosition("MyAcctId") = 0) and (FilledStatus = 0)then

begin

NTCommand("Place", "MyAcctId", "Sell", 1, "StopLimit", (High - .0001), (High+.0010), "", "", "MyOrderId", "", "");

FilledStatus = -1;

end;

end;