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

Help Troubleshooting EasyLanguage Code



PureBytes Links

Trading Reference Links

Dear Valued Client,

The following document was created by Victor Cuadra, our EasyLanguage 
Product Manger.  I'm sure it will be of help in troubleshooting 
EasyLanguage code, when sending information to a user or to create expert 
teachers that will give pointers as to what a chart is doing at a given 
moment.

    Working with Expert Commentary

Wouldn't it be great if you could know the value of any expression at any 
bar by just clicking at the bar? Or sending a customized message on a 
particular bar depending on what the market is doing? Well you can by using 
the expert commentary feature on Easy Language.    By clicking on the 
expert icon  and then clicking on any bar you can read commentary off any 
of your analysis techniques.

>From your Easy Language code in the Power Editor you can send messages to 
charting by using the Commentary() built in function.      This function 
creates the commentary that is read by the  expert  icon and is displayed 
on charting.

The Commentary() function will accept any text string or expression as a 
parameter.    This does not mean numbers can not be used to create 
commentaries, but that they will have to be converted to strings 
beforehand.

It is very easy to follow the values that a variable or expression adopts 
at any bar in your chart by using the commentary feature.   Lets create a 
system using this example:

Value1 = Value1 + 1.;
If Value1 > 10 then
    Value1 = 0;

As it is evaluated on each bar this code will add 1 to the value of the 
variable Value1, once it reaches a number greater than 10 it will be reset 
to zero.   Without using the Print command to send information to the print 
log or text drawing objects you can know what is the value of the variable 
Value1 on any bar by adding these lines to this code:

Variable: txt("");

Value1 = Value1 + 1.;
If Value1 > 10 then
    Value1 = 0;

txt = "The value of Value1 is: " + NumToStr(value1, 0) + NewLine;
Commentary(txt);

Remember that the Commentary() function only accepts text strings, so In 
order to convert a number to a string the function NumToStr(Num, Dec) is 
used.    The NewLine command is used to insert a carriage return at the end 
of the commentary.     This is important because if omitted, commentaries 
from other analysis techniques will start in the same line as the 
commentary from this system.

Once you apply this system to a chart and click on any bar with the expert 
commentary pointer you will see what value the variable has for that 
particular bar.     You can do this for any number of variables, functions 
or expressions that your analysis technique is using for trouble shooting 
or other purposes.

You might notice that the time used to calculate the analysis technique 
increased significantly once the Commentary() function was added to the 
code; this is because the commentary is being created in charting for every 
single bar of the chart.     By using the AtCommentaryBar built in function 
you can limit the number of bars where commentary is being run to the bar 
which is clicked with the expert commentary button.   So if you have not 
clicked on any bars with the expert commentary the code dedicated to expert 
commentary will not even be evaluated.    Our example would look like this:

Variable: txt("");

Value1 = Value1 + 1.;
If Value1 > 10 then
    Value1 = 0;

If AtCommentaryBar then Begin
txt = "The value of Value1 is: " + NumToStr(value1, 0) + NewLine;
Commentary(txt);
End;

You can also build messages that would express more complex expressions or 
ideas that have direct relation to the clicked bar on the chart.   For 
example, you could use the following code:

Variable: txt("");

If AtCommentaryBar then Begin
 	If Close > Close[1] then
txt = "On this bar: Close > Close[1]"
	Else If Close < Close[1] then
		txt = "On this bar: Close < Close[1]"
	Else
		txt = "On this bar: Close = Close[1]";
Commentary(txt);
End;

With this code you will receive a commentary comparing the close of this 
bar with the close of the previous bar.     This can be particularly useful 
to point out when markets are in a certain mode, when a system has entered 
in a setup phase, when some bar pattern is evolving or any other situation 
that is difficult to signal with a line, a dot on the chart or a bar being 
painted a certain color.   Now lets take a look at the following 
expression:

txt = txt +  "AND Condition2[" + NumToStr(Value1,0) + "]";

This expression will add  to what is currently held in the variable txt the 
string "And Close[" plus a string corresponding to the value of the 
variable value1 and closing with "]".     If we assign a value of 2 to the 
variable value1 we will have the string "AND Condition2[2]".    Now if we 
ran this expression after our previous commentary we would end with:

	"On this bar: Close = Close[1] AND Condition2[1]"

Now by placing a similar expression in a loop we can have the commentary 
build a Easy Language formula for the last N bars.    The code for this 
would be:

	If AtCommentaryBar then Begin
			If Close[0] > Close[1] then
					Txt = Txt +  " On this bar: Close[0] > Close[1] "
			Else If Close[0] < Close[1] then
					Txt = Txt + " On this bar: Close[0] < Close[1] "
			Else
					Txt = Txt + " On this bar: Close[0] = Close[1] ";
	
			For Value1 = 1 to 5 Begin
					If Close[Value1] > Close[Value1+1] then
						Txt = Txt +  "AND Close["+NumToStr(Value1,0)+"] > " + 
																			"Close["+NumToStr(Value1+1,0)+"] "
					Else If Close[Value1] < Close[Value1+1] then
						Txt = Txt + "AND Close["+NumToStr(Value1,0)+"] < " + 
																			"Close["+NumToStr(Value1+1,0)+"] "
					Else
						Txt = Txt + "AND Close["+NumToStr(Value1,0)+"] = " 
+																			"Close["+NumToStr(Value1+1,0)+"] ";
			End;
			Commentary(txt);
	End;

As the variable Value1 increases  the loop will  add the strings 
corresponding to 'older' bars together producing the corresponding bar 
pattern for the last five (5) bar closes.     Here is a screen shot of the 
results:
		


In sum, the expert commentary can be a great aid when trouble shooting your 
code, when sending information to a user or to create expert teachers that 
will give pointers as to what a chart is doing at a given moment.

Janette Perez
Corporate Relations Director