How to create Moving Average Cross code afl

Dear Experts,

I’d like to get AFL scan for Below Condition. Please Help Me.

Buy signal: When short term Moving average 20 cross above Moving average 50, and long-term Moving average 100 is above Moving average 200 to confirm uptrend.

I’m waiting for your help.

Thanks and Best Regard,

@hungnsm11 this site works best if you show us your attempts at coding, and we can help you learn if you have made a mistake, or we see a better way to approach it.

Coming on the site, waiting an hour, then posting a “do it for me” type questions, does not endear you to us. Why should we help if you have not put the effort in to try???

When you come to post your work, make sure you read the “How to use this site” and use the proper code tags.


May be you want to check here (not verified) …

It is Very Simple only.
Please Try this one.
Learn AFL and come up next time with an attempt.
Nobody would help you out if you ask this way every time.

_SECTION_BEGIN("20/50/100/200 EMA Trending");


Buy = Ref(W,-1)<Ref(X,-1) AND Ref(W,0)>Ref(X,0) AND Ref(Y,0)>Ref(Z,0) ;
Sell = Ref(W,-1)>Ref(X,-1) AND Ref(W,0)<Ref(X,0)  AND Ref(Y,0)<Ref(Z,0) ;

PlotShapes( shapeUpArrow*Buy, colorPink,0, L, -20);
PlotShapes( shapeDownArrow*Sell, colorPink,0,H, -20) ;

Filter=Buy OR Sell;


All the Best.
Gloria Filamino


To check for buy signals according to your short term strategy, you can use the below code:

Buy = Cross(EMA(Close, 20), EMA(Close, 50));

For your long term strategy, you can use this code:

Buy = Cross(EMA(Close, 100), EMA(Close, 200));

You can also combine the above two:

Buy = Condition1 AND Condition2;

This way you will only get buy signal when both conditions are met.

1 Like

@ Gloriafilamino plz help me also devolop an afl code.I want to develop an AFL code that recognises and gives indication like lines or dots in the specific time frame whenever 50 ema,100 ema,150 ema and 200 ema reach almost equal level for a short time like 5 min,10 min,15 min,30 min++ time.


Welcome to the forum.

There are a few things that you need to do to get help.

  1. Get your "Verified Badge". If you don't know what that is, do a search and follow the steps to get Verified.
  2. Search and Read - How to use this site.
  3. Show YOUR work. (Use code blocks so it is easy for people to try to help you out).

This forum is meant as a "Help You Learn", but it means that You have to show you are trying.


@gopan once you have followed the suggestions by @snoopy.pa30 you should also carefully and thoroughly read,

And as to your specific coding request, define exactly what you are looking for and perhaps this function will help you achieve your goals.

Good luck, and welcome to AmiBroker! Once you have posted some attempts at code you will get more responses about how to fix your code.