Automated Trading Course - Part 1: Programming

Discussion in 'Automated Trading' started by jcl, Sep 8, 2012.

  1. #11     Sep 9, 2012
  2. #12     Sep 9, 2012
  3. jcl

    jcl

    77% losers is in fact a good result - from all strategies or EA's I've seen on the net and in trading books, 99% are unprofitable. In the second part of the course we'll also learn how to find out if a strategy is profitable or not. This is non-trivial.

    -Back to work. Today we'll write our first script. You'll need to download Zorro now if you haven't done so already. After installation, start it and you'll see something like this:

    [​IMG]

    Click the [Script] scrollbox, go all the way down and select [New Script]. A text editor will now open. Type in the following:

    Code:
    function main()
    {
      var a,b,c;
    
      a = 1;
      b = 2;
      c = a + b;
      printf("Result = %.f",c);
    }
    Now, select [Save As] in the [File] menu of the text editor, and save it under a name like "myfirstscript.c" in the "Strategy" subfolder of your Zorro installation. When you now click Zorro's [Script] scrollbox again, the name "myfirstscript" should appear among the other scripts. Select it, press [Test] on Zorro's panel, and watch what happens in its message window.

    If you did anything right, you should now see a message like "Result = 3". Otherwise, please complain here.

    Now, edit the numbers in the a and b lines and replace them with

    a = 5;
    b = 12;


    Save the edited script (File / Save or [Ctrl-S]), then press [Test] again. Tell us if your result is different than 17.

    That was our first program. Starting to make sense of this, isn't it? It looks like c is the sum of a and b; try to type several values for a and b and you will convince yourself. Now let's take a look at the piece of script that transforms Zorro in a sort of simple calculator.

    function main()
    {
    ...
    }


    The script starts with a function named main - everything that happens in a program is inside the winged brackets { } of a function. But we'll come to functions tomorrow. Here we concentrate on variables, and the next lines should already be familiar from what I said above:

    var a,b,c;

    We can see that the 3 variables a, b, c are defined, just as described above. The following lines are commands:

    a = 5;
    b = 12;


    The variables here get a content; they are set to 5 and 12. Now the following line is the core of our script:

    c = a + b;

    This line of C code appears to be simple too; it makes c equal to the sum of a and b. It is a command to the computer to add the content of the variables a and b and store the result in the variable c. Commands are lines in the code that do something, usually with variables.

    The last line is also a command, used for displaying c in the message window:

    printf("Result = %.f",c);

    Let's make a small experiment. Find the line of code c = a + b; in the editor, and then replace the "+" by a "*", the 'times' character, so that the line now reads:

    c = a * b;

    Save the script, then press the [Test] button again. Does the result make sense?

    You have now mastered the basics of lite-C. Zorro has multiplied 5 by 12, displaying the correct result: 60. I know it's not yet a trade strategy what we're doing here, but we're going somewhere! So now we know how to add and multiply values; we can use "-" to subtract two numbers or "/" to divide them. We could replace the line that does the c = a * b; calculation with much more complex expressions...

    But we'll save that for the next lessons. Enough for today.

    Please let me know if something was unclear or hard to understand.
     
    #13     Sep 9, 2012
  4. +1
     
    #14     Sep 9, 2012
  5. Daring

    Daring

    #15     Sep 9, 2012
  6. By learning to read Dr. Seuss I learned nothing about trading or the markets, but if I didn't I wouldn't be able to read your useful post.

    You have to start somewhere, he is laying the foundation to learn how to begin to program.
     
    #16     Sep 9, 2012
  7. Eight

    Eight

    We're only as good as the lowest common denominator we associate with. I suggest using the ignore feature for negative posters. They all think they are helping probably but ignore is still a great option.
     
    #17     Sep 9, 2012
  8. Great service your doing here jcl!!
     
    #18     Sep 9, 2012
  9. ok great. I shld be encouraging u guys to go ahead and learn.

    The last thing u shld learn in an algo/automated trading is how to write codes yourself.

    It just goes to show the world the reason of 95%/5%, the way you prioritize things.
     
    #19     Sep 9, 2012
  10. Needless to say your post begs the answer to the question, "if" the problem is the way "we" prioritize things, than what is the proper priority order? Please illuminate, the world awaits.
     
    #20     Sep 10, 2012