[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Drawing Objects from EasyLanguage



PureBytes Links

Trading Reference Links

*** TFS Evaluation Copy of module : MS Exchange ***

Dear Valued Client:

Many of you were very happy with examples written by our EasyLanguage Product 
Manager posted last week.  So I am attaching 
a new document that will walk you through creating drawing objects using 
EasyLanguage.

Thank you for your continued support.

Janette

Drawing Objects from EasyLanguage
a. 	Drawing text on the screen

    With Trade Station you will be able to have your analysis techniques write 
text automatically on your charts.      Analysis Techniques can write text  
only on sub-graphs that hold price data,     EasyLanguage will not write text  
on a new sub-graph or on one which contains indicators only.    

    Whenever you write text in charting, Trade Station will assign an number 
to it.    This is called the text object reference  number and you will use it 
to reference this text  from Easy Language.   Whenever the Text_New() function 
is used to write text to the chart it will return the reference number used by 
charting,   this is very important as you will use this number to reference 
the text object to either modify its attributes, delete it, move it or read 
its value. 


1. 	Needed: a date, time and price

    In order to write text to a chart, either from Easy Language or using the 
drawing object tool in Charting we will need to decide where we want to place 
the text in the chart.     Because charts have time ( date and time ) as their 
X axis and price as the Y axis, we will have to specify the location of the 
text by providing a Date, Time and Price;  so with this information Trade 
Station can write to a specific point in your chart.     

The function used in Easy Language to draw trend lines on the chart is
 	Text_New(Date, Time, Val, "Text")
    Where:
Date		Date of the bar where the text will be drawn
Time 		Time of the bar where the text will be drawn (for daily, weekly and
 monthly  charts the trading Session end time is used)
Val		Price used to place the text in the chart
Text		The string expression that will be written in the chart

So when Trade Station reads the line
   Value1 = Text_New(970103, 1200, 780.00, "Text");
It will write the word Text the 12:00 o'clock bar of January 3rd of 1997 at 
780.00 AND will store the text object referemce number in the variable Value1

    In order for text to be written in a chart from a EasyLanguage study, 
there has to be a bar with the date and time specified in the Text_New() 
function.    If you are plotting Daily bars and the date corresponds to a 
weekend or a holiday the text will not be written.   If you are using 60 
minute bars and the specified time does not match the time of one of the bars 
in the chart the text will not be written. 


2. 	Formatting Text Drawing Objects

    Whenever text is written to a chart from EasyLaanguage it will use the 
default attributes from charting, but often you will want to modify these 
attributes.    Whenever you want to change the defaults that trend lines have 
you will need to use the   Text_Setxxx()    functions.     

    In order for you to modify the attributes of a text drawing object  you 
will need two basic requirements: first,  you need to know the reference 
number used to identify the text you want to change, second you need the text 
to exist in the chart.    

    As stated in the beginning of this section, whenever you need to work with 
text drawing objects will need to know the reference number first.     When 
you write text charting will assign a number to it, in charting you can see 
what  this number is by clicking on the text and holding down the mouse button 
and reading the caption and/or status bar of Trade Station.    You will see a 
id#=9999 where 9999 will be the reference number of the particular object you 
are pointing at.  if you are creating the text object by using the Text_New() 
function it will return the reference number and you can store it in a 
variable for latter use.   In example, if you use the code
	Value1 = Text_New(970103, 1200, 780.00,"Test");
The word Test will  be written on the chart and the reference number will be 
stored under the variable Value1.

    The second requirement seems obvious but often text written by studies 
will disappear  after a Text_Setxxx() function is added to the Easy Language 
code, this is generally because the Text_Setxxx() function is executed before 
the text is written on the chart.    When this happens the Text_Setxxx() 
function will  return an error and no text functions will be executed there 
after by  the analysis technique.   If your Easy Language code writes text 
whenever a certain condition occurs, it is imperative that you set the 
attributes of this object after the text is written.   In example:

If LastBarOnChart then
    Value1 = Text_New(Date, Time, High, "Test");

Value5 = Text_SetColor(Value1, Tool_Red);

    This code will write the word Test at the last bar of the chart, yet it 
tries to change the color to red from bar 1 (the Text_SetColor() function has 
no IF-THEN).    The set color function will return an error as the text will 
be written only in the last bar of the chart,.    To avoid this, you can 
change you code to

If LastBarOnChart then
Begin
    Value1 = Text_New(Date, Time, High, "Test");
    Value5 = Text_SetColor(Value1, Tool_Red);
End;


3. 	Choosing When to Write to a chart

    There is a limit of XXXX text drawing objects per chart and if a chart, 
also writing text on every single bar may overload the chart to a point that 
is becomes unreadable, so it will be necessary to limit the number of bars 
where you write text from your analysis technique.     

By using a IF - THEN statement you can limit the bars where text is written to 
by the Easy Langauge code and avoid reaching the XXXX limit.     Drawing 
objects can be used in a similar fashion as a ShowMe or PaintBAr study, 
highlighting special events with a particular message.    IN example, if you 
are interest in Buying whenever two moving averages cross, you can write: 

If Average(Close, 8) Crosses Over Average(Close, 18) then
    Value1 = Text_New(Date, Time, High + .5, "Buy Here!");

These lines of code will write the message Buy Here!   Slightly above the High 
of the bar where a 8 bar moving average crosses over a 18 bar moving average.

If you want to only write text to a chart at if the cross over occurred at the 
very last a bar of the chart you can use the function LastBarOnChart, so you 
would write:

If Average(Close, 8) Crosses Over Average(Close, 18) AND LastBarOnChart then
    Value1 = Text_New(Date, Time, High + .5, "Buy Here!");


4. 	Using Text objects to trouble-shoot 

     Text objects can be very valuable as a way to trouble shoot your studies 
and systems, as you can place on any or all bars in the chart  the value of a 
variable or the result of an operation.     So if you want to know what value 
the variable Value20 has in each bar you can use the following code:

Value1 =  Text_New(Date, Time, High + .5, NumToStr(value20, 2));

This will show over every bar the value of the variable value20.    Note that 
because the Text_New() function can only write text expressions on the chart, 
the function NumToStr() is used to transform the value of the variable Value20 
into a text string.


b. 	Drawing Trend Lines

    With Trade Station you will be able to have your analysis techniques draw 
trend lines automatically on your charts.      Analysis Techniques can draw 
trend lines only on sub-graphs that hold price data.     Easy Language will 
not draw a trend line in a new sub-graph or one which contains indicators 
only.    

    Whenever you draw a trend line in charting, Trade Station will assign an 
number to it.    This is called the trend line reference number and you will 
use it to identify this trend line from Easy Language.   Whenever the TL_New() 
function is used to create a new trend line it will return the reference 
number provided by charting.    This is very important as you will use this 
number to reference the trend line to either modify its attributes, delete it, 
move it or read its value. 


1. 	Needed: a starting date, time and price AND a ending date, time and price

     In order to draw a trend line, either from Easy Language, using the 
drawing object tool in Charting or with a ruler in a sheet of paper, we will 
need two points.     In Easy Language we will call these the Trend Line start 
and end points.    

    Because charts have time ( date and time ) as their X axis and price as 
the Y axis, we will have to specify the Start and End points by specifying a 
Date, Time and Price for each;  so with this information Trade Station can 
draw a trend line in a chart from the start to the end point.     

The function used in Easy Language to draw trend lines on the chart is
 	TL_New(sDate,sTime,sVal,eDate,eTime,eVal)
    Where:
sDate		Date of the bar where the starting point is
sTime 		Time of the bar where the starting point is (for daily, weekly and 
monthly
charts the trading Session end time is used)
sVal		Price used as the starting point for the trend line
eDate		Date of the bar where the ending point is
eTime 		Time of the bar where the ending point is (for daily, weekly and 
monthly
charts the trading session end time is used)
eVal 		Price used as the ending point for the trend line

So when Trade Station reads the line
   Value1 = TL_New(970103, 1200, 780.00, 970124, 1200, 800.00);
It will draw a trend line from the 12:00 o'clock bar of January 3rd of 1997 at 
780.00 to the 12:00 bar of January 24th at 800.00  AND will store the trend 
line number in the variable Value1

     In order for the trend line to be drawn from your Easy Language study, 
there has to be a bar with the date and time specified in the start and end 
points.    If you are plotting Daily bars and the start point date corresponds 
to a weekend or a holiday the Trend Line will not be drawn.   If you are using 
60 minute bars and the specified time does not match the time of one of the 
bars in the chart the trend line will not be drawn.   Also, as a rule the 
starting point will have to be 'to the left' of the ending point.   That is, 
the starting point of the trend line has to be an earlier date/time than the 
ending point.	


2. 	Formatting Trend Lines 
		a.- Changing Attributes

    Whenever you apply a trend line to a chart from Easy language it will use 
the default attributes from charting, but often you will want to modify these 
attributes.    Whenever you want to change the defaults that trend lines have 
you will need to use the   TL_Setxxx()    functions.     

    In order for you to modify the attributes of a trend line you will need 
two basic requirements: first,  you need to know the reference number used to 
identify the trend line you want to change, second you need the trend line to 
exist in the chart.    

    As stated in the beginning of this section, whenever you need to work with 
trend lines you will need to know the trend line number first.     When you 
create a trend line charting will assign a number to it, if you are drawing a 
trend line manually from charting you can see what  this number is by double 
clicking on the trend line and reading the caption of the Format Trend Line 
window; if you are creating the trend line by using the TL_New() function it 
will return the trend line number and you can store it in a variable for 
latter use.   In example, if you use the code
	Value1 = Tl_New(970103, 1200, 780.00, 970124, 1200, 800.00);
The trend line will be drawn on the chart and the trend line number will be 
stored under the variable Value1.

    The second requirement seems obvious but often trend lines drawn by 
studies will disappear  after a TL_Setxxx() function is added to the Easy 
Language code, this is generally because the TL_Setxxx() function is executed 
before the trend line is drawn in the chart.    When this happens the 
TL_Setxxx() function will  return an error and no trend lines functions will 
be executed there after by  the analysis technique.   If your Easy Language 
code draws a trend line whenever a certain condition occurs, it is imperative 
that you set the attributes of this trend line after the trend line is drawn.  
 In example:

If LastBarOnChart then
    Value1 = TL_New(Date[10], Time[10], High[10], Date, Time, High);

Value5 = TL_SetExtRight(Value1, True);

    This code will draw a trend line at the last bar of the chart, yet it 
tries to extend the trend line to the right from bar 1 (the TL_ExtRight() 
function has no IF-THEN).    The extend right function will return an error as 
the trend line will be drawn only in the last bar of the chart,.    To avoid 
this, you can change you code to

If LastBarOnChart then
Begin
    Value1 = TL_New(Date[10], Time[10], High[10], Date, Time, High);
    Value5 = TL_SetExtRight(Value1, True);
End;


b. 	Moving vs. Deleting and Redrawing trend lines

    Often you will need to update the position of your trend line in the 
chart.   To do this you have two options:  delete the existing trend line and 
redraw it or move the current trend line.     If you delete the trend line and 
draw a new one in the new position you will need to keep track of the 
different trend line numbers and this can significantly complicate your code 
and trend line numbers will change as you delete the old trend line and draw a 
new one.     In stead you have the option of moving the start and end point of 
the existing trend line to a new position using the TL_SetEndD and 
TL_SetBegin() functions, thus keeping the original trend line number and 
simplifying the code of your analysis technique.

    When a trend line is moved such that the begin date falls after the end 
date, you must first set the end date  (using TL_SetEnd() function) so it is 
latter than the new begin date.   In the same way, when a trend line is moved 
such that the end date falls before the begin date, you must first set the 
begin date  (using TL_SetBegin() function) so it is earlier than the new end 
date.

    Moving the start and end points of the trend line will facilitate the task 
of tracking the reference number and will allow other studies to reference 
these trend lines.    So if you have an indicator that draws two trend lines 
and you have seen that these trend lines are using reference number 1 and 2, 
you can use these reference numbers from a system; while if you indicator 
deletes and redraws the trend lines on each bar the trend lines will use new 
reference numbers and other studies will not be able to track these trend 
lines.


3. 	Reading Trend Lines from a chart

     One of the most valuable functions available in Easy Language available 
to work with drawing objects is TL_GetValue(), this function will let you read 
the value that a trend line has for a particular bar.    Here are the uses of 
this function:


a. 	Trend lines created by the study

     Once your analysis technique draws trend lines to the chart you can 
follow the values that these trend lines adopt by using the TL_GetValue() 
function.    When you use the TL_New() function to create a new trend line you 
can use the values of this trend lines in your calculations, to trigger alerts 
and trading system orders.    In example, this code will write a trend line at 
the beginning of the month and then Buy 1 contract when the close crosses over 
the trend line:

Variable: TL_Ref(-1);

If Month(date) <> Month(date)[1] then
   tl_ref = TL_New(Date[10], Time[10], High[10], Date, Time, High);

If tl_ref <> -1 then
    If Close crosses over TL_New(tl_ref,  date, time) then
        Buy this bar at close;

    Note how the variable tl_ref is initialized with a value of -1, this is to 
avoid an attempt to read the trend line before it is drawn on the chart.    
When the variable tl_ref is different from -1 this will mean that a trend line 
was drawn, and the variable tl_ref has the reference number for the new trend 
line that has be drawn. 


b. 	Trend lines created by other studies

        Because information can not be exchanged between analysis techniques, 
you will need to determine what is the trend line reference number that was 
assigned to the trend line(s) created by the second study before hand.   For 
example:  the Trend Lines Automatic indicator (with the input named History 
set to "No" ) will always have a up trend line with reference number 0 and a 
down trend line with reference number 1 (this if no other trend lines are 
drawn before the indicator is applied).     So from a system you will be able 
to read these trend line and have orders generated based on these trend lines. 
  You can write the followin:

Value1 = Tl_GetValue(0, Date, Time);
value2 = TL_Getvalue(1, Date, Time);

If Close crosses under Value1 then
   Sell this bar on Close;
If Close crosses over Vlaue2 then
   Buy this bar on Close; 


c. 	Trend lines created manually by user

     Reading trend lines created manually in charting is very similar to 
reading trend lines created by other studies.    You will need to determine 
the trend line reference number used by your trend line in advance in order 
for the analysis technique to know what trend line to  look for.    You can 
write:

Inpuit: TL1(0), TL2(1);

Value1 = Tl_GetValue(TL1, Date, Time);
value2 = TL_Getvalue(TL2, Date, Time);

If Close crosses under Value1 then
   Sell this bar on Close;
If Close crosses over Vlaue2 then
   Buy this bar on Close; 

     As you can see in the example the input will allow you more flexibility 
at the moment of adding this trading system as you can specify one the moment 
of inserting the trading system what are the trend lines for a buy or sell 
signal.

Thanks,
Janette Perez
Corporate Relations Director