Sie sind auf Seite 1von 9

5/27/2015

Easylanguage & PowerLanguage Tutorials - Lesson 01: The Basics

Home

Blog

Services

Custom Easylanguage
Programming
Project Description
Projects Include
Research
EasyLanguage Consulting
Multicharts Programming
Free Custom Programming
Free Indicator Download
Project Showcase
Testimonials

Contact Us

Go to...

Home
Blog
Services
Custom Easylanguage Programming
Project Description
Projects Include
Research
EasyLanguage Consulting
Multicharts Programming
Free Custom Programming
Free Indicator Download
Project Showcase
Testimonials
Contact Us
Home/EasyLanguage Tutorial, PowerLanguage Tutorial/EasyLanguage & PowerLanguage Tutorials Lesson 01

Previous Next

http://www.abctradinggroup.com/powerlanguage-tutorials-lesson-01/

Search ...

1/9

5/27/2015

Easylanguage & PowerLanguage Tutorials - Lesson 01: The Basics

EasyLanguage & PowerLanguage


Tutorial Lesson 01
The first steps towards Easylanguage & PowerLanguage proficiency

We are providing
solutions

for

independent
traders,

trading

Recent Posts
Recommended Futures

groups

and

hedge

funds

Broker for MultiCharts

since 2005. We

Trendlines and Text:

are

Learning EasyLanguage &

experts

in

Great, you are taking the first step towards learning to program in Multicharts and Tradestation. I am custom
PowerLanguage
happy for you as this will be an interesting journey.

PowerLanguage Lesson

This lesson will teach you the basics of the PowerLanguage and the PowerLanguage Editor. I have Multicharts.
Besides projects
thought about the best way to do the lessons. On the one hand we could dive into the

Lesson 04: If statements and

05

programming for

programming right away and I explain the theory along the way. On the other hand it seems a good in EasyLanguage
idea to lay a basic foundation and build up on this. When we deal with some of the basics in later for Tradestation,

conditional branching
Multicharts PowerLanguage
Tutorial Lesson 03: The

have
lessons you will have heard them already. This aspect of redundancy will hopefully help you learn we
provided
clients
things more easily, too.
The latter approach seems to give you a better learning experience.

Multicharts Tutorial

while loop
EasyLanguage &

strategies

PowerLanguage Tutorials

and indicators for

Lesson 02: Coding A Moving

with

In this lesson we will start familiarizing ourselves with the PowerLanguage Editor. We will learn the eSignal,
Ninjatrader,
difference between inputs and variables. How to declare and initialize them (and what the two

Average

Keep in mind that I am learning to teach this to you, too. I will try to keep it not too technical, but at trading
the same time include a couple of points that are good to know. So in case you have ideas on how platforms.

Learning EasyLanguage &

to improve the teaching or any other feedback, Id highly appreciate hearing it. Enough with the

05

talking, lets begin our journey.

Tole Sag on Trendlines and

Let me start with pointing out that a computer doesnt speak our language. It gets its instructions

Text: Learning

from machine code or an intermediate language. While you could program directly in these

EasyLanguage &

languages, it is much more comfortable to use a different programming language. One that is closer

PowerLanguage Lesson

to a human language, like PowerLanguage for example. Then you only need a program that is able

05

to compile your code into something the computer can understand. This is where the build in

ABC on Trendlines and Text:

compiler of the PowerLanguage Editor comes into play.

Learning EasyLanguage &

Lets take a look at the editor, where the coding and compiling is done. If PowerLanguage editor is

PowerLanguage Lesson

not yet running, please open it. You will likely see something close to this:

05

Recent Comments
words mean as well of course). Finally this lesson will cover some good coding practices that will Metatrader and
other
major
make your life as a programmer a lot easier.
ABC on Trendlines and Text:
PowerLanguage Lesson

Tole Sag on Trendlines and


Text: Learning
EasyLanguage &
PowerLanguage Lesson
05
ABC on EasyLanguage &
PowerLanguage Tutorials
Lesson 02: Coding A Moving
Average
Archives
September 2014
April 2014
January 2014
November 2013
September 2013
August 2013
June 2013
Categories
EasyLanguage Tutorial
PowerLanguage Tutorial
Research Ideas

The main window is currently empty. If you have studies open, they will be shown here. The
navigator window on the right lets you quickly access your studies and the dictionary. The
dictionary contains all keywords of the programming language. In conjunction with inputs and

