Learn to program with me...

Discussion in 'Automated Trading' started by C99, Mar 23, 2007.

  1. you doing very good here, c99
     
    #21     Mar 23, 2007
  2. I meant pages with more VBA trading related examples
     
    #22     Mar 24, 2007
  3. That's a great link,thanks.I bought 'Building Automated Trading Systems' on the title really!It gives a basic introduction to C++.net but is usefull for the architecture of trading systems in their entirety IMO.I'm a beginner (more than you are C99) and will enjoy playing around with excel and vba.I can't see why you couldn't trade with it in longer timeframes,particularly.I'll enjoy this thread very much,thanks.
     
    #23     Mar 24, 2007
  4. bidask

    bidask

    hey guys what other types of articles do you want to see? it's kind of hard to move on to other stuff unless you understand what's going on in that article first.
     
    #24     Mar 24, 2007
  5. http://www.elitetrader.com/vb/showt...ge=6&highlight=excel for trading&pagenumber=1

    Thread entitled 'excel 2007'
    Mentions the new 'unlimited' worksheet size PLUS using an 'array' to do the calculations and then moving the data back to the sheet (rather than recalculating after every cell change).Perhaps you could create your own thread,Bidask?Learn excel/vba trading programming with me?Sort of a sister thread?
     
    #25     Mar 24, 2007
  6. bidask

    bidask

    they're talking about some general row capacity and data processing issues. that's not something a beginner needs to deal with. it's best if you guys tell me something specific that you want to do and i'll start from the beginning and deal with issues as we go along.
     
    #26     Mar 24, 2007
  7. C99

    C99

    OK, sorry I got sidetracked for a few days there but back on task now. Here is the code with comments for my complleted IB form to connect and get data for one symbol. This is from the form1.cs tab in my VS2005. None of the code in any other files (or tabs) was altered by me. If anyone tries to copy and past this into their Visual Studio, just mind the label and button names. Some I gave descriptive names to, but some I just left with the auto generated names. So the bulk of this could be copied over, but make sure to change button and label references to the names of your buttons and labels. Anything afte the double backslashes are comments and ignored by the program.


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;

    namespace IBTest
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }
    //Next line created automatically by clicking on the menu item in form designer.
    private void connectIBToolStripMenuItem_Click(object sender, EventArgs e)
    //This line needs to be typed out.
    {
    axTws1.connect("localhost", 7496, 0);

    }
    //Button1 is the request mkt data button. I was lazy and didn't give my buttons or labels descriptive names.
    //Clicking on the button creates this line of code.
    private void button1_Click(object sender, EventArgs e)
    //These next two lines had to be typed out.
    {
    double strike = new double();
    axTws1.reqMktData(Convert.ToInt16(tbxSymID.Text),tbxSymbol.Text, tbxType.Text, tbxExpiration.Text, strike, "", "",tbxExchange.Text, "", tbxCurrency.Text, "");
    }
    //This line is created by clicking on the TWS control on the form, finding the events
    //and clicking on the tickPrice event.
    private void axTws1_tickPrice(object sender, AxTWSLib._DTwsEvents_tickPriceEvent e)
    //These next few lines had to be typed. First, I create the variables to hold the price info.
    //Then we check that the symbol ID on the tickPrice event matches the Symbol ID of the symbol.
    //With only one symbol that we have requested data for, of course it will match,
    //but I guess this will be more important once I add more symbols.
    //Then we check the tickType. The IB API docs give the # that will be returned
    //if the tick is a bid, ask, last, etc. So basically we ceck that it matches the symbol
    //, check what type of tick it is, then assign it to the proper variable and label.
    //the ("0.00") is just to format the return value with two decimal places. I think out of everything here
    //that took me the longest to figure out.

    {
    double last = new double();
    double bid = new double();
    double ask = new double();
    if ((e.id == Convert.ToInt16(tbxSymID.Text)) && (e.tickType == 4))
    {
    last = e.price;
    lblLast.Text = last.ToString("0.00");
    }
    if ((e.id == Convert.ToInt16(tbxSymID.Text)) && (e.tickType == 1))
    {
    bid = e.price;
    lblBid.Text = bid.ToString("0.00");
    }
    if ((e.id == Convert.ToInt16(tbxSymID.Text)) && (e.tickType == 2))
    {
    ask = e.price;
    lblAsk.Text = ask.ToString("0.00");
    }
    }
    //This line was auto generated by clicking on the tickSize event.
    private void axTws1_tickSize(object sender, AxTWSLib._DTwsEvents_tickSizeEvent e)

    //And these lines do the same as the the code above except that
    //here it is for the bid and ask size instead of prices.

    {
    double BidSize = new double();
    double AskSize = new double();

    if ((e.id == Convert.ToInt16(tbxSymID.Text)) && (e.tickType == 0))
    {
    BidSize = e.size;
    lblBsize.Text = BidSize.ToString();

    }
    if ((e.id == Convert.ToInt16(tbxSymID.Text)) && (e.tickType == 3))
    {
    AskSize = e.size;
    lblAsize.Text = AskSize.ToString();
    }
    }
    //This line auto added by clicking the stop mkt data button.
    private void button2_Click(object sender, EventArgs e)

    //These lines were typed. We first cancel the mkt data request and then set the labels
    //all to blank.
    {
    axTws1.cancelMktData(Convert.ToInt16(tbxSymID.Text));
    lblBid.Text = "";
    lblBsize.Text = "";
    lblLast.Text = "";
    lblAsk.Text = "";
    lblAsize.Text = "";


    }
    }
    }

    <img src="http://elitetrader.com/vb/attachment.php?s=&postid=1421842">
     
    #27     Apr 2, 2007
  8. C99

    C99

    That really wasn't that hard to get working. I had initially started my experimenting with the REDi API and I must say that from my limited experience here the IB API is ten times easier to work with. It has one control you drop on the form. Then when you click on the control it shows all the methods and events, VS intellisense kicks in and give you some guidance, and the API documentation actually makes sense to a novice on how to get them working. Two thumbs up for the IB API so far.

    Redi API is a whole different beast. I honestly am not sure where to start. If anyone has any experience with it, I am publicly begging for some assistance. I don't think I am supposed to take the same route as IB and add a control to the toolbox. If you follow those same steps, there are a few redi controls that show up, but there is no documentation for any of them. I think you go the route of adding a reference to the Redi Library. Then from the Object browser in VS you can see the dirrerent classes, etc. I added the etc. there because I'm not really sure what I'm looking at in the object browser. There seems to be multiple redundant entries with the same or very similiar choices showing up in multiple places. So which is the right one to use? Then I'm confused by the lack of events. I can only find a few and they are not descriptive. And then on top of all that, even if I use what I believe to be proper syntax, intellsense doesn't help out at all. I have some excel examples, a C++ example, and a VB example. If anyone thinks they can provide some insight I will gladly post those example apps. Just say the word. For now I am going to post just this one word doc. I think to an experienced programmer it has the info needed to connect. I can't make heads or tails of it. So if there is anyone out there that can interpret this, I would greatly appreciate any insight. Even if you don't use or have access to REDI, I can experiment with any suggestions on my end. My first goal is to creat the same form I did for IB- nothing complicated. Get connected and get quotes for one symbol.
     
    #28     Apr 2, 2007
  9. C99

    C99

    The above post gave everything needed to recreate my IB test app. I didn't post the VS files or the compiled app because I'm not sure if they are file types that can be attached to posts here. If anyone wants the actual files, just ask and I'll try to figure out how to do it. Maybe zipping them up will make it work?

    I'll also post some of my *not working* redi code soon to see if anyone might be able to see where I'm going wrong. I've actually recieved a few PM's re: redi since starting this thread from people in the same boat- wanting to work with the redi api but no idea where to start. So I'd really like to figure this out and get some more entry level info about the redi API out there bec. I think it really is a confusing API for those without a lot of programming experience.
     
    #29     Apr 2, 2007
  10. raf_oh

    raf_oh

    Just ran across this thread - I am about to begin a 13 week intensive C# class after trading for 5 years. Hopefully, I'll be able to contribute constructively soon :) .

    Meanwhile, I came across this also, "Creating a Mechanical Trading System" parts 1 and 2.

    Chris Donnan is blogging with relevant content.

    I'll post anything else that seems useful.
     
    #30     Apr 3, 2007