Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
i have a number of questions regarding the print to file and append file commands in ts. ts support is one of the worst things ever, their "support" personnel just ignore most of the posts in the ts fora which just go unanswered and will be buried by other inquiries that will also be left unanswered. actually, the ts fora might be the worst place of all to get advice or guidance, i have received far better suggestions and corrections in every other forum i have posted to.
anyway, i will post the last two questions i made on the ts fora here. i would really appreciate if other members who are more knowledgeable than i am about programming and data management could help me with this matter. i have been using ts's email alerts for a number of weeks, and i would like to know if there are any other alternatives available to get ts to compile in real time all the alerts and orders my numerous charts generate as text or data instead of sending them to market or as email messages.
i have just learned about the ts print to file command. this is very much in line with what i have in mind. ¿does anyone know if ts can also interact with other software like open source database programs and other tools like ftp clients and servers, and in this case what are the best practices to use these kinds of software?
initially, the only possibility that i thought existed to create a compilation of my ts alerts and orders in real time as they were being triggered was to keep the email alerts as they i had them, continue to send them to myself, and then use an smtp reader to compile everything as text. however, i have received several recommendations to get rid of redundant processes, and if possible, keep all processes local in my own computer in order to avoid the possibility of email malfunctions. i have also received recommendations to use database software, if possible, as this is a far superior alternative to simple text files.
so, if anyone has managed to save their ts alerts and orders to their local disks as string - text and can share their experience and recommendations i will be most grateful.
and this is my second inquiry about the print to file and append file commands. i want to create a compilation of all the alerts my charts generate, each one to a separate text file in one same folder. ¿how can i do so that ts would print to a different file each time? the most useful format for me would be c:\symbol ticker + space + date in yyyymmdd format + space + time in hhmm format.txt . ¿is ts capable of something like this? i have taken a look at the easylanguage essentials pdfs but interesting cases like this one are not covered at all.
i would also want to include some information in the text that would be written to these files. ¿how can i round the last price for the symbol in my chart to integers? ¿is it possible to round to other intervals like .5, 2.5, 5 or 10? ¿how does the round function work? i imagine that it rounds up above .5 and down below this value.
i also want to include the date for the next wednesday in yymmdd format. in all cases my variable should use the date for next wednesday, if today is a wednesday, use the date for the next wednesday. ¿is this even possible in ts?
very well, thanks to all, regards.
Can you help answer these questions from other members on NexusFi?
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,049 since Dec 2013
Thanks Given: 4,386
Thanks Received: 10,206
Can you print to a database? Sorry don't know. I know you can load information from other sources though.
Can you print alerts. Sorry don't know.
@ABCTG and @kevinkdog are more proficient at easylanguage than me and are both also very helpful, so they may be able to help.
This should work
filename = GetSymbolName + " " + NumToStr(Date + 19000000, 0) + " " + NumToStr(Time, 0) + ".txt"
fileappend(filename, .....)
incredibly i have received a minimally useful reply from ts. i post it here in case it is useful for anyone, particularly people who are performing internet searches for easylanguage resources:
- ts support -
"
You should consider using a StreamWriter, as it is much more flexible and allows you to dynamically build the file name.
Sample StreamWriter
If you simply want the integer portion of a number, you can use the reserved word IntPortion. IntPortion(2.82) returns a value of 2.
The reserved word Round takes two parameters, the number to round and the number of decimals. Round(142.82, 0) returns a value of 143.
To round a number to the lowest integer greater than the specified number, use the reserved word Ceiling. Ceiling(4.5) returns a value of 5.
To round a number to the highest integer less than a specified number, use the reserved word Floor. Floor(4.5) returns a value of 4.
Note when writing a number to a file you will need to convert it to a string. This can be done using the reserved word NumToStr. This reserved word is similar to Round in that it takes two parameters, the number to convert to a string and the number of decimals to retain in the string expression. NumToStr(1170.5, 2) returns the string expression "1170.50". NumToStr(1170.5, 0) returns the string expression "1171".
The below method demonstrates how to calculate next Wednesday given a DateTime object, such as BarDateTime or elsytem.DateTime.Now. The method returns next Wednesday's date as a string in the format "yymmdd".
"
--
i still have two issues that i could use a lot of help with, first of all, the script for the date of the next wednesday does verify ok and it seems like it should work but i don't know how to get ts to print that information anywhere. i created an indicator with this code and inserted it to a chart and nothing, i looked in the data window and nothing. ¿how could i print this date to an alert and how could i use this information as a string to be written to a text file?
and the second thing is that the streamwriter sample that the mfs at ts provided does not create text files with variable names, which is what i have been trying to create all along. ¿does anyone know what changes should be made to the code so that the file names were created dynamically?
i also tried the suggestion that SMCJB kindly offered and nothing.
if i try to verify this script, ts says that a file name is expected instead of filnam in print(file(filnam). i did ask for assistance with creating dynamic file names in the ts fora again but ts support don't give a heck.
this has taken a very long time but i have managed to make some progress in having ts write information to text files instead of sending email alerts.
this indicator will print to a text file instead of generating the typical ts alerts. i share it in case anyone on the internet performs a search for easylanguage print to file or append file resources:
using elsystem;
using elsystem.collections;
using elsystem.io;
inputs:
price(close),
length(9),
string iprimarydirectory("c:\tslogs\"),
string symtic("clm19"),
string indnam("sma crossovers");
variables:
sma(0),
streamwriter sw(null);
sma = average (price, length);
plot1 ( sma, "sma alert logs" );
if price[0] > sma[0] and price[1] < sma[1] and lastbaronchart and barstatus( 1 ) = 2 then begin
print(file("c:\tslogs\test002.txt"), symbol + spaces(2) + symtic + spaces(2) + indnam + " started uptrend " + numtostr(date,0) + spaces(2) + numtostr(close,2) + newline);
end;
if price[0] < sma[0] and price[1] > sma[1] and lastbaronchart and barstatus( 1 ) = 2 then begin
print(file("c:\tslogs\test002.txt"), symbol + spaces(2) + symtic + spaces(2) + indnam + " started downtrend " + numtostr(date,0) + spaces(2) + numtostr(close,2) + newline);
end;
for the append file command, just use this structure instead of print to file:
if price[0] < sma[0] and price[1] > sma[1] and lastbaronchart and barstatus( 1 ) = 2 then begin
fileappend("c:\tslogs\test001.txt", symbol + spaces(2) + symtic + spaces(2) + indnam + " started downtrend " + numtostr(date,0) + spaces(2) + numtostr(close,2) + newline);
end;
i have been working on a version of this indicator that would use streamwriter. i share it as well:
using elsystem;
using elsystem.collections;
using elsystem.io;
using tsdata.common;
using tsdata.marketdata;
using tsdata.trading;
inputs:
price(close),
length(9),
string iprimarydirectory("c:\tslogs\"),
string symtic("clm19"),
string indnam("sma crossovers");
variables:
sma(0),
streamwriter sw(null);
// pass in a string containing line to be written to the file
method void recordevent(string msg)
variables:
string filepath;
begin
// create file name, including a directory based upon the symbol
//
// note: symbol should not contain characters that are not valid in file names
// indicator name should not contain invalid characters for a file name
// add whatever other parameters desired
filepath = string.format("{0}{1}\{2}_{3:yyyymmddhhmmss}.Log",
iprimarydirectory,
OrderTicket.GetTradingSymbolFor(Symbol, Category),
indnam,
datetime.now);
Print(FilePath);
sw = streamwriter.create(filepath);
sw.AutoFlush = true;
sw.writeline(msg);
sw.close();
end;
sma = average (price, length);
plot1 ( sma, "sma alert logs" );
if price[0] > sma[0] and price[1] < sma[1] and lastbaronchart and barstatus( 1 ) = 2 then begin
recordevent(" uptrend has started ");
end;
if price[0] < sma[0] and price[1] > sma[1] and lastbaronchart and barstatus( 1 ) = 2 then begin
recordevent(" downtrend has started ");
end;
this study verifies without issues but it crashes as soon as it has to write to a file:
i did some superficial research on the internet about the error messages and then tried to run ts as an administrator and the errors still happened. i also tried some modifications on the text that determines the directory where the files will be created but that was also irrelevant. this is strange because the two previous versions of this indicator i have created with print to file and file append commands still work without issues even when they all write to the same directory that the streamwriter version says it can't find.
if anyone has any idea how to get this to work i will be most grateful. thanks, regards.
I am posting my reply to you from the Tradestation forum here, as it might help other futures.io members, too.
With the information you provided it's hard to tell where the error is exactly coming from, but the "The specified path is invalid, [...]" error message would for example come up if the folder you are trying to write to does not exist on your hard drive. The code Chris posted in the Tradestation forum will (depending on your input value for iprimarydirectory) write to a sub folder within the iprimarydirectory folder. This sub folder is named using OrderTicket.GetTradingSymbolFor(Symbol, Category) as name:
If either one of these two folders does not exist already when the study tries to write to the folder the error message would come. If that is the problem on your end the solution would be to either manually create the folders or to change the code that sets the filepath.
The recordevent method prints the full filepath to the EasyLanguage Output, this can be helpful in checking if all required folders exist.
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,049 since Dec 2013
Thanks Given: 4,386
Thanks Received: 10,206
Windows 10? I've had a similar but different before. W10 stops you writing/saving to the root directory (anything in C: as opposed to Documents) unless you change the security options.
but nein. the streamwriter process should write to the same folder that the print to file and file append commands are writing to without problem. only the filename is variable.
this code does verify, it is a very simple indicator. if anyone has the chance to try it on their own devices we could determine whether the issue lies with the code or with my server.
SMCJB,
thanks. your comment makes a lot of sense. i did some tests by changing the tslogs folder to the documents folder in my server and it made no difference at all. the indicator crashed all the same as soon as it had to write to a file. that and the fact that the print to file and file append commands are able to write to c:\tslogs without problem leads me to think that it is not a matter of permissions with the os.
---
these malfunctions are really, really strange. ts support has taken more than a week to help me with this command. and there are no official ts resources to learn how to use processes like streamwriter, vectors and ooel even when these are complicated and demanding processes that the regular ts user could never be expected to figure out on their own. there are no official resources anywhere (not even in the ts fora themselves) for anything that was added to ts after their easylanguage pdfs from almost 15 years ago were created. and ts support won't solve most requests in the ts fora or will take forever to be of any assistance. i have been working for weeks to get ts to create a new text file with a variable name to my local disk instead of generating the ts ordinary alerts because this will allow me to use other resources to create an automated option trading system. i have achieved some progress and will make sure i get this done but everything related to ts is always really frustrating.
the Streamwriter code you posted works fine on my end if all folders exist already. If any of the folders does not exist when the code tries to write to it, the study raises a similar error message to the one you posted.
I am not sure what you mean with "the streamwriter process should write to the same folder that the print to file and file append commands are writing to without problem. only the filename is variable.", because this is not what the code you posted does. You would have to change the code to achieve that as it currently uses the file name as a folder, too as the code snippet from my previous post shows.
Regards,
ABCTG
maggtrading
herr ABCTG, danke, danke.
but nein. the streamwriter process should write to the same folder that the print to file and file append commands are writing to without problem. only the filename is variable.
this code does verify, it is a very simple indicator. if anyone has the chance to try it on their own devices we could determine whether the issue lies with the code or with my server.