could anybody explain this coding of afl

sparun

Active Member
#1
prev=AMA2(C,1,0);

d=IIf(C>Ref(Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),-1),Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))),
IIf(C<Ref(Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))),-1),Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),PREV));
 

mastermind007

Well-Known Member
#3
prev=AMA2(C,1,0);

d=IIf(C>Ref(Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),-1),Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))),
IIf(C<Ref(Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))),-1),Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),PREV));
This code could be used to set discretionary stop loss strategy
 

pratapvb

Well-Known Member
#4
prev=AMA2(C,1,0);

d=IIf(C>Ref(Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),-1),Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))),
IIf(C<Ref(Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))),-1),Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),PREV));
d=IIf( C> Ref( Max(
Max(H, Ref(H,-20)), // max of high and high 20bar back
Max(Ref(H,-10), Ref(H,-15)) // max of high ten bars back and high 15 bar back
// max of high, high 10 bars back, 15 bars back and 20 bars back
), -1), // not counting current bar


Min(
Min(L,Ref(L,-20)),
Min(Ref(L,-10),Ref(L,-15))), // then min of low of current 10 and 15 and 20 bars back

//else
IIf( C< Ref( Min(
Min(L, Ref(L,-20)),
Min(Ref(L,-10),Ref(L,-15))
),-1),

Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),

PREV));



so it means

if ( C > max of high of prev bar, 10+1 bars back, 15+1 bars back and 20+1 bars back)

then
d = min of low of current bar, 10 bars, 15 bars and 20 bars back

else
if ( C < min of low of prev bar, 10+1 bars back, 15+1 bars back and 20+1 bars back)

then
d = max of high of current bar, 10 bars, 15 bars and 20 bars back

else // that is neither of above conditions is satisfied
d = PREV ( which was set to AMA2(C, 1, 0)
 

pratapvb

Well-Known Member
#6
pratap sir , what is ama2(c,1,0) ??
similar to AMA but provides for feedback factor in addition to smoothening factor....here anyway the last argument = 0

SYNTAX ama2( ARRAY, SMOOTHINGFACTOR, FEEDBACKFACTOR )
RETURNS ARRAY
FUNCTION calculates adaptive moving average - simliar to EMA() but smoothing factor could be time-variant (array).
AMA2 has a separate control of feedbackfactor which is normally (1-SMOOTHINGGFACTOR). Internally this function works like this: today_ama = SMOOTHINGFACTOR * array + FEEDBACKFACTOR * yesterday_ama
EXAMPLE The example of volatility-weighted adaptive moving average formula: graph0 = ema( close, 15 );
fast = 2/(2+1);
slow = 2/(30+1);
dir=abs(close-ref(close,-10));
vol=sum(abs(close-ref(close,-1)),10);
ER=dir/vol;
sc =( ER*(fast-slow)+slow)^2; graph0 = ama2( close, sc, 1-sc);
 

sparun

Active Member
#7
d=IIf( C> Ref( Max(
Max(H, Ref(H,-20)), // max of high and high 20bar back
Max(Ref(H,-10), Ref(H,-15)) // max of high ten bars back and high 15 bar back
// max of high, high 10 bars back, 15 bars back and 20 bars back
), -1), // not counting current bar


Min(
Min(L,Ref(L,-20)),
Min(Ref(L,-10),Ref(L,-15))), // then min of low of current 10 and 15 and 20 bars back

//else
IIf( C< Ref( Min(
Min(L, Ref(L,-20)),
Min(Ref(L,-10),Ref(L,-15))
),-1),

Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),

PREV));



so it means

if ( C > max of high of prev bar, 10+1 bars back, 15+1 bars back and 20+1 bars back)

then
d = min of low of current bar, 10 bars, 15 bars and 20 bars back

else
if ( C < min of low of prev bar, 10+1 bars back, 15+1 bars back and 20+1 bars back)

then
d = max of high of current bar, 10 bars, 15 bars and 20 bars back

else // that is neither of above conditions is satisfied
d = PREV ( which was set to AMA2(C, 1, 0)


thank u pratap :clapping::clapping:
 

Similar threads