http://www.abctradinggroup.com/powerlanguage-tutorials-lesson-01/

2/9

5/27/2015

Easylanguage & PowerLanguage Tutorials - Lesson 01: The Basics

variables we will use these keywords to program studies.


The bottom window displays three different tabs:
Build will provide information coming from the compiler. For example if there is a problem
with the code this information will help you tracking it down.
The Output window displays information coming from your studies. You can add code to
your studies to print values to the output window. This is useful for checking that your study
correctly works, too.
Help displays information from the build in help file. You can highlight a keyword and press
F1 and the PowerLanguage Editor will display the help information for this keyword. This is a
good tool when you need some clarification about how a keyword works.
Lets create a new indicator by clicking on File -> New within PowerLanguage Editor.

This will bring up a new window. Set the study type to Indicator and click OK.

Give the study a name of your choice. The only limitation is that the name cant be already in use by
a different study.
For example I will use ABC_PowerLanguage Lesson 01 as name and then click OK again. The name
will be what you use later to add the study to the chart, so it helps when it displays the purpose of
the study. I like using the ABC_ prefix to label the studies that I have worked on for myself or the
website for example. For other work I will use different labels. This makes it easier to find
something when I have to look up a study.
Every study can have inputs that you can assign a default value to. For example you can use an
input for the length of a moving average. The inputs for indicators and signals can be changed when
you load the study on a chart. So it makes sense to have some inputs to allow a more user friendly
study.
When you declare an input by giving it a name and initialize it by assigning a default value, you also
define the type of the input. There can be three different types:

http://www.abctradinggroup.com/powerlanguage-tutorials-lesson-01/

3/9

5/27/2015

Easylanguage & PowerLanguage Tutorials - Lesson 01: The Basics


1. a Numeric input
2. a String input
3. a Boolean input i.e. a true/false input

To declare an input you use the keyword Inputs (or Input they are the same) followed by : and
then the input name and the default value in brackets. You can declare several inputs and separate
them with a comma.
This is how the three different input types could look with a valid name and a default value:

Try it out yourself. Type the three inputs and when you are done, hit Compile (or F3).

The Build tab in the bottom window will now display something like this:

It displays the name of the study and the start and end time for the compilation. The message
indicates that you have just successfully compiled your first PowerLanguage indicator for
Multicharts. Congratulations.
If you receive an error message, this means there is something wrong with your code. Compare your
code to the code screenshot again and check for differences. This might be something simple like a
missing comma or a bracket not closed.
You can use the inputs in the code later, but the value of it cant change within the code. This is
where variables come into play.
Variables are used to store numerical, string, or logical (true/false) values. The value stored in a
variable can be referenced throughout a script by the variables name and can be modified by the
script at any time. Variables must be declared before use.
Your code can use variables to work with data. They are used to store a value and as the name
suggest the value can vary. It can be changed (it is variable, hence the name) while your study runs.
The value can be numerical, string or logical (true/false).
Just like the inputs the variables in PowerLanguage can have the same three types:
1. a Numeric variable
2. a String variable
3. a Boolean variable i.e. a variable storing true/false data
You also set the type by initializing the variable when you assign a default value to it.
Additionally you can specify the update basis (during the bar or at the end of the bar) and the data
number for each variable when you declare it. This is something I will cover in detail in a future

http://www.abctradinggroup.com/powerlanguage-tutorials-lesson-01/

4/9

5/27/2015

Easylanguage & PowerLanguage Tutorials - Lesson 01: The Basics

lesson, so dont worry about that at the moment.


Lets add some variables to your code now. Type in the three variables you see on the screenshot
and press Compile (or F3):

This did not work as expected. What went wrong? Take a look at the Build output tab. It will give
you a clue.

This word has already been defined. This refers to the second occurrence of A_Boolean_Input.
You can only use the same name once to declare a variable or input within each study.
PowerLanguage will treat upper and lower cases the same.
So VariableName is the same like VARIABLENAME or VariaBLENamE and every other
combination.
Change the variable name according to the screeshot below and it should compile without
problems.

