 |
savagemp5
Registered: Mar 2011
Posts: 205 |
09-10-12 04:57 AM
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.
|
| |
|
Edit/Delete • Quote • Complain |
Tonkadad
Registered: May 2002
Posts: 487 |
09-10-12 05:05 AM
Quote from savagemp5:
It just goes to show the world the reason of 95%/5%, the way you prioritize things.
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.
|
| |
|
Edit/Delete • Quote • Complain |
savagemp5
Registered: Mar 2011
Posts: 205 |
09-10-12 05:42 AM
u wan to learn hw to automate an algo that prints money every 3 hours.
So u wait here. I will spoon feed and teach you and everyone else !!! U wait.. wait..
|
| |
|
Edit/Delete • Quote • Complain |

cdcaveman
Registered: Aug 2011
Posts: 3514 |
09-10-12 06:29 AM
What's the %.f for?
Quote from 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:

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.
|
| |
|
Edit/Delete • Quote • Complain |

jcl
Registered: Jan 2012
Posts: 407 |
09-10-12 07:35 AM
Quote from cdcaveman:
What's the %.f for?
The %.f in the printf function is a placeholder. In the printed text, it is replaced by the content of a var passed to that function. We'll come to the printf function tomorrow. For today, we'll look into functions in general. Once you got variables and functions, you have a basic understanding of how a script works.
What are these functions, anyway? Let's see a small example:
code: function add_numbers( )
{
var a, b, c;
a = 3;
b = 5;
c = a + b;
}
Do you see what I see? A function is nothing more than a collection of C commands that are executed by the computer one after the other. Let's see some properties for these functions:
► A function is normally defined using the word function followed by the name of the function and a pair of parentheses (). The parentheses are used to pass additional variables to the function; we'll learn about that later. In our case we don't pass any variables, so they are empty.
► The body of the function (its list of commands) must be written inside a pair of winged brackets { }. The body consists of one or more lines of lite-C code that end with a semicolon. For clarity, programmers usually indent the code in the function body by some spaces or a tab, for making clear that it is inside something.
► The names used for the functions follow the same naming convention as for variables. You shouldn't use the same name for a variable and a function; this will lead to errors.
If you can read this tutorial I hope that you know your age, too. Not in years, but in days! What, you don't know it? Ok, so let's try to write a function that computes the number of days spent by me (or you) on Earth.
I know how to start! I write the keyword function and then the name of the function; let's name it compute_days:
function compute_days()
{
I haven't forgotten the parenthesis after the name of the function and I have added the first curly bracket!
We will use some variables, so we'd better define them now:
var my_age = 33; // your age (in years) goes here
var days_a_year = 365.25;
Nothing new so far, right? We have defined two var variables and they have received initial values, because I know my age in years and I also know that every year has about 365.25 days. Now comes the scary part: how will I be able to tell the computer to compute the number of days? How would I do it with a pocket calculator? I would enter something like this:
33 * 365.25 =
Now let's take a look at our variables; if I replace 33 with my_age and 365.25 with days_a_year, I will get something like this:
number_of_days = my_age * days_a_year;
Ok, so our function should end like this:
var number_of_days = my_age * days_a_year;
printf("I am %.f days old!",number_of_days);
}
I have remembered to add the second curly bracket, so now the body of the function is enclosed by the two required curly brackets. I am really curious to see if this function works, so let's test it. Fire up Zorro, and then select [New Script] in the Script list. Wait until the editor opens. Then copy and paste the lines below into the editor window. Select the entire script below with your mouse, right click and choose Copy (or hit [Ctrl-C]), switch to the editor, right click into the empty window named "script1", then choose Paste:
code: function compute_days()
{
var my_age = 33;
var days_a_year = 365.25;
var number_of_days = my_age * days_a_year;
printf("I am %.f days old!",number_of_days);
}
The code looks pretty simple, doesn't it? We already know how to work with those variables, we know how to add comments... So let's save it (File / Save As) into the Strategy folder of the Zorro installation, under a name like myscript2.c. Don't forget the ".c" at the end - it means that this file contains C code.
If you did everything right, you should now find myscript2 in the Script list. Select it. Time to [Test] our script:

Does this error message mean that a script always need a main() or run() function? Yes, main is a predefined function name. If a function is named main, it will automatically run when we start our script. The function named run is special to Zorro; it contains our trade strategy and is automatically run once for every time period. If a script has neither a main nor a run function, Zorro assumes that you made a mistake and will give you this error message.
Now, let's enter a main function at the end of the script:
code: function main()
{
compute_days();
}
The way I see it, this code 'calls' (meaning it starts) our compute_days function. Ok, now that we are here let's see how we call a function: we write its name followed by a pair of parenthesis and then we end the line of code with a semicolon. Sounds logical, doesn't it?

Important tip: write the lines of code for your functions first and call them later. The computer reads the code the same way you read a book: it starts with the top of the script page and goes down to the bottom, reading the code line by line. If I would write my script the other way around, like this:
code: function main()
{
compute_days();
}
function compute_days()
{
...
}
the computer will say: oh, that's function main. I know function main; I need to run it every time. What does it say now? compute_days(). What's with this function? I don't know it yet! I don't know what it wants from me. I'm going to display an error message and I'll take the rest of the day off.

Don't forget to define your functions first, otherwise the computer will complain when you try to use it.
Tomorrow we'll look into functions more closely. Please complain here when something didn't work or was unclear.
|
| |
|
Edit/Delete • Quote • Complain |

| Receive
an email whenever a new post is added to this thread by subscribing
to it. |
|
|
|
|