regards to everyone,
i think this kind of indicators i'm trying to create should be quite interesting for the expert programmers with nt support.
i have been using an inferior and failed platform (ts) for several years, it does a decent job creating visually passable charts but their backtesting, optimization and automated trading engines are all colossal failures. non minute charts (range, momentum, kase and others) will draw one way when they have been created from real time data but then if one copies or closes and reopens these kind of charts the bars will be drawn quite differently from historical data (erroneously), and this will cause all indicators and strategies in that chart to redraw and recalculate erroneously as well. this makes backtesting or optimizing on ts a complete waste of time as these processes all run on historical data. in fact, to be able to determine if any particular strategy would really be competitive - profitable in the real world i realized that i would have to create indicators that would be exact equivalents to my strategies but instead of sending orders to market would generate either email alerts or text files using streamwriter. as both the email messages and the text files exist outside of ts and it is impossible to modify them once they have been created i can use the information in these logs to determine with certainty the profits or losses that these trades would have generated trading in real time in the real world.
i have been evaluating nt for a couple of weeks and i would like to create indicators that did the very same thing in this platform. that is, replicate my strategies to perfection but instead of sending orders to the market send email alerts or create text files using streamwriter. it is important for me to be able to generate these external logs so that i can have determine how good nt is at executing automated strategies in real time and how profitable my strategies would be if i used nt to trade them automated.
i have never used email alerts with nt but i think i should be able to figure out by myself how to send email messages every time an uptrend or downtrend begins and ends. i think i will start by using the strategy builder to see how the code to send emails looks like and go from there.
email messages are adequate for this objective, but one has to open several messages and go through their contents to be able to know how a group of trades would have performed in the real world. however, streamwriter can create much more useful and practical text files as one can evaluate the profitability of an strategy just by taking a glance at these logs.
this below is an example of the code i'm using in ts. this script generates one individual file for every event (start or end of a downtrend or uptrend, which a strategy would have processed as entry or exit orders). streamwriter creates the names for the files dynamically and they include the symbol ticker one is monitoring, the kind of event (casnum), date and time information and the price for the instrument at the time of the event. i have tried to convert this script to ninjascript - c# but this is as far as i was able to get and the samples that i have found to use streamwriter with nt all create one single file and then append it endlessly, which is not useful for me. i will insert some comments throughout this piece of code using * *. it is quite important for me to be able to generate these logs using nt, so i will be grateful if the people with nt support can assist me in fully converting this indicator to ninjascript.
using elsystem; using elsystem.collections; using elsystem.io; using tsdata.common; using tsdata.marketdata; using tsdata.trading; inputs: price(close), smap01(20), nc(white), uc(darkblue), dc(darkred), rounum(5), poioff(10), string iprimarydirectory("c:\ntlogs"), string symtic("aapl"), string filnamplusymtic("logs_aapl"), string gronam("aaplg01"); * the indicator draws a moving average that changes color from neutral to uptrend or downtrend color if the appropriate conditions are present, it also generates a text file to log all the requested information. * variables: smav01(0), utc(false), dtc(false), cc(white), casnum(0), tarpriu(0), tarprid(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}_{4}_{5}.txt", iprimarydirectory, filnamplusymtic, //orderticket.gettradingsymbolfor(symbol, category), gronam, datetime.now, casnum, numtostr(price,2)); print(filepath); sw = streamwriter.create(filepath); sw.autoflush = true; sw.writeline(msg); sw.close(); end; * this fragment above generates file names dynamically, one per event. having all the relevant information in the file name itself is immensely convenient. * smav01 = sma( price, smap01 ) ; plot1 ( smav01, "sm crossover colors tf" ); tarpriu = ( ( rounum * ( Math.Floor ( price / rounum ) ) ) - poioff ) ; tarprid = ( ( rounum * ( Math.Ceiling ( price / rounum ) ) ) + poioff ) ; * these are some target prices i calculate based on the price of the instrument at the time of the event. * if smav01[0] > close[0] then begin utc = true; casnum = 1; cc = uc; end else if smav01[0] < close[0] then begin utc = false; casnum = 2; if cc = uc then cc = nc; end; if smav01[0] < close[0] then begin dtc = true; casnum = 3; cc = dc; end else if smav01[0] > close[0] then begin dtc = false; casnum = 4; if cc = dc then cc = nc; end; * i use boolean variables to determine if a downtrend or uptrend is currently active. the four different types are indeed necessary if i want to use all the components in my strategies. * setplotcolor(1, cc); if utc=true and utc[1]=false and lastbaronchart and barstatus( 1 ) = 2 then begin recordevent( "group "+ gronam + newline + "symbol:" + spaces(1) + symtic + spaces(1) + “started uptrend” + spaces(1) + “case 1” + spaces(1) + numtostr(price,2)" + newline ); end; * i only want real time events to be recorded, if i don't use the last bar on chart and bar status completed commands then the indicator would create alerts or files for every event in the historical data in a chart which would be useless. i don't know if the streamwriter syntax for the information to be written inside each file would be different in the case of ninjascript - c#, i would think it must be the same or pretty similar. * if utc=false and utc[1]=true and lastbaronchart and barstatus( 1 ) = 2 then begin recordevent( "group "+ gronam + newline + "symbol:" + spaces(1) + symtic + spaces(1) + “ended uptrend” + spaces(1) + “case 2” + spaces(1) + numtostr(price,2)" + newline ); end; if dtc=true and dtc[1]=false and lastbaronchart and barstatus( 1 ) = 2 then begin recordevent( "group "+ gronam + newline + "symbol:" + spaces(1) + symtic + spaces(1) + “started downtrend” + spaces(1) + “case 3” + spaces(1) + numtostr(price,2)" + newline ); end; if dtc=false and dtc[1]=true and lastbaronchart and barstatus( 1 ) = 2 then begin recordevent( "group "+ gronam + newline + "symbol:" + spaces(1) + symtic + spaces(1) + “ended downtrend” + spaces(1) + “case 4” + spaces(1) + numtostr(price,2)" + newline ); end;
very well, this is the situation. it took me and the ineffective people with ts support more than two weeks to create this code and get it to work to perfection to accomplish my objectives (nothing like this had ever been done in ts). however, i have no doubts that it won't be a challenge to create an equivalent indicator for nt. excellent, thanks, regards.
Comment