Transferring formula to AFL

Dear ALL

I have simple code which work om MetaStock and I want to get the write code of AFL to use it on AmiBroker , this formula representing 4 moving Average

below is the code working om Metastock

Div(Mov(H,13,S) + Mov(L,13,S) + Mov(H,65,S) +Mov (L,65,S) , 4 )
;Div(Mov(H,13,S) + Mov(H,65,S) ,2)**
;Div(Mov(L,13,S) + Mov(L,65,S) ,2)
;Div(Mov(H,9,S)

can any one help to make it work on amibroker please

Thank you all

@ali I think on this forum you will find that you can get more help if you make an effort. Some effort to show that you are trying to learn how to use AmiBroker. This is not a free code writing service.

Also, use words to describe your strategy or indicator because the mess of unformatted Metastock gibberish that you posted in not easy to understand (are you trying to divide them, or multiply them or both?).

To help get you started, you appear to want 4 moving averages and then you want to do some calculations with them?

Ave1 = MA(H, 13);
Ave2 = MA(L, 13);
Ave3 = MA(H, 65);
Ave4 = MA(L, 65);

// and then your last line
Ave5 = MA(H, 9);

I don't understand what it is you want to do with those moving averages, and do you only want those exact look back periods or do you want to create parameters for the different length's? To learn about AmiBroker's moving average function you should of course read the User Guide.

http://www.amibroker.com/guide/afl/ma.html

Good luck.

4 Likes

In MS language Div is simply division. So instead of Div( A, B) write A / B in AFL.
MOV( H, 13, S ) is 13-bar simple moving average of High price. So in AFL it is MA( H, 13 );

@portfoliobuilder @Tomasz
Thank you all for helping

I already tried to represented on the chart and it didn't work , I'm sorry but I did my best
below is the code which I write for the first moving average only but still it going a way from pricing chart

(MA(High,13)+MA(Low,13)+MA(High,65)+MA(Low,65) /4)

-- in this line I'm trying to take the average of all of this 4 moving then divide it by the total number , it means each line mentioned in Meta Stock formula refer to 1 simple moving average so if i have 2 moving avg I should sum them then divide by 2 to get final result

-- also i but the line above in below code to show the out but

_SECTION_BEGIN("MA");

Plot( (MA(High,13)+MA(Low,13)+MA(High,65)+MA(Low,65) /4), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

At the end I should get 4 moving average working on the price chart which i couldn't get it yet

Thank you for supporting

I think one of your brackets is in the wrong position. I haven't tested in AB.

MyAverage = (MA(High,13)+MA(Low,13)+MA(High,65)+MA(Low,65))/4
1 Like

Sorry, left out the semi-colon - rookie error.
Also, make sure you use the code button </> when posting code.

MyAverage = (MA(High,13)+MA(Low,13)+MA(High,65)+MA(Low,65))/4; 

If you expect to see price and 4 moving averages, you need at least 5 Plot() , one for price and 4 Plots, one for each moving average

1 Like

Thank you a lot I appreciate your support all
as @Chris25 my brachets wasn't right position
@awilson Thank you It's working on the chart now