My first AFL- A thread for newbie questions


I could not find this answer on Forums Help File or Google.

My Code
Plot (MA(Close,21), "MA 21", colorBlue, styleLine, Null, Null,12);
Buy = ( Close > MA( Close, 21 ));
PlotShapes(IIf(Buy==1, shapeCircle , shapenone), colorWhite, 0,Low, Offset=-30);

What I understand from this code is when price close is greater then MA 21 buy value will be 1 and circle will be printed, When I plot this on chart it prints a circle when close is below 21, please help me understand the logic. I have marked it on chart as well.


I solved the issue myself with help of a friend.

I am sharing the answer as this caused a lot of incorrect result.

This issue happen only when we plot MA using the code
Plot (MA(Close,21), "MA 21", colorBlue, styleLine, Null, Null,12);

To solve this problem we plotted MA from Chart Option in Amibroker

then we only added Buy condition and it worked fine.

Reason for this issue is unknown to me. It should work fine from both places. Experts can guide better

This simply is user error/misunderstanding!

You shifted MA plot by 12 bars forward in time!
7th argument of Plot() function is surprise, surprise... x-shift.

What about AmiBroker manual...


So you have to set xshift to zero if you do not want to shift in x-direction.

Plot (MA(Close,21), "MA 21", colorBlue, styleLine, Null, Null, xshift = 0);

And FYI, apparently you have not read this thread in regards to using code tags.


Thank you for pointing that out, I am a beginner, trying hard to grasp everything. This line of code took me 3 days to write with at least 7-8 hours of searching finding and trying. Even though I did see that page I would not have understood what is xshift, until a detailed explanation would have been given with example to use x- shift.

But thank you for clarifying it. At least I know now what is x-shift and why my code was not working.

Thanx again.



Thank you my Licence is verified now

1 Like