Tutorial 206 | Using the OpenFileDialog class to access a text file for use with the optimization class

  • 2 months ago
Based on Tutorial 100 (see https://markplex.com/free-tutorials/tutorial-100-building-app-optimizer-api/) and Quicktip 37 (see https://markplex.com/free-tutorials/tradestation-easylanguage-quicktips/quick-tip-37-use-streamreader-to-import-a-symbol-list-into-the-optimizer/
Tutorial 100 demonstrated a simple optimization using the optimizer class. Quicktip 37 took the tutorial 100 program, which had a list of symbols to be used in the optimization 'hard coded' into the program, and instead made it so that the user to store the list of symbols into a txt file and for the program to import.

Tutorial 206 extends this further by taking the Quicktip 37 program and allowing the user to search for a file on their hard drive. The file is selected and the symbol data is imported.
#EasyLanguage #tradestation #markplex
Transcript
00:00Hello and welcome to Tutorial 206.
00:03And in this tutorial, we're going to be looking at the Optimizer app again.
00:08In fact, this tutorial follows on from Tutorial 100 and Quick Tip 37.
00:15And what I suggest, if you're not super familiar with the Optimizer API,
00:19then it would be a really good idea to go back to Tutorial 100 and watch the videos there.
00:24Then look at Quick Tip 37 before going through Tutorial 206, which covers a lot of the same
00:32ground. In fact, it's built on essentially the same program. So just to remind you what these
00:36did, Tutorial 100 demonstrates a very simple program where you can use the Optimizer API.
00:44The symbols can either be hard-coded into the program, or you can actually
00:48import the symbol in a form. Now, Quick Tip 37 went a little bit further and allowed you to
00:55import a document containing a list of symbols. Bear in mind that the Optimizer API can be used
01:02to optimize over a number of symbols, a number of strategies, etc. So a very flexible tool.
01:09So Quick Tip 37 added the ability to import a file. And what I've done in this new program
01:15is rather than importing a file, when we click the Start Optimization, you have the option to
01:22actually find a file on the hard disk containing a list of symbols. The program will then upload
01:29that into the program, put those symbols into a token list, and then use that token list in the
01:36Optimizer API and do a optimization using the symbols. So let me just demonstrate it to you,
01:41then I'll just go through some of the things that I've changed from Quick Tip 37 to this new
01:47tutorial, Tutorial 206, which I will make available, by the way, to GoldPass members, or if you want to
01:54transcribe the code, you're very welcome, or there will be a download available for a modest fee.
02:00So let's start the optimization. When we do that, we see the hard drive, and this is going to my
02:07Markplex work folder. It's going to zoom to the bottom, and what I've done is created a file
02:13containing a number of symbols. I'll show you that in a moment, but what I'm going to do for now,
02:17for now, is just open that. And what happens is the symbols are all uploaded by the program,
02:23stored in a token list, and then that also begins the processing of the Optimizer API.
02:31And the best profit so far is displayed here, along with a representation using this progress
02:37bar. Also, you can see that down here in the print area. So I'll just let that go on,
02:43might speed it up for a few seconds, just so you can see that come to an end. Well,
02:47it looks like we're getting there already. Okay, so there, it's telling us a net profit of 98,357.
02:55Now, let me just show you the file. So it is simply an ordinary text file that you could
03:01create in Notebook, for example, and we just have a list of random symbols included in that. It
03:08could be any length, it doesn't matter. So that is the text file. The way that we're doing, the
03:12way this program works, and this is the real purpose of this tutorial, is to show you, introduce,
03:19if you're not familiar with it, a feature, which I think is quite useful, and that is using the
03:26Open File Dialog. Now, this is the way that we get the dialog coming up in the program. So it's not
03:33super well documented in TradeStation, but you can maybe use this, or there are also some on
03:40the forum that you could use as a model for using it in your work. So to set up this Open
03:47File Dialog, what I've done is use this syntax here, New Open File Dialog, and then there are
03:54various options that you get with that. So probably the best thing to do is if you go to the dictionary,
04:01which I'll just try and demonstrate, and type in Open File Dialog, you'll see various options there
04:10of syntax that you can utilize, such as Creo, such as MultiSelect, and so on. Now, you're not
04:20seeing some others that I'm using here. So one of the things that you can do is go to a Microsoft
04:26site, because this functionality, or this class, is based on a Microsoft. It's essentially the
04:34same thing with maybe not all of the methods and properties available. But you can look at
04:43that site, and so you can see other syntax and other examples of the use, which is what I did.
04:49But what we're using is we're saying we're not allowing MultiSelect. We're setting the initial
04:55directory, and we're using a filter. So when I go back and restart the program, you'll notice
05:01that there are only text files. Well, we're seeing directories, but we're only seeing text files.
05:05There are JPEG files. There are other files in that folder, but we're not seeing them because
05:09we've restricted the filter just to text files. And then we've got, there's a couple of events
05:17that can occur with this class, and one of them is called File OK. And we're going to be using
05:23this to know when the user, in other words, me in this case, clicks on a file. So when that happens,
05:32then we can go to the next stage of the program. So the first part of the program is when we click
05:38the button on the form, just to go back to that form, when we click the button Start Optimization,
05:46that is where we start this Open File dialog. And then in the Open File dialog, when we click the
05:54button on the file we want, then we go to File OK, which is here. And that is where we set up
06:04the stream reader in order to access the contents of the text file, which is what we do here,
06:12which is actually very similar to what we did in QuickTip 37, when we already knew where the file
06:19was, where the location of the file was hard-coded. But we just needed to add a little bit extra here
06:25so that we could do it by selecting a file. So what that does is, again, just like in QuickTip 37,
06:33which, as I mentioned, is worth looking at, we take the contents, put it in a stream reader,
06:38and then we take those values and put them into a token list. And then we call the job,
06:46or we start the job, define the job, as you can see here, which then calls some other. So we have
06:51Define Job. And you can see that we add the symbols by going through the token list and
06:57using this syntax here, opsymbol.addsymbol, and then the counter number so that we're getting
07:02those all set up in the job for the optimization. So what I would suggest is to experiment with
07:10this. You could maybe go through this program, type it in anew, or you could go back to Tutorial
07:16100 or QuickTip 37 and use code from there. I'm just going to run through this slowly so you can
07:22see what's going on. But the key to this new functionality over and above QuickTip 37 is
07:30the use of the Open File Dialog. And what I'll do, I'll put in a link under this video on the
07:39website showing you where you can access the Microsoft site where you can find potentially,
07:47not definitely, but potentially information that you could use.
07:52And what I've done is anything that was created using the toolbox, I have now copied that into
08:01the program. As you can see, for example, the forms, which are a lot more, a lot easier to
08:07create using the toolbox, using the form creation tools, rather than putting all this information,
08:13typing all this information in. So I'm just going to copy that into the program.
08:21By hand, that can be done using the form tool. So I'm just going to show you one more time what
08:29the program looks like. We're going to, let's just clear the print logs, go back to the program,
08:34which is a trading app, and start optimization. Going to go back to that file that we used before
08:39and you can see the optimization taking place. Anyway, I hope, hopefully, that will be useful
08:46to you. Thank you very much.
09:16you
09:46you
10:16you
10:46you
11:16you
11:46you
12:16you
12:46you

Recommended