While we are on the topic of inputs and variables, lets go over some things regarding the naming.
Apart from the reserved keywords you are totally free in choosing the name (except some special
characters like %, & or $ are not allowed, too). This means you can name a variable var1 or
WeightedAverage. Both could store the exact same value. The latter name however gives you an
idea about the purpose of the variable already. You can make your coding life a lot easier when you
use meaningful names for inputs and variables.
This comes in handy when you are looking through your code to track down a bug, too.
When you have a line like this:
Var1 = Var2 + Var3 * (Var4 Var2);
Its much harder to see what is intended with this piece of code. This line is in fact the calculation of
an exponential average. With using good variable names it can be a lot clearer:
ExponentialAverage = Average1BarAgo + WeightingFactor * (PriceValue - Average1BarAgo);
Before we finish the first lesson, lets go over a couple of things that will also help making your life
a lot easier in the long run.

Improve the readability of your code


http://www.abctradinggroup.com/powerlanguage-tutorials-lesson-01/

5/9

5/27/2015

Easylanguage & PowerLanguage Tutorials - Lesson 01: The Basics

I find it very helpful to have some structure in the code. This can be accomplished by whitespaces.
Horizontal tabs and blank lines after a code block for example help when you are working inside
the code. No one is stopping you to write your whole code within one line. However code like this
is much harder to maintain. The whitespaces will also not hurt your codes performance. When you
compile the code within the PowerLanguage Editor, the compiler will get rid of the whitespaces
when creating the machine code that Multicharts can work with.
Our input and variable part could look like this and the result would be exactly the same. It would
just be much harder to read:

Not only have the inputs and variables no meaningful names, but I have also been overly generous
with the horizontal tab and blank lines once and on other instances have not used them at all.
I want to conclude the first lesson with comments and my opinion on code commenting. You can
add code to your study that will be ignored by the compiler, but can add a lot of help for the
programmer to understand the code. Comments wont change the studies logic, they are only for
you or other programmers.
There are two types of comments:
a comment that only spans from the start of the comment to the end of the line
a comment that spans from its start to where you stop it
The first type of comment will start with // and end at the end of the line you start it.
The second type of comment will start with an opening brace { and end only if you set a closing
brace }.

These comments are great to add some explanations to your code. With that I dont mean adding
comments to every line to explain what is going on. Write the code in a clear way that its able to
tell what is done. Add the comments then to explain why something is done. There are no rules
carved in stone for code commenting. In my opinion everything that helps making the code easier
to read and understand is useful. Leave writing novels for the writers and dont let the comments
get too excessive.
Sometimes a code piece is very clear and doesnt need additional commenting. At other times you
might need a couple of lines to explain something.
Dont be afraid of using too many comments, though. Using no comments at all is definitely worse.
Having to understand code that is not commented at all and maybe doesnt use meaningful variable
names can be very time consuming. Id much rather go through code that uses too many comments.
Why should I use proper commenting, meaningful names and whitespaces if I am the only one
who works with the code?
Even if you only code for yourself it makes sense to use the coding techniques from above. While

http://www.abctradinggroup.com/powerlanguage-tutorials-lesson-01/

6/9

5/27/2015

Easylanguage & PowerLanguage Tutorials - Lesson 01: The Basics

you are writing the code everything is usually perfectly clear. You have a good grasp of why you are
doing what you are doing. If you have to go back to your code after weeks or month however, it
might not be that clear anymore. You will save yourself a lot of time in the end if you incorporate
some good coding habits right away. This will also help you finding bugs and problems easier. As
looking for problems is a major part in programming, everything that lowers the time spend with
problem finding is good.
Thats it for todays lesson. I hope it wasnt too technical, but I felt like laying a foundation is a good
starting point. The next session will be more practical for sure.
In this lesson you got to know the PowerLanguage Editor and learned how to compile a study. You
should know how to declare and initialize inputs and variables and their three different types.
The last part taught you some good coding habits to improve your code readability.
Using whitespaces, meaningful names and comments will make your life easier as they save you a
lot of time in the long run.
I am glad if this lesson was helpful for you and I am looking forward to creating Lesson 2.
1: If you like you can read more about machine code here.
By ABC|September 2nd, 2013|Categories: EasyLanguage Tutorial, PowerLanguage Tutorial|Tags:
easylanguage tutorial, lesson 1, powerlanguage tutorial|10 Comments

Share This Story, Choose Your Platform!

About the Author: ABC

10 Comments

1.
Fernando Santos September 11, 2013 at 7:58 am - Reply
Im looking forward for the next tutorials.
Really good service youre doing here, thanks.

ABC September 11, 2013 at 10:28 am - Reply


