PDA

View Full Version : Auto Trade with TradeStation


Zardoz
03-24-2005, 06:08 AM
Questions:

To the traders using TradeStation, are you using the "Signal" file to code your buy and sell orders?

I've just started this and the problem I'm having is that when I add the Strategy (which contains the Signal) to the chart, TS marks all the past buy/sell signals on the chart and of course each time issending a file with a OIF orderto Ninja.

I'm I just missingsome code to stop it from looking atpast signals?

Also on the Ninja website it states in "The Basics". "Once NinjaTrader has processed the Passthrough OIF, it will delete the file. You can use this event to determine when it is safe to send the next Passthrough OIF. Has anyone figured out how check for this event?


Any ideas would be much appreciated.
Any simple examples that someone might have wouldbe also good.

Thanks, Happy Easter

Zardoz

scjohn
03-27-2005, 07:00 AM
I do not use TS but your problems occur in all software.

For your problem of sending orders on historical data, you will need to add some code that tells you if you are, now running in real-time. In other words, you are finished with the historical data.

As to whether or not the OIF file has been deleted, hopefully there is FileExists() command in TS.

You may want to look atthe TS example on the main web site. http://www.ninjatrader.com/doc_automated_trading_tradestation.htm

aspTrader
03-27-2005, 02:35 PM
Regarding whether a bar is an historical bar or a realtime bar, use the TS boolean condition "LastBarOnChart" as in:

IF LastBarOnChart

THEN BEGIN

// some code statement

// OIF file output statement

END;



scjohn wrote:
As to whether or not the OIF file has been deleted, hopefully there is FileExists() command in TS.
The best statement to use for file manipulation procedures including FileExists() in TS can be found in the EL Collections DLL package provided by the user named "Bamboo". I would also look for Bamboo's code contribution in the thread called "FastFileAppend".

Zardoz
03-28-2005, 09:22 AM
Thanks a lot guys,

aspTrader

I had got a workaround but the "if lastBarOnChart" is better. My workaround was just to bring up NinjaTrader after I activated my Strategy and delete the file manually.

As for the "FileExist", I'm not sure. Bamboo seems to have a different TradeStation then myself, probably the new edition. His EL Collections isan ELD file. TS 2000i supports ELA and ELS files.There is no FileExists command with TradeStation 2000i

scjohn

The example on the main website is more confusing than anything, but then I'm just a rookie at this. He uses a lot of fileappend commands when I thought one had to create a new file for each command to be sent to Ninja. I don't think there was one file create or PrintFile command in the whole thing.

Anyway I got the basic Strategy working minus a few extras that I had to take out.

Thanks again for you help!!!

Zardoz

aspTrader
03-29-2005, 03:17 AM
Zardoz wrote: I had got a workaround but the "if lastBarOnChart" is better. My workaround was just to bring up NinjaTrader after I activated my Strategy and delete the file manually.

As for the "FileExist", I'm not sure. Bamboo seems to have a different TradeStation then myself, probably the new edition. His EL Collections isan ELD file. TS 2000i supports ELA and ELS files.There is no FileExists command with TradeStation 2000i
Hi,

The LastBarOnChart is the standard way in TS to only activate an order in realtime. If your NT strategy related code is in a TS indicator AND you have "Update Every Tick" turned on then you'll need to do something in addition to that.

Bamboo's code contributions run with the new Tradestation. I'm not sure of their status vis-a-vis TS 2000i.

Zardoz
03-29-2005, 05:48 AM
asp Trader, Hi

I do use update-every-tick and I am using a signal off a 52 tick bar chart. As far as I can tell this has not been a problem so far. Maybe because I don't get multiple signals within one bar.

The problem I'm having now it that every now and then I'm getting a "runtime Error" on my signal with the message "Error opening file". Iassume that is the order.txt filethat I'mcreating to send the command to Ninja. Was wondering if I'm getting this message because I'm trying to create the file the same time Ninja is polling for it?

Has anyone else had this problem?

This is frustrating.



Zardoz

Zardoz
03-31-2005, 03:11 AM
Vincent help me please.

This is crazy. I took out basically all my code and only left one file create statement and I'm still getting the error. Here is the code. Still getting "Error opening file"most of the time the singal is activated. Someone must have also had this problem?

Thought that maybe Ninja was trying to create a file in the same directory at the same time like the updateor position.txt file that Ninja creates. Or maybe the polling is the problem.


If KBLshortterm < OverSold
then TabLong = 1
else TabLong = 0;

If TabLong = 1 Then Begin

If Price > High of 1 bar ago and KBLMedterm > KBLMedterm of 1 bar ago
Then Begin

Print(File("c:\program files\ninjatrader 4\AT\order.txt"),"YM 06-05,,DAY,BUY,MKT,,,,,,,YM One,SIM-101,");

End;

End;

Merv
03-31-2005, 03:41 AM
Zardoz,

You seem to be printing to a file that does not allow access. In TS8, the syntax for writing a file is the command FileAppend

Here is a line in my TS strategy that writes my file to NT V3.027 to enter a strategy order on the ER.

FileAppend("C:\Program Files\NinjaTrader\Ninja V3.027 Cash\AT\order.txt",
"ER2,1,GTC,BUY,LMT,"+numtostr(Close,2)+",,,,,,FALSE,ER 2C 3.0T 4.0T,,");

The numtostr command inserts the closing price of the bar into the file prior to it being written.

Hope this helps.

Merv

NinjaTrader_Ray
03-31-2005, 03:54 AM
We do not have any TS Easy Language experience here and would not know what the issue is with your ability to write out files. Hopefully Merv's comments will be of value. Thanks for that Merv.

On another note, a tip for anyone accessing any NT AT update files. They should be copied to another folder then read. This can avoid any potential file locking issues.

Ray

Zardoz
03-31-2005, 04:02 AM
Thanks Merv,

I'm using TS 2000i. It states the FileAppend command is not to create a file as one has to do for NinjaTrader but to add info into a file that already exists. As Ninja deletes the file after it reads it I need to create a new file. The Print command does work sometimes, just not consistently. I will however give it a go and see what happens. I have nothing to lose at this point.

Thanks Again

Zardoz

Zardoz
04-14-2005, 02:31 PM
Solved my problem. thx