How to add Fundamental data from CVS ?, I have afl sample, but must use their plugin. I have prepared the fundamental data in CVS.
This is the example of AFL
ty_SECTION_BEGIN("FA EPS Qtr");
AflTitle = "FA EPS - QTR Trend";
countDrawBar = 8; //6
plPeriodType = "Quarterly";
period = Hor= 2;
plFinancial = ParamList("Financials","EPS",0);
QIFA = QIsnFAHistory(plFinancial,plPeriodType,period);
if( Status("action") == actionExplore || IsIndex() || Nz(QIsnFA("EPS"),0) == 0)
titleheader = "" ;
else
titleheader = QIsnFA("Asofdate")+" "+Name()+ " - "+ plFinancial ;
PriceScale = 1;
plScale = ParamList("Amount (Rp.) ","In Million",0);
ShowGridLine = ParamToggle("Show Grid ?","Yes|No",0);
FinQtr = 0;
QtrBar = 8; //5
LastQIFA = 0 ;
for( i = 0; i < BarCount; i++ )
{
iBar=BarCount-(i+1);
if( ( QIFA[ iBar ] / PriceScale ) != LastQIFA )
{
FinQtr = QIFA[ iBar ] / PriceScale ;
VarSet("FinQtr" + QtrBar, FinQtr );
LastQIFA = FinQtr ;
QtrBar--;
if(QtrBar<1) break;
}
}
GfxSetOverlayMode( 2 );
CellHeight = (Status("pxheight")-1)/3;
CellWidth = (Status("pxwidth")-1)/3;//14;
CellQtrWidth = (Status("pxwidth")-1)/(4+1);
GfxSelectFont( "Arial Bold", 8.5 );
GfxSelectSolidBrush( colorWhite);
GfxRectangle( 0, 0, Status("pxwidth"), Status("pxheight"));
GfxSetBkMode( 1 );
GfxSelectSolidBrush( colorBlack );
YOffset = 25;
XOffset = 15;
function PrintQtrInCell( string, row, Col )
{
Color = ColorRGB( IIf( row == 0 || col == 0 || col == 13, 220, 255 ), 255, IIf( row % 2, 255, 220 ) );
GfxSelectSolidBrush( Color );
GfxSetTextColor( colorBlue );
GfxDrawText( string, Col * CellQtrWidth + 1 + CellWidth, row * CellHeight + 1, CellWidth + (Col + 1 ) * CellQtrWidth, (row + 1 ) * CellHeight, 32+5 ); //32+5
}
function DrawBar( text, bar, numbars, y, Miny, Maxy )
{
BarWidth = (Status("pxwidth") - 4 * XOffset )/( numbars + 1 );
BarHeight = Status("pxheight") - 2 * YOffset;
relpos = ( y - Miny ) / (Maxy - Miny );
xp = XOffset + ( bar + 0.5 ) * BarWidth;
yp = YOffset + BarHeight * ( 1 - relpos );
xe = XOffset + ( bar + 1 ) * BarWidth;
ye = YOffset + BarHeight * ( 1 - ( -miny )/( maxy - miny ) );
if( y > 0 )
{
GfxGradientRect( xp, yp, xe , ye, colorPaleGreen, colorDarkTeal );
GfxSetTextColor( colorDarkTeal );
GfxTextOut( text, xp, ye ); //Annually or Quarterly
GfxSelectPen( colorBrightGreen, 1, 2 );
GfxTextOut( StrFormat("%.0f", y ), xp, yp );
}
else
{
GfxGradientRect( xp, ye, xe , yp, colorRose, colorDarkRed );
GfxTextOut( text, xp, ye ); //Annually or Quarterly
GfxTextOut( StrFormat("%.2f", y ), xp, yp );
}
}
function DrawLevels( Miny, Maxy )
{
range = Maxy - Miny;
grid = 100;
if( range < 10 ) grid = 1;
else
if( range < 20 ) grid = 2;
else
if( range < 50 ) grid = 5;
else
if( range < 100 ) grid = 10;
else
if( range < 200 ) grid = 20;
else
if( range < 500 ) grid = 50;
else
if( range < 1000 ) grid = 100;
else
if( range < 5000 ) grid = 500;
else
if( range < 10000 ) grid = 1000;
else
if( range < 30000 ) grid = 3000;
else
if( range < 50000 ) grid = 5000;
else
if( range < 100000 ) grid = 10000;
else
if( range < 1000000 ) grid = 100000;
else
if( range < 5000000 ) grid = 500000;
_TRACE("grid = "+grid +" range "+range );
width = Status("pxwidth") - 4 * XOffset;
height = Status("pxheight") - 2 * YOffset;
GfxSelectPen( colorBlack, 1, 2 );
for( y = grid * ceil( Miny / grid ); y <= grid * floor( Maxy / grid ); y += grid )
{
yp = YOffset + Height * ( 1 - ( y - Miny ) / (Maxy - Miny ) );
GfxMoveTo( XOffset, yp );
if(ShowGridLine==1) GfxLineTo( XOffset + width , yp );
GfxTextOut( " "+ y, XOffset + 2 + width, yp );
}
GfxSelectPen( colorBlack, 1, 0 );
GfxMoveTo( XOffset, YOffset );
GfxLineTo( XOffset + width, YOffset );
GfxLineTo( XOffset + width, YOffset + Height );
GfxLineTo( XOffset , YOffset + Height );
GfxLineTo( XOffset , YOffset );
}
function DisplayQuarterTrend()
{
Bar = 0;
MinAvgProf = MaxAvgProf = 0;
for( m = QtrBar+1; m <= countDrawBar; m++ )
{
FinQtr = VarGet("FinQtr" + m );
MinAvgProf = Min( MinAvgProf, FinQtr );
MaxAvgProf = Max( MaxAvgProf, FinQtr );
}
for( m = QtrBar+1; m <= countDrawBar; m++ )
{
FinQtr = VarGet("FinQtr" + m ) ;
DrawBar( QIsnMRQ("AsOfDate",(countDrawBar-m)*-1), Bar++, countDrawBar, FinQtr, MinAvgProf , MaxAvgProf );
}
TitleWidth = (Status("pxwidth")-1)/2;
GfxSetTextColor( colorBrown );
GfxSelectFont( "Cooper Black", 12 );
GfxTextOut(AflTitle, 15, 3 );
GfxSetTextColor( colorBlack );
GfxTextOut(titleheader, 15+TitleWidth, 3 );
GfxSelectFont( "Arial", 9 );
GfxSetTextColor( colorBlack );
if( plFinancial == "EPS" )
{
mQtrEarningGrowth = QIsnFA("QEG");
mYoyEarningGrowth = QIsnFA("YOYEG");
}
if( plFinancial =="RevenuePerShare" )
{
mQtrRevenueGrowth = QIsnFA("QRG");
mYoyRevenueGrowth = QIsnFA("YOYRG");
if(!IsNull(mQtrRevenueGrowth)) GfxTextOut( "MRQ vs Qtr.1Yr.Ago = "+StrFormat("%.2f",mQtrRevenueGrowth)+"%", 15+(TitleWidth*2), 5 );
if(!IsNull(mYoyRevenueGrowth)) GfxTextOut( "TTM vs TTM 1Yr.Ago = "+StrFormat("%.2f",mYoyRevenueGrowth)+"%", 15+(TitleWidth*3), 5 );
}
DrawLevels( MinAvgProf , MaxAvgProf );
}
/* Main program */
if(!IsIndex() && Nz(QIsnFA("EPS"),0) != 0)
{DisplayQuarterTrend();}
else{
GfxSelectFont("Tahoma", 10, 100);
GfxSetTextColor(colorYellow);
GfxTextOut("Symbol: "+Name(), 5, 5 );
GfxTextOut("QIFA - Quarterly Trend: N/A", 5, 25 );
GfxSetTextColor(colorBlack);
GfxSelectFont("Verdana", 8, 100);
}
_SECTION_END();
pe or paste code here
I've tried many times, but can only display 1 bar. There cannot be many data bars from CVS. Thanks
This is the example of AFL
//Pray and need help...
_SECTION_BEGIN("histogram eps 1");
fh = fopen("C:\\Program Files\\AmiBroker\\Fundamenta.csv", "r");
_eps1 = 0;
if (fh) {
while(!feof(fh)) {
line = fgets(fh);
code = StrExtract(line, 0, separator = ';');
_TRACE("code => " + code);
if (code == Name()) {
_eps1 = StrExtract(line, 29, separator = ';');
break;
}
}
fclose( fh );
}
else {
Error("Error opening file");
}
/*
end bar 1
*/
YOffset = 25;
XOffset = 15;
function DrawBar(text, bar, numbars, y, minEps, maxEps) {
BarWidth = (Status("pxwidth") - 4 * XOffset) / (numbars + 1);
BarHeight = Status("pxheight") - 2 * YOffset;
relpos = (y - minEps) / (maxEps - minEps);
xp = XOffset + (bar + 0.5) * BarWidth;
yp = YOffset + BarHeight * (1 - relpos);
xe = XOffset + (bar + 1) * BarWidth;
ye = YOffset + BarHeight * (1 - (-minEps) / (maxEps - minEps));
if(y > 0) GfxGradientRect(xp, yp, xe, ye, colorPaleGreen, ColorRGB(56, 131, 88));
else GfxGradientRect(xp, ye, xe, yp, colorRose, colorRed);
GfxTextOut(text, xp + 40, ye + 5);
GfxTextOut(StrFormat("%.2f", y ), xp + 40, yp - 20);
}
function DrawLevels(minEps, maxEps) {
range = maxEps - minEps;
grid = 100;
if(range < 10) grid = 1;
else
if(range < 20) grid = 2;
else
if(range < 50) grid = 5;
else
if(range < 100) grid = 10;
else
if(range < 200) grid = 20;
else
if(range < 500) grid = 50;
else
if(range < 1000) grid = 100;
else
if(range < 5000) grid = 500;
else
if(range < 10000) grid = 1000;
else
if(range < 30000) grid = 3000;
else
if(range < 50000) grid = 5000;
else
if(range < 100000) grid = 10000;
else
if(range < 1000000) grid = 100000;
else
if(range < 5000000) grid = 500000;
width = Status("pxwidth") - 4 * XOffset;
height = Status("pxheight") - 2 * YOffset;
GfxSelectPen(colorBlack, 1, 2);
for(y = grid * ceil(minEps / grid); y <= grid * floor(maxEps / grid); y += grid) {
yp = YOffset + Height * (1 - (y - minEps) / (maxEps - minEps));
GfxMoveTo(XOffset, yp);
GfxTextOut(" "+ y, XOffset + 2 + width, yp);
}
GfxSelectPen(colorBlack, 1, 0);
GfxMoveTo(XOffset, YOffset);
GfxLineTo(XOffset + width, YOffset);
GfxLineTo(XOffset + width, YOffset + Height);
GfxLineTo(XOffset, YOffset + Height);
GfxLineTo(XOffset, YOffset);
}
maxbar = 1;
x = "Jan";
y[0] = StrToNum(_eps1);
bar = 0;
minEps = 0;
maxEps = 0;
for(i = 0; i < maxbar; i++) {
minEps = Min(minEps, y[i]);
maxEps = Max(maxEps, y[i]);
}
for(i = 0; i < maxbar; i++) {
DrawBar(StrExtract(x, i), bar++, 4, y[i], minEps , maxEps);
}
TitleWidth = (Status("pxwidth") - 1) / 2;
GfxSelectFont("Cooper Black", 11);
GfxTextOut("Title Header", 15 + TitleWidth, -4);
GfxSelectFont("Arial", 9);
GfxSetTextColor(colorBlack);
DrawLevels(minEps, maxEps);
_SECTION_END();
/*
_SECTION_BEGIN("histogram eps 2");
_eps2 = 1;
if (fh) {
while(!feof(fh)) {
line = fgets(fh);
code = StrExtract(line, 0, separator = ';');
_TRACE("code => " + code);
if (code == Name()) {
_eps2 = StrExtract(line, 29, separator = ';');
break;
}
}
fclose( fh );
}
else {
Error("Error opening file");
}
YOffset = 25;
XOffset = 15;
function DrawBar(text, bar, numbars, y, minEps, maxEps) {
BarWidth = (Status("pxwidth") - 4 * XOffset) / (numbars + 1);
BarHeight = Status("pxheight") - 2 * YOffset;
relpos = (y - minEps) / (maxEps - minEps);
xp = XOffset + (bar + 0.5) * BarWidth;
yp = YOffset + BarHeight * (1 - relpos);
xe = XOffset + (bar + 1) * BarWidth;
ye = YOffset + BarHeight * (1 - (-minEps) / (maxEps - minEps));
if(y > 0) GfxGradientRect(xp, yp, xe, ye, colorPaleGreen, ColorRGB(56, 131, 88));
else GfxGradientRect(xp, ye, xe, yp, colorRose, colorRed);
GfxTextOut(text, xp + 40, ye + 5);
GfxTextOut(StrFormat("%.2f", y ), xp + 40, yp - 20);
}
function DrawLevels(minEps, maxEps) {
range = maxEps - minEps;
grid = 100;
if(range < 10) grid = 1;
else
if(range < 20) grid = 2;
else
if(range < 50) grid = 5;
else
if(range < 100) grid = 10;
else
if(range < 200) grid = 20;
else
if(range < 500) grid = 50;
else
if(range < 1000) grid = 100;
else
if(range < 5000) grid = 500;
else
if(range < 10000) grid = 1000;
else
if(range < 30000) grid = 3000;
else
if(range < 50000) grid = 5000;
else
if(range < 100000) grid = 10000;
else
if(range < 1000000) grid = 100000;
else
if(range < 5000000) grid = 500000;
width = Status("pxwidth") - 4 * XOffset;
height = Status("pxheight") - 2 * YOffset;
GfxSelectPen(colorBlack, 1, 2);
for(y = grid * ceil(minEps / grid); y <= grid * floor(maxEps / grid); y += grid) {
yp = YOffset + Height * (1 - (y - minEps) / (maxEps - minEps));
GfxMoveTo(XOffset, yp);
GfxTextOut(" "+ y, XOffset + 2 + width, yp);
}
GfxSelectPen(colorBlack, 1, 0);
GfxMoveTo(XOffset, YOffset);
GfxLineTo(XOffset + width, YOffset);
GfxLineTo(XOffset + width, YOffset + Height);
GfxLineTo(XOffset, YOffset + Height);
GfxLineTo(XOffset, YOffset);
}
maxbar = 1;
x = "Jan";
y[0] = StrToNum(_eps1);
bar = 0;
minEps = 0;
maxEps = 0;
for(i = 0; i < maxbar; i++) {
minEps = Min(minEps, y[i]);
maxEps = Max(maxEps, y[i]);
}
for(i = 0; i < maxbar; i++) {
DrawBar(StrExtract(x, i), bar++, 4, y[i], minEps , maxEps);
}
TitleWidth = (Status("pxwidth") - 1) / 2;
GfxSelectFont("Cooper Black", 11);
GfxTextOut("Title Header", 15 + TitleWidth, -4);
GfxSelectFont("Arial", 9);
GfxSetTextColor(colorBlack);
DrawLevels(minEps, maxEps);
_SECTION_END();type or paste code here
Anyone can give me solution? Thanks