Wednesday, December 14, 2011

AFL Code Writing : Lesson 2 (Part 4)

In our last lesson, I explained the below code :

_SECTION_BEGIN("Price");
Plot( Close, "Close", ParamColor("Color", colorGold), styleBar);
_SECTION_END();


And we also gave the power to our user to change the color without changing the afl code. Our chart also looked like below :

Now, we will modify the above chart. We will thick the bar by adding styleThick after styleBar.

Again Copy and paste the below code in your Formula Editor :

_SECTION_BEGIN("Price");
Plot( Close, "Close", ParamColor("Color", colorGold), styleBar | styleThick);
_SECTION_END();


Please see we did not use coma " , " to separate the two items. We've used  " | " sign. Because both are in same group. Did not understand, right? Okay, no problem. Please keep it in your mind that Bar and Thick began with style. That's why we separate styleBar | styleThick by  " | " sign instead of  " , " . I hope you have already copied and pasted the above code in your Formula Editor and your chart's bar looks like thick bar :

Again Copy and paste the below code in your Formula Editor :

_SECTION_BEGIN("Price");
Plot( Close, "Close", ParamColor("Color", colorGold), styleBar | styleThick | styleNoLabel);
_SECTION_END();


We have use styleNoLabel. As a result Label will not be displayed. Are you still confused regarding the Label? Okay, see the below chart :

I've described styleBar | styleThick | styleNoLabel  but these are not the all. Moreover, your user of afl does not know the code. We can solve this problem by the ParamStyle() function. Okay, copy and paste the below code in your formula editor:

_SECTION_BEGIN("Price");
Plot( Close, "Close", ParamColor("Color", colorGold), ParamStyle("Style", styleBar, maskAll));
_SECTION_END();


After Save As and displaying the chart, pls. right click on the chart and you will find Parameters... and click on Parameters..... your will find  :

Now checked and unchecked the box as per your desire and see the effect on the chart.

Finally, I'll describe the ParamStyle function :

Syntax : ParamStyle("Style", styleBar, maskAll)
Meaning : ParamStyle() indicates that it will be displayed in the Parameters dialog box so that our user can change the style without editing the code.


Syntax : ParamStyle("Style", styleBar, maskAll)
Meaning : "Style" - It's a name. It has no programing value. You may keep it blank. For more please see the immediate previous lesson.


Syntax : ParamStyle("Style", styleBar, maskAll)
Meaning : "styleBar" - I've taken the styleBar as default style i.e. I would like to price through bar.


Syntax : ParamStyle("Style", styleBar, maskAll)
Meaning : "maskAll" - You need not to memorize all the style. If you write maskAll, all the style will be displayed and your user will be able to select style as per their desire.

Allah Hafiz

No comments:

Post a Comment