NexusFi: Find Your Edge


Home Menu

 





help with print to file commands.


Discussion in TradeStation

Updated
      Top Posters
    1. looks_one maggtrading with 5 posts (0 thanks)
    2. looks_two SMCJB with 3 posts (3 thanks)
    3. looks_3 ABCTG with 2 posts (2 thanks)
    4. looks_4 kevinkdog with 1 posts (1 thanks)
    1. trending_up 4,673 views
    2. thumb_up 6 thanks given
    3. group 3 followers
    1. forum 10 posts
    2. attach_file 1 attachments




 
Search this Thread

help with print to file commands.

  #1 (permalink)
maggtrading
quintana roo, méxico
 
Posts: 84 since Mar 2013
Thanks Given: 222
Thanks Received: 40

regards to everyone,



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.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
Futures True Range Report
The Elite Circle
Better Renko Gaps
The Elite Circle
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
38 thanks
NexusFi site changelog and issues/problem reporting
27 thanks
GFIs1 1 DAX trade per day journal
19 thanks
The Program
18 thanks
  #2 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT and Stellar
Broker: Advantage Futures
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,041 since Dec 2013
Thanks Given: 4,375
Thanks Received: 10,192

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.


maggtrading View Post
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.

This should work
filename = GetSymbolName + " " + NumToStr(Date + 19000000, 0) + " " + NumToStr(Time, 0) + ".txt"
fileappend(filename, .....)

Reply With Quote
Thanked by:
  #3 (permalink)
maggtrading
quintana roo, méxico
 
Posts: 84 since Mar 2013
Thanks Given: 222
Thanks Received: 40


regards to everyone,


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

 
Code
{  
This sample code demonstrates output the datetime and value of some function each time it changes.  
For demonstration purposes the Simple Moving Average is used as the function value to export.  
  
The CSV file can be imported into Excel.  
}  
using elsystem;  
using elsystem.io;  
using tsdata.common;  
using tsdata.marketdata;  
  
inputs:  
	string iCSVFilePath("C:\Temp\TestCSV.csv"),  
	double iMinimumChange(.01),  
	bool iOnlyAtBarClose(true);  
	  
variables:  
	StreamWriter SW(null),  
	TokenList TL(null),  
	bool OutputData(false),  
	double SMA(0),  
	double ExportedSMA(0);  
	  
once  
begin  
	SW = new StreamWriter(iCSVFilePath);  
	TL = new TokenList("");  
end;  
  
OutputData = false;  
  
if not iOnlyAtBarClose  
	or BarStatus(DataNum + 1) = 2 then OutputData = true;  
  
if Outputdata then  
begin  
	SMA = Average(Close, 9);  
	if AbsValue(SMA - ExportedSMA) >= iMinimumChange then  
	begin  
		TL.Clear();  
	  
		  
		if iOnlyAtBarClose or GetAppInfo(airealtimecalc) = 0 then  
			TL.Add(BarDateTime.Format("%m/%d/%Y %H:%M:%S"))  
		else	  
			TL.Add(DateTime.Now.Format("%m/%d/%Y %H:%M:%S"));  
		  
		TL.Add(Numtostr(SMA, 5));  
		Print(TL.Value);  
		SW.WriteLine(TL.Value);  
  
	end;  
end;


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".


 
Code
using elsystem; 
	 
// Returns a string in the format yymmdd from a DateTime object	 
method string GetNextWednesday(DateTime dT)  
variables: 
	int DoW, 
	DateTime NextWednesday; 
begin 
 
	NextWednesday = dT; 
	 
	DoW = DayOfWeek( NextWednesday.ELDate ); 
	 
	if DoW >= 3 then 
		NextWednesday.AddDays(7 - (DoW - 3)) 
	else  
		NextWednesday.AddDays(3 - DoW); 
		 
	return NextWednesday.Format( "%y%m%d" ); 
	 
end; 
 
Print( GetNextWednesday(BarDateTime) );
"
--


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.

 
Code

inputs:  
string indnam("indnamtest001");
	
	  
variables:  
string filnam("");  
	  

filnam = "c:\" + getsymbolname + " " + indnam + " " + numtostr(date + 19000000, 0) + " " + numtostr(time, 0) + ".txt";


print(file(filnam), "date ",date:7:0," last ",close);

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.



very well, thanks to all, regards.

Reply With Quote
  #4 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,647 since Jul 2012
Thanks Given: 1,890
Thanks Received: 7,338

That seems like more than a "minimally useful" to me...

Follow me on Twitter Reply With Quote
Thanked by:
  #5 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT and Stellar
Broker: Advantage Futures
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,041 since Dec 2013
Thanks Given: 4,375
Thanks Received: 10,192


SMCJB View Post
filename = GetSymbolName + " " + NumToStr(Date + 19000000, 0) + " " + NumToStr(Time, 0) + ".txt"
fileappend(filename, .....)


maggtrading View Post
i also tried the suggestion that SMCJB kindly offered and nothing.
 
Code
variables:  
string filnam("");  
	  
filnam = "c:\" + getsymbolname + " " + indnam + " " + numtostr(date + 19000000, 0) + " " + numtostr(time, 0) + ".txt";


print(file(filnam), "date ",date:7:0," last ",close);
if i try to verify this script, ts says that a file name is expected instead of filnam in print(file(filnam).

print - Prints to Screen.
fileappend - appends to a file!

Reply With Quote
Thanked by:
  #6 (permalink)
maggtrading
quintana roo, méxico
 
Posts: 84 since Mar 2013
Thanks Given: 222
Thanks Received: 40

regards to everyone,


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:


 
Code
 
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:


 
Code
  

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.

Reply With Quote
  #7 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623

rtwave,

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:
 
Code
	filepath = string.format("{0}{1}\{2}_{3:yyyymmddhhmmss}.Log",     
		iprimarydirectory,     
		OrderTicket.GetTradingSymbolFor(Symbol, Category),     
		indnam,     
		datetime.now);
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.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #8 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT and Stellar
Broker: Advantage Futures
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,041 since Dec 2013
Thanks Given: 4,375
Thanks Received: 10,192

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.

Reply With Quote
Thanked by:
  #9 (permalink)
maggtrading
quintana roo, méxico
 
Posts: 84 since Mar 2013
Thanks Given: 222
Thanks Received: 40

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.


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.


thanks to all.

Reply With Quote
  #10 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623


maggtrading,

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 View Post
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.


Follow me on Twitter Reply With Quote
Thanked by:




Last Updated on May 17, 2019


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts