AFL Coding required

Hi,

I try to do my own research and use Amibroker to select my stocks for the next day but its a long manual process that takes a lot of my time.
Would request you if your team can create this stock scanning strategy for me in Amibroker.

Please help me code this strategy:

BUY when EMA 15 is above EMA 30 irrelevant of the stock price BUT the important thing here is
William’s %R(3) is below -80(oversold)

SELL when EMA 30 is above EMA 15 irrelevant of the stock price BUT the important thing here is
William’s %R(3) is above -20(overbought)

Please mail me the AFL if you can.
Looking for a positive reply.

Thanks,
Vishal Kapoor.

@vishalk If you post some code so that we can see what you are having a problem with then maybe someone on the forum can help you. For a moving average crossover you need to read this,

https://www.amibroker.com/guide/afl/cross.html

For the additional condition of your Williams % R you need to use the AND function,

https://www.amibroker.com/guide/a_language.html

But I think you really need to start by reading this post,

I really hope this forum does not become like some of those other crappy forums where many posts are just requests for free code writing with no effort made by the original poster to solve his/her own problem.

@spintrader, Herman made a kind and compassionate post worth reading,

and to Herman’s point it would have taken less time for me to provide a full solution than to create this response. But that would then encourage more posts like the original where no effort to learn Amibroker has been displayed.

Helping others is often done with the hope that the newbies will become more proficient in Amibroker and then become active and helpful contributors on the forum. But I believe that posts that exhibit no effort indicate that the poster is very unlikely to ever become a helpful contributor to the community. If you doubt this then you should take a look at a couple of other forums (I will not post the sites here) where you find dozens of “no effort” requests and if you scroll through the years of posts those same members Never offer to help others.

I also think that trading is hard and takes a lot of study. You are competing against organizations and individuals who are investing a great deal of time, effort and money to take your money. Maybe we should actively discourage forum members who don’t have the inclination to work hard at learning this. We may actually be saving them from the inevitable trading losses they are heading for.

Lastly I am not the best person to make this post as I have neither the time nor expertise to actively participate on the forum. But I do make my appreciation felt by posting dozens of “likes” (the little heart shaped icon) to hopefully thank and encourage those contributors who take time out of their busy days to make this a great forum.

Although it is nice for someone to post a “thank you” for an answer, I am pretty sure I read that Discourse encourages you to skip that “thank you” post and just click on the “like” heart to express your thanks.

Keep at it @vishalk and you will be thankful that you learned Amibroker.

5 Likes

Hi,

I tried my best to create an AFl by reading and looking at various videos.

Came up with this, can anyone go through it and tell me if its correct, also some could please help me
how do I code the conditions to the generate buy sell signal, and whether its complete.

Thanks.

_SECTION_BEGIN(“Price”);
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, “Close”, ParamColor(“Color”, colorDefault ), styleNoTitle | ParamStyle(“Style”) | GetPriceStyle() );
_SECTION_END();

Long = EMA(C, 30);
Shoter = EMA(C, 15);

Plot(Long, “Longer EMA”, colorRed, styleNoTitle);

Plot(Shoter, “Shoter EMA”, colorBrightGreen, styleNoTitle);

_SECTION_BEGIN(“William’sTRY 3”);
//-- Begin of Script -----
pds = Param( “Periods”, 3, 2, 200);
OB = Param( “OB Level”, -20, -49, 0);
OS = Param( “OS Level”, -80, -100, -51);

WR = ((HHV(H,pds) - C) /(HHV (H,pds) -LLV (L,pds))) *-100;

_N(Title = StrFormat("{{NAME}}- W%%R(%g)= %g", pds, WR));

Plot( WR, “”, ParamColor( “Color”, colorBrown ), ParamStyle(“Style”));
Plot(OB,"",colorBlack);
Plot(OS,"",colorBlack);

PlotOHLC( WR,WR,-50,V, “”, colorRed, styleCloud | styleClipMinMax, OS, OB );
//-- End of Script -----
_SECTION_END();

Buy = ??

Sell = ??

1 Like

First of all, make sure you read How to use this site and use Code markups so your AFL displays correctly on the forum.

Your Buys and Sells will be a combination of your array definitions combined with ANDs, eg:

Buy = Shoter > Long AND WR < -80;
Sell = Long > Shoter AND WR > -20;

The rest of it looks fine. Well done for have a go at it.