Thank you very much for your comment. I am having fun creating them, but I totally
underestimated the time that it takes to create one. Although I am pretty sure there is
a learning curve for me, too and I might get quicker with every tutorial. Having said
that I am currently working on the next one and it will cover more basics, like max
bars back, plotting, using functions and more.

2.
eddysmc September 18, 2013 at 7:47 am - Reply
thanks you very good and helpfull comment, im looking forward for your second tutorial

3.
Tcool September 28, 2013 at 6:31 pm - Reply
Merci,
Trs bonne initiative et trs bien fait
Jespre quil y en aura beaucoup dautres
4. Multicharts PowerLanguage tutorial - Lesson 2: Coding a Moving Average November 27,

http://www.abctradinggroup.com/powerlanguage-tutorials-lesson-01/

7/9

5/27/2015

Easylanguage & PowerLanguage Tutorials - Lesson 01: The Basics


2013 at 8:36 pm - Reply
[] Previous []

5.
stef November 28, 2013 at 5:44 pm - Reply
Thank you very much from stefano italy

6.
King Depp December 26, 2013 at 5:15 am - Reply
Excellent tutorial for the guy likes me who just wants to learn powerlanguage. Thank you
very much.
7. Trendlines and Text in EasyLanguage and PowerLanguage - Lesson 05 April 1, 2014 at 9:06
pm - Reply
[] a symbol. If you havent read the previous lessons, I suggest you start at the beginning
with lesson 01, as this lesson will use basics covered in earlier []

8.
Ignazio July 15, 2014 at 9:04 pm - Reply
I wrote:
Inputs:
A_Numeric_Input (123),
A_String_Input (I am a String),
A_Boolean_Input (true);
After compilation the message error:
A namespace cannot directly contain members such as fields or methods
ABCPowerLanguageLesson01 [Indicator] Ln 1
Firthermore the name you suggest for the new indicator is invalid; Not possible to put _ or
spaces.
The Idea of this tutorial is really good, but I think that is not so clear, or maybe some things
should be checked.
Thank you in advance
Best regards

ABC July 16, 2014 at 5:12 pm - Reply


Ignazio,
thank you for your reply. What platform are you using? My guess is that you are using
Multicharts.NET. This tutorial is for the regular Multicharts version (and Tradestation).
The code wont work with Multicharts.NET.
Regards,
ABC

Leave A Comment
Name (required)

Email (required)

Website

Comment...

http://www.abctradinggroup.com/powerlanguage-tutorials-lesson-01/

8/9

5/27/2015

Easylanguage & PowerLanguage Tutorials - Lesson 01: The Basics


Post Comment

I'm not a robot


reCAPTCHA
Privacy - Terms

Recent Posts
Recommended Futures Broker for MultiCharts
Trendlines and Text: Learning EasyLanguage & PowerLanguage Lesson 05
Multicharts Tutorial Lesson 04: If statements and conditional branching
Multicharts PowerLanguage Tutorial Lesson 03: The while loop
EasyLanguage & PowerLanguage Tutorials Lesson 02: Coding A Moving Average
Recent Tweets
Receive free custom programming worth more than US $500 with every new #Multicharts license you buy. Find out how: http://t.co/8zpEK6klNe
5 months ago
If you are using #Multicharts you might find this free VPOC and POC tool useful: http://t.co/pbluaPCszb #FT71
11 months ago
Latest Downloads

Risk Warning: Trading Futures, Options on Futures, and retail off-exchange foreign currency transactions carries substantial levels of risk and is not suitable for all
investors. Before deciding to invest in financial instruments or foreign exchange you should carefully consider whether trading is suitable for you in light of your
circumstances, knowledge, and financial resources. The high degree of leverage can work against you as well as for you and you may lose all or more of your initial
investment.
TradeStation, PowerEditor, EasyLanguage and the EasyLanguage Specialist logo are trademarks of TradeStation Technologies, Inc.
Neither TradeStation Technologies nor any of its affiliates has reviewed, certified, endorsed, approved, disapproved or recommended, and neither does or will review,
certify, endorse, approve, disapprove or recommend, any product or service that offers training, education or consulting regarding the use of EasyLanguage.
Copyright 2015 ABC Trading Group | All trademarks and copyrights are the property of their respective owners.
Legal Notice | Terms of Use | Sitemap | About Multicharts | About Tradestation | EasyLanguage Programmer | Contact Us

http://www.abctradinggroup.com/powerlanguage-tutorials-lesson-01/

9/9

Das könnte Ihnen auch gefallen