Help Needed to create afl

#1
Dear All,

I like to create one AFL in below condition. Can any one help this .

Buy Condition : market cross over EMA then buy when market again go first candle High.

Sell Condition : Market Cross below the EMA then Sell when market again go below first candle low.

Example : If market crossed above the EMA, then assume (after crossover) first candle high is 5000. Then Buy Which candle break first candle high (5000) .

If Market Crossed Below the EMA, then assume (after crossbelow) first candle low is 4990. Then Sell which candle break first candle low (4990) .
 

Abhi1284

Active Member
#4
i m not afl expert but tried to write below if this is right then please continue

_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

a=EMA(C,15);

Buy = Cross(C,a);
Sell= Cross(a,C);
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);

Buyt=ValueWhen(Buy,H,1);
Sellt=ValueWhen(Sell,L,1);
Buytt=Cross(H,Buyt);
selltt=Cross(Sellt,L);
Buytt = ExRem(Buytt, Selltt);
Selltt = ExRem(Selltt, Buytt);

GraphXSpace = 5;
dist = 1*ATR(5);
for( i = 0; i < BarCount; i++ )
{if( Buytt ) PlotText( "Buy Triger", i, L[ i ]-dist, colorSkyblue );
if( Selltt ) PlotText( "Sell Triger", i, H[ i ]+dist,colorGold);
}
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorBrightGreen, 0,L, Offset=-10);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorRed, 0,H, Offset=-10);

PlotShapes(IIf(Buytt, shapeUpTriangle, shapeNone),colorGreen, 0,L, Offset=-10);
PlotShapes(IIf(Selltt, shapeDownTriangle, shapeNone),colorRed, 0,H, Offset=-10);

Abhishek
 
#5
i m not afl expert but tried to write below if this is right then please continue

_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

a=EMA(C,15);

Buy = Cross(C,a);
Sell= Cross(a,C);
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);

Buyt=ValueWhen(Buy,H,1);
Sellt=ValueWhen(Sell,L,1);
Buytt=Cross(H,Buyt);
selltt=Cross(Sellt,L);
Buytt = ExRem(Buytt, Selltt);
Selltt = ExRem(Selltt, Buytt);

GraphXSpace = 5;
dist = 1*ATR(5);
for( i = 0; i < BarCount; i++ )
{if( Buytt ) PlotText( "Buy Triger", i, L[ i ]-dist, colorSkyblue );
if( Selltt ) PlotText( "Sell Triger", i, H[ i ]+dist,colorGold);
}
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorBrightGreen, 0,L, Offset=-10);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorRed, 0,H, Offset=-10);

PlotShapes(IIf(Buytt, shapeUpTriangle, shapeNone),colorGreen, 0,L, Offset=-10);
PlotShapes(IIf(Selltt, shapeDownTriangle, shapeNone),colorRed, 0,H, Offset=-10);

Abhishek



Dear Abhi1284,
Thanks a lot. Thanks for your Help.
 
#8
Dear Abhi1284,
I need some help in a AFL condition plz help me out

Buy When = Buy + (Buy Price x 0.001% of Buy Price)
Sell When = Sell - (Sell Price x 0.001% of Sell Price)

In Simple EMA AFL

_SECTION_BEGIN("Sample_EMA");
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() );


FastEMAPeriod = Param("FastEMAPeriod",5,1,100,1);
SlowEMAPeriod =Param("SlowEMAPeriod",13,1,100,1);

EMA1= EMA(C,FastEMAPeriod);
EMA2= EMA(C,SlowEMAPeriod);

Plot( EMA( C, FastEMAPeriod ), "EMA Fast", colorRed, styleLine | styleNoRescale );


Plot( EMA( C, SlowEMAPeriod ), "EMA Slow", colorBlue, styleLine | styleNoRescale );

Buy = Ref(Cross(EMA1,EMA2),-1); //Cross(EMA1,EMA2) ;

Sell= Ref(Cross(EMA2,EMA1),-1) ;
Buy = ExRem( Buy, Sell);
Sell= ExRem(Sell,Buy);

Short = Ref(Cross(EMA2,EMA1),-1);
Cover = Ref(Cross(EMA1,EMA2),-1);


Short=ExRem(Short,Cover);
Cover= ExRem(Cover,Short);
BuyPrice=SellPrice=ShortPrice=CoverPrice=O;

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorRed, 0,H, Offset=-45);

PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
PlotShapes(IIf(Cover, shapeUpArrow, shapeNone),colorBlue, 0,L, Offset=-45);
_SECTION_END();
 

extremist

Well-Known Member
#9
Dear Abhi1284,
I need some help in a AFL condition plz help me out

Buy When = Buy + (Buy Price x 0.001% of Buy Price)
Sell When = Sell - (Sell Price x 0.001% of Sell Price)

In Simple EMA AFL

_SECTION_BEGIN("Sample_EMA");
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() );


FastEMAPeriod = Param("FastEMAPeriod",5,1,100,1);
SlowEMAPeriod =Param("SlowEMAPeriod",13,1,100,1);

EMA1= EMA(C,FastEMAPeriod);
EMA2= EMA(C,SlowEMAPeriod);

Plot( EMA( C, FastEMAPeriod ), "EMA Fast", colorRed, styleLine | styleNoRescale );


Plot( EMA( C, SlowEMAPeriod ), "EMA Slow", colorBlue, styleLine | styleNoRescale );

Buy = Ref(Cross(EMA1,EMA2),-1); //Cross(EMA1,EMA2) ;

Sell= Ref(Cross(EMA2,EMA1),-1) ;
Buy = ExRem( Buy, Sell);
Sell= ExRem(Sell,Buy);

Short = Ref(Cross(EMA2,EMA1),-1);
Cover = Ref(Cross(EMA1,EMA2),-1);


Short=ExRem(Short,Cover);
Cover= ExRem(Cover,Short);
BuyPrice=SellPrice=ShortPrice=CoverPrice=O;

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorRed, 0,H, Offset=-45);

PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
PlotShapes(IIf(Cover, shapeUpArrow, shapeNone),colorBlue, 0,L, Offset=-45);
_SECTION_END();
U try the following lines.

Buyo=Buy+(valuewhen(buy,c)*0.00001);
Sello=Sell-(valuewhen(Sell,c)*0.00001);

I hope this will solve ur purpose.
 

Similar threads