AFL writing guide for new user

#51
hi
I was trying to test a very basic BTST system.
it has a buy condition (say if 1 day ROC > 2%) then buy at todays CLOSE & sell tomorrows OPEN.

BuyPrice = Close;
SellPrice = Open;
Buy=ROC(C,1)>2;
sell = barssince(Buy)==1 ; works fine
but when buy condition is true for many consecutive days , system do not sell the next day, But the day next to day buy was true last time.
which makes it a forward looking system.

How can this be avoided.
Thanks in advance.

Best regards,
 
#53
Hi, this is the code for the slow stochastic:

Code:
_SECTION_BEGIN("Slow Stochastic");
periods = Param( "Periods", 8, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Dsmooth = Param( "%D avg", 4, 1, 200, 1 );
Plot( StochK( periods , Ksmooth ), "Stochastic (%K)", colorWhite, styleLine );
Plot( StochD( periods , Ksmooth, DSmooth ), "Stochastic (%D)", colorRed, styleLine );

PlotGrid( 80 );
PlotGrid( 20 );
_SECTION_END();
I would like to put an histogram behind the stochastic as similar as the MACD histogram, where the upside bars are only drawn if %K => 80 and %K =< 20

Do you think that can actually be done?

Thanks
 
#54
AFL FOR STOCHASTIC HISTOGRAM​

Here is the condition.

put an histogram behind the stochastic as similar as the MACD histogram, where the upside bars are only drawn if %K => 80 and %K =< 20

Here is the Code:
_SECTION_BEGIN("AFl by Debarghya Mukherjee");
periods = Param( "Periods", 8, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Dsmooth = Param( "%D avg", 4, 1, 200, 1 );
Plot( d1 = StochK( periods , Ksmooth ), "Stochastic (%K)", colorWhite, styleLine );
Plot( StochD( periods , Ksmooth, DSmooth ), "Stochastic (%D)", colorRed, styleLine );

Plot( IIf(d1 <= 80 AND d1 >= 20, d1-20, IIf(d1 > 80, 80-d1, d1-20)), "Histogram", IIf(d1 <= 80 AND d1 >= 20, colorRed, colorGreen) , styleHistogram );

PlotGrid( 80 );
PlotGrid( 20 );
_SECTION_END();

Here is the screen:
Hi, this is the code for the slow stochastic:

Code:
_SECTION_BEGIN("Slow Stochastic");
periods = Param( "Periods", 8, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Dsmooth = Param( "%D avg", 4, 1, 200, 1 );
Plot( StochK( periods , Ksmooth ), "Stochastic (%K)", colorWhite, styleLine );
Plot( StochD( periods , Ksmooth, DSmooth ), "Stochastic (%D)", colorRed, styleLine );

PlotGrid( 80 );
PlotGrid( 20 );
_SECTION_END();
I would like to put an histogram behind the stochastic as similar as the MACD histogram, where the upside bars are only drawn if %K => 80 and %K =< 20

Do you think that can actually be done?

Thanks
 
#55
YOUR AFL CHART GIVES VOICE BASED BUY AND SELL SIGNAL

This system will give you voice based signal at time of any signal.

Here is the code:

_SECTION_BEGIN("Debarghya: AFL Coding");

em3=EMA(C,3);
em13=EMA(C,13);
Plot( em3, "EMA(3)", colorRed );
Plot( em13, "EMA(13)", colorGreen );

PlotOHLC( Open,High,Low,Close, "Price", colorRed, styleCandle);
PlotOHLC( em3,em3,em13,em13, "", IIf( em3 > em13, colorGreen, colorRed ), styleCloud | styleClipMinMax );

Buy=Cross( em3, em13 );
Sell= Cross( em13,em3 );
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

PlotShapes(IIf(Sell==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-20);
PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorGreen, 0,Low, Offset=-20);

if (EndValue(Buy)==1) Say("Buy Alert: Buy now");
if (EndValue(Sell)==1) Say("Sell Alert: Sell now");

_SECTION_END();
 
#57
Thank you.
Warm wishes for this coming new year 2012 to you and your family.
Njoy lot.


Hi DM...... Good job..... Keep going and a very Happy New Year........ :)
 
#58
Bollinger Fibonacci Bands​

Here is the code:

_SECTION_BEGIN("Debarghya: AFL Coding");
GraphXSpace = 3;
per = Param("Period",20,10,55,1);
TH =IIf(Ref(C,-1) > H,Ref(C,-1),H);

TL=IIf(Ref(C,-1) < L,Ref(C,-1),L);
TR = TH-TL;
TRa= Wilders(TR,per);
UpperBand3 =MA( C, per) + ( 4.2360 * TRa);
UpperBand2=MA( C, per) + ( 2.6180 * TRa);
UpperBand1=MA( C, per) + ( 1.6180 * TRa);

MidPoint=MA(C, per);

LowerBand1=MA( C, per) - ( 1.6180 * TRa);
LowerBand2=MA( C, per) - ( 2.6180 * TRa);
LowerBand3=MA( C, per) - ( 4.2360 * TRa);


Plot(MidPoint,"",colorGreen,4);
Plot(UpperBand1,"",colorRed,1);
Plot(LowerBand1,"",colorRed,1);
Plot(UpperBand2,"",colorAqua,1);
Plot(LowerBand2,"",colorAqua,1);
Plot(UpperBand3,"",colorYellow,1);
Plot(LowerBand3,"",colorYellow,1);



PlotOHLC(O,H,L,C,"",colorWhite,64);

_SECTION_END();
 
#60
SAMPLE AFL
I am giving two AF code here. Save them in two different Afl files. Then check them at a time. The visual signal is self sufficient.

Here is the Code:

Code 1:
_SECTION_BEGIN("AFL CODE: Debarghya Mukherjee");

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
k=Param("multiplication factor", 1,0.5,5,0.1);

period=k*5;
VS_raw = 2.2 * EMA(ATR(1), period);

// for longs, VS line is below price
loline = VS_below_price = HHV(Close, period) - VS_raw;

// for shorts, VS line is above price
hiline = VS_above_price = LLV(Close, period) + VS_raw;
between = IIf (C < hiline AND C > loline, 1, 0);
up = IIf(C > hiline OR (H > Ref(H, -1) AND H > hiline), 1, 0);
dn = IIf(C < loline OR (L < Ref(L, -1) AND L < loline), 1, 0);
upcond = IIf(between AND BarsSince(up) < BarsSince(dn) , 1, 0);
dncond = IIf(between AND BarsSince(dn) < BarsSince(up) , 1, 0);
upline = IIf(up OR upcond, loline, Null);
dnline = IIf(dn OR dncond, hiline, Null);

Buy=upline;
Sell=dnline;

Col = IIf(Buy,colorGreen,IIf(Sell,colorRed,colorBlack));

Plot(C, "", col, styleBar | styleThick );

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorBrightGreen, colorRed ),0, IIf( Buy, Low, High ) );
_SECTION_END();



Code 2:

_SECTION_BEGIN("AFL Example");

r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
ml = MACD(r1, r2);
sl = Signal(r1,r2,r3);
Plot( ml-sl, "MACD Histogram", IIf( ml > sl, colorGreen , colorRed), styleNoTitle | ParamStyle("Histogram style", styleHistogram | styleNoLabel, maskHistogram ) );
_SECTION_END();
 

Similar threads