Afl code world famous tony crabels formula for intraday

jsb2012

Active Member
#1
Hi friends presenting here afl with risk reward ratio of 1:3 go short @ resistance with SL of 7 points (for nifty) and change ur position abv sl and vice-versa @ support approx risk reward is 7:21 Trade at your own risk! All the best! Thanks to my friend P.Sivakumar for helping me write this code! levels will display after 9.29am.(Also i have added ATP and Instantaneous trendline for better judgement)
The afl Code:
dh1=TimeFrameGetPrice("h",inDaily,-1)-TimeFrameGetPrice("O",inDaily,-1);
dh2=TimeFrameGetPrice("h",inDaily,-2)-TimeFrameGetPrice("O",inDaily,-2);
dh3=TimeFrameGetPrice("h",inDaily,-3)-TimeFrameGetPrice("O",inDaily,-3);
dh4=TimeFrameGetPrice("h",inDaily,-4)-TimeFrameGetPrice("O",inDaily,-4);
dh5=TimeFrameGetPrice("h",inDaily,-5)-TimeFrameGetPrice("O",inDaily,-5);
dh6=TimeFrameGetPrice("h",inDaily,-6)-TimeFrameGetPrice("O",inDaily,-6);
dh7=TimeFrameGetPrice("h",inDaily,-7)-TimeFrameGetPrice("O",inDaily,-7);
dh8=TimeFrameGetPrice("h",inDaily,-8)-TimeFrameGetPrice("O",inDaily,-8);
dh9=TimeFrameGetPrice("h",inDaily,-9)-TimeFrameGetPrice("O",inDaily,-9);
dh10=TimeFrameGetPrice("h",inDaily,-10)-TimeFrameGetPrice("c",inDaily,-10);
dl1=TimeFrameGetPrice("O",inDaily,-1)-TimeFrameGetPrice("l",inDaily,-1);
dl2=TimeFrameGetPrice("O",inDaily,-2)-TimeFrameGetPrice("l",inDaily,-2);
dl3=TimeFrameGetPrice("O",inDaily,-3)-TimeFrameGetPrice("l",inDaily,-3);
dl4=TimeFrameGetPrice("O",inDaily,-4)-TimeFrameGetPrice("l",inDaily,-4);
dl5=TimeFrameGetPrice("O",inDaily,-5)-TimeFrameGetPrice("l",inDaily,-5);
dl6=TimeFrameGetPrice("O",inDaily,-6)-TimeFrameGetPrice("l",inDaily,-6);
dl7=TimeFrameGetPrice("O",inDaily,-7)-TimeFrameGetPrice("l",inDaily,-7);
dl8=TimeFrameGetPrice("O",inDaily,-8)-TimeFrameGetPrice("l",inDaily,-8);
dl9=TimeFrameGetPrice("O",inDaily,-9)-TimeFrameGetPrice("l",inDaily,-9);
dl10=TimeFrameGetPrice("O",inDaily,-10)-TimeFrameGetPrice("l",inDaily,-10);

d1=Min(dh1,dl1);
d2=Min(dh2,dl2);
d3=Min(dh3,dl3);
d4=Min(dh4,dl4);
d5=Min(dh5,dl5);
d6=Min(dh6,dl6);
d7=Min(dh7,dl7);
d8=Min(dh8,dl8);
d9=Min(dh9,dl9);
d10=Min(dh10,dl10);

m=(D1+D2+D3+D4+D5+D6+D7+D8+D9+D10)/10;



p=(ValueWhen(TimeNum()==092900,C));

pp=P+m;
Plot(pp,"",5,5);

pt=P-m;

Plot(pt,"",4,5);

_SECTION_BEGIN("Price1");
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", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("Instantaneous Trendline");
// Instantaneous Trendline
Price = (H+L)/2;
Length = Param("Length", 20, 2, 100, 1 );
SMA = MA( Price, Length );
Slope = Price - Ref( Price, - ( Length - 1 ) );
SmoothSlope = ( Slope + 2 * Ref( Slope, -1 )
+ 2 * Ref( Slope, -2 ) + Ref( Slope, -3 ) )/6;
ITrend = SMA + 0.5 * SmoothSlope;
// Cyclic Component
alpha = 0;
HP = 0;
SmoothHP = 0;
PI = 3.1415926;
alpha = ( 1 - sin( 2 * PI / Length ) )/cos( 2 * PI / Length );
HP = AMA2( Price - Ref( Price, -1 ), 0.5 * ( 1 + alpha ), alpha );
SmoothHP = ( HP + 2 * Ref( HP, -1 )
+ 2 * Ref( HP, -2 ) + Ref( HP, -3 ) ) / 6;
Plot( Price, "Price", colorBlack, styleCandle );
// components of model
// Plot( ITrend, "ITrend", colorRed );
// Plot( SmoothHP, "SmoothHP", colorRed );
Model = ITrend + SmoothHP;
Plot( Model, "Model", colorRed );
_SECTION_END();

_SECTION_BEGIN("ATP");
Atp=ParamToggle("ATP","Off|On",1);
if(Atp==1)
{


DayChange = Day() != Ref(Day(), -1);
AvgTradePrice = Null;
CurDayBars = 0;
CurDayCloseSum = 0;

for (i = 0; i < BarCount; i++)
{
if (DayChange)
{
CurDayCloseSum = C;
CurDayBars = 1;
}
else
{
CurDayCloseSum = CurDayCloseSum + C;
CurDayBars++;
}
AvgTradePrice = CurDayCloseSum / CurDayBars;
}
Plot(AvgTradePrice, "AvgTradePrice",colorBlue,styleThick);
ATP=AvgTradePrice;

_SECTION_END();}
 
#9
Hi friends presenting here afl with risk reward ratio of 1:3 go short @ resistance with SL of 7 points (for nifty) and change ur position abv sl and vice-versa @ support approx risk reward is 7:21 Trade at your own risk! All the best! Thanks to my friend P.Sivakumar for helping me write this code! levels will display after 9.29am.(Also i have added ATP and Instantaneous trendline for better judgement)
The afl Code:
dh1=TimeFrameGetPrice("h",inDaily,-1)-TimeFrameGetPrice("O",inDaily,-1);
dh2=TimeFrameGetPrice("h",inDaily,-2)-TimeFrameGetPrice("O",inDaily,-2);
dh3=TimeFrameGetPrice("h",inDaily,-3)-TimeFrameGetPrice("O",inDaily,-3);
dh4=TimeFrameGetPrice("h",inDaily,-4)-TimeFrameGetPrice("O",inDaily,-4);
dh5=TimeFrameGetPrice("h",inDaily,-5)-TimeFrameGetPrice("O",inDaily,-5);
dh6=TimeFrameGetPrice("h",inDaily,-6)-TimeFrameGetPrice("O",inDaily,-6);
dh7=TimeFrameGetPrice("h",inDaily,-7)-TimeFrameGetPrice("O",inDaily,-7);
dh8=TimeFrameGetPrice("h",inDaily,-8)-TimeFrameGetPrice("O",inDaily,-8);
dh9=TimeFrameGetPrice("h",inDaily,-9)-TimeFrameGetPrice("O",inDaily,-9);
dh10=TimeFrameGetPrice("h",inDaily,-10)-TimeFrameGetPrice("c",inDaily,-10);
dl1=TimeFrameGetPrice("O",inDaily,-1)-TimeFrameGetPrice("l",inDaily,-1);
dl2=TimeFrameGetPrice("O",inDaily,-2)-TimeFrameGetPrice("l",inDaily,-2);
dl3=TimeFrameGetPrice("O",inDaily,-3)-TimeFrameGetPrice("l",inDaily,-3);
dl4=TimeFrameGetPrice("O",inDaily,-4)-TimeFrameGetPrice("l",inDaily,-4);
dl5=TimeFrameGetPrice("O",inDaily,-5)-TimeFrameGetPrice("l",inDaily,-5);
dl6=TimeFrameGetPrice("O",inDaily,-6)-TimeFrameGetPrice("l",inDaily,-6);
dl7=TimeFrameGetPrice("O",inDaily,-7)-TimeFrameGetPrice("l",inDaily,-7);
dl8=TimeFrameGetPrice("O",inDaily,-8)-TimeFrameGetPrice("l",inDaily,-8);
dl9=TimeFrameGetPrice("O",inDaily,-9)-TimeFrameGetPrice("l",inDaily,-9);
dl10=TimeFrameGetPrice("O",inDaily,-10)-TimeFrameGetPrice("l",inDaily,-10);

d1=Min(dh1,dl1);
d2=Min(dh2,dl2);
d3=Min(dh3,dl3);
d4=Min(dh4,dl4);
d5=Min(dh5,dl5);
d6=Min(dh6,dl6);
d7=Min(dh7,dl7);
d8=Min(dh8,dl8);
d9=Min(dh9,dl9);
d10=Min(dh10,dl10);

m=(D1+D2+D3+D4+D5+D6+D7+D8+D9+D10)/10;



p=(ValueWhen(TimeNum()==092900,C));

pp=P+m;
Plot(pp,"",5,5);

pt=P-m;

Plot(pt,"",4,5);

_SECTION_BEGIN("Price1");
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", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("Instantaneous Trendline");
// Instantaneous Trendline
Price = (H+L)/2;
Length = Param("Length", 20, 2, 100, 1 );
SMA = MA( Price, Length );
Slope = Price - Ref( Price, - ( Length - 1 ) );
SmoothSlope = ( Slope + 2 * Ref( Slope, -1 )
+ 2 * Ref( Slope, -2 ) + Ref( Slope, -3 ) )/6;
ITrend = SMA + 0.5 * SmoothSlope;
// Cyclic Component
alpha = 0;
HP = 0;
SmoothHP = 0;
PI = 3.1415926;
alpha = ( 1 - sin( 2 * PI / Length ) )/cos( 2 * PI / Length );
HP = AMA2( Price - Ref( Price, -1 ), 0.5 * ( 1 + alpha ), alpha );
SmoothHP = ( HP + 2 * Ref( HP, -1 )
+ 2 * Ref( HP, -2 ) + Ref( HP, -3 ) ) / 6;
Plot( Price, "Price", colorBlack, styleCandle );
// components of model
// Plot( ITrend, "ITrend", colorRed );
// Plot( SmoothHP, "SmoothHP", colorRed );
Model = ITrend + SmoothHP;
Plot( Model, "Model", colorRed );
_SECTION_END();

_SECTION_BEGIN("ATP");
Atp=ParamToggle("ATP","Off|On",1);
if(Atp==1)
{


DayChange = Day() != Ref(Day(), -1);
AvgTradePrice = Null;
CurDayBars = 0;
CurDayCloseSum = 0;

for (i = 0; i < BarCount; i++)
{
if (DayChange)
{
CurDayCloseSum = C;
CurDayBars = 1;
}
else
{
CurDayCloseSum = CurDayCloseSum + C;
CurDayBars++;
}
AvgTradePrice = CurDayCloseSum / CurDayBars;
}
Plot(AvgTradePrice, "AvgTradePrice",colorBlue,styleThick);
ATP=AvgTradePrice;

_SECTION_END();}


This AFL is not working Dude..:(
 

Similar threads