Portfolio AFL coding help

amitrandive

Well-Known Member
#1
Dear All

I would like to have a simple AFL code for the following condition.

Buy/Cover on Price crossing 12EMA upwards on Daily Charts
Sell/Short on Price crossing 12EMA downwards on Daily Charts


Format of the exploration should be as shown in the below image, for tracking portfolio.



Thanks in advance for all your help.
 
#2
_SECTION_BEGIN("Price");
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("ema_crossover");
x = EMA(Close,12);
y = EMA(Close,12);
Plot(EMA(Close,12),"",colorRed,styleLine);
Plot(EMA(Close,12),"",colorDarkGreen,styleLine);

Buy=C>x;
Short=C<y;
Sell=Short;
Cover=Buy;

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
PlotShapes(Buy*shapeUpArrow, colorGreen, 0, Low,-30);
PlotShapes(Sell*shapeDownArrow, colorPink, 0, High,-30);
PlotShapes(Cover*shapeUpArrow, colorBlue, 0, Low,-30);
PlotShapes(Short*shapeDownArrow, colorRed, 0, High,-30);
_SECTION_END();
Filter=Buy OR Sell;
AddColumn(Buy,"buy",1.2,colorDefault,colorGreen);
AddColumn(Sell,"Sell",1.2,colorDefault,colorRed);
AddColumn(Buy,"buy",1.2,colorDefault,colorGreen);
AddColumn(Sell,"Sell",1.2,colorDefault,colorRed);
 

amitrandive

Well-Known Member
#3
_SECTION_BEGIN("Price");
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("ema_crossover");
x = EMA(Close,12);
y = EMA(Close,12);
Plot(EMA(Close,12),"",colorRed,styleLine);
Plot(EMA(Close,12),"",colorDarkGreen,styleLine);

Buy=C>x;
Short=C<y;
Sell=Short;
Cover=Buy;

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
PlotShapes(Buy*shapeUpArrow, colorGreen, 0, Low,-30);
PlotShapes(Sell*shapeDownArrow, colorPink, 0, High,-30);
PlotShapes(Cover*shapeUpArrow, colorBlue, 0, Low,-30);
PlotShapes(Short*shapeDownArrow, colorRed, 0, High,-30);
_SECTION_END();
Filter=Buy OR Sell;
AddColumn(Buy,"buy",1.2,colorDefault,colorGreen);
AddColumn(Sell,"Sell",1.2,colorDefault,colorRed);
AddColumn(Buy,"buy",1.2,colorDefault,colorGreen);
AddColumn(Sell,"Sell",1.2,colorDefault,colorRed);
autotrade

Thanks for the code.Would be very helpful if you can add the remianing part of the exploration as I have shown in the image.
:clapping:
 

amitrandive

Well-Known Member
#4
Dear All

I would like to have a simple AFL code for the following condition.

Buy/Cover on Price crossing 12EMA upwards on Daily Charts
Sell/Short on Price crossing 12EMA downwards on Daily Charts


Format of the exploration should be as shown in the below image, for tracking portfolio.



Thanks in advance for all your help.
Bumping request
 

casoni

Well-Known Member
#5

mastermind007

Well-Known Member
#7
This sounds more like report that comes out from back testing and it is way too complicated to do it in Explorer.
 

mastermind007

Well-Known Member
#8
#9
_SECTION_BEGIN("Price");
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("ema_crossover");
x = EMA(Close,12);
y = EMA(Close,12);
Plot(EMA(Close,12),"",colorRed,styleLine);
Plot(EMA(Close,12),"",colorDarkGreen,styleLine);

Buy=C>x;
Short=C<y;
Sell=Short;
Cover=Buy;

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
PlotShapes(Buy*shapeUpArrow, colorGreen, 0, Low,-30);
PlotShapes(Sell*shapeDownArrow, colorPink, 0, High,-30);
PlotShapes(Cover*shapeUpArrow, colorBlue, 0, Low,-30);
PlotShapes(Short*shapeDownArrow, colorRed, 0, High,-30);
_SECTION_END();
Filter=Buy OR Sell;
AddColumn(Buy,"buy",1.2,colorDefault,colorGreen);
AddColumn(Sell,"Sell",1.2,colorDefault,colorRed);
AddColumn(Buy,"buy",1.2,colorDefault,colorGreen);
AddColumn(Sell,"Sell",1.2,colorDefault,colorRed);


Why exploration showing 2 times buy- sell??

Can you make it to one time.. Buy - Sell.

Thanx you
 

casoni

Well-Known Member
#10
Why exploration showing 2 times buy- sell??

Can you make it to one time.. Buy - Sell.

Filter=Buy OR Sell;
AddColumn(Buy,"buy",1.2,colorDefault,colorGreen);
AddColumn(Sell,"Sell",1.2,colorDefault,colorRed);
AddColumn(Buy,"buy",1.2,colorDefault,colorGreen);
AddColumn(Sell,"Sell",1.2,colorDefault,colorRed);

Thanx you
Because there are 2 colums for buy-sell , instead there should be

Filter=Buy OR Sell or short or cover;
AddColumn(Buy,"buy",1.2,colorDefault,colorGreen);
AddColumn(Sell,"Sell",1.2,colorDefault,colororange);
AddColumn(short,"short",1.2,colorDefault,colorred);
AddColumn(cover,"cover",1.2,colorDefault,colorpalegreen);
 

Similar threads