Saturday, May 25, 2013

AFL Code Writing : Lesson 3 (Part 4)

Returned from the hibernation.

In our last tutorials we show you how to add simple moving average in your chart. We also learnt that how to make the moving average more dynamic for our user. Today, I will show you how to write moving average crossover.

Now, we will recall our last simple moving average code:

_SECTION_BEGIN("Moving Average");
//Below code will display 50 days simple moving average line
Plot (MA(Close, Param("Periods", 50, 2, 300)), "MA", ParamColor("Color", colorRed), ParamStyle("Style", styleThick));
_SECTION_END();

Today, we will see a moving average crossover between 10 days moving average and 30 days moving average. We already have code for moving average. We will use it. I have just copied the above moving average code 2 times as follows:

_SECTION_BEGIN("MA 30");
//Below code will display 30 days simple moving average line
Plot (MA(Close, Param("Periods", 30, 2, 300)), "MA", ParamColor("Color", colorRed), ParamStyle("Style", styleThick));
_SECTION_END();

_SECTION_BEGIN("MA 10");
//Below code will display 10 days simple moving average line
Plot (MA(Close, Param("Periods", 10, 2, 300)), "MA", ParamColor("Color", colorBlue), ParamStyle("Style", styleThick));
_SECTION_END();


I have made the following changes on our above two moving averages:
  • I have given separate names for our two moving averages. One is MA 30 and another one is MA 10. MA stands for Moving Average.
  • I have changed 50 days to 30 days and 10 days.
  • I have also changed the 10 days moving average color from from red to blue as our both moving average color were same.
Now, our final code for the two moving averages crossover as follows:
/*
-------------------------------
AFL code writing for moving average cross-over.
Date : May 25, 2013
-------------------------------
*/

_SECTION_BEGIN("Price");
//The below code will display the price through candlesticks
Plot( Close, "Close", ParamColor("Color", colorGold), ParamStyle("Style", styleCandle, maskAll));
_SECTION_END();


_SECTION_BEGIN("MA 30");
//Below code will display 30 days simple moving average line
Plot (MA(Close, Param("Periods",30, 2, 300)), "MA", ParamColor("Color", colorRed), ParamStyle("Style", styleThick));
_SECTION_END();


_SECTION_BEGIN("MA 10");
//Below code will display 10 days simple moving average line
Plot (MA(Close, Param("Periods", 10, 2, 300)), "MA", ParamColor("Color",colorBlue), ParamStyle("Style", styleThick));
_SECTION_END();

//-----------------------------

Allah Hafiz

3 comments:

  1. Hello JC , thank you very much for your tutorials in AFL writing, iam willing to learn lot more, where can i find to learn some more advance afl writing tutorials by you.please guide me.. thankyou

    ReplyDelete
  2. I like to learn AFL code writing, I have gone through your lessons and nicely completed those, can you please tell me how I can get the remaining lessons,

    You kind help will be highly appreciated,

    Thank you,

    Regards,
    Shahadat
    e-mail : shahadat@edenintl.com

    ReplyDelete
  3. Hello there, I am Rakshit Krishan Kundra, I represent the HR team of BLB Limited. We have 2 very urgent positon for candidates who have expertise on AFL coding. Salary is no bar for a relevant candidate if he proves himself to be the one we are looking for. Relevant candidate can send their profiles on my official email id rakshit.bcl@blblimited.com and can also contact me directly on +918130598523.

    ReplyDelete