Simple Coding Help - No Promise.

KelvinHand

Well-Known Member
Hi all,

I'm trying to export the exploration results to text file. I found something on this topic. The following code is trying to export results to a text file; but the output file is blank. I would really appreciate if any AFL expert can fix this.

// create folder for exporting purposes
fmkdir( "C:\\DataExport\\" );

// open file for writing
fh = fopen( "c:\\DataExport\\explore.txt", "w" );

if( fh )
{
// sample exploration code
Filter = ROC( Close, 1 ) > 3 AND Volume > 1000000;

if ( LastValue( Cum( Filter ))) //check if filter has contents
fputs( "", fh ); // write ticker name

fclose( fh ); //close file
}
Code:
// create folder for exporting purposes
fmkdir( "C:\\DataExport\\" );

// open file for writing
fh = fopen( "c:\\DataExport\\explore.txt", "w" );

if( fh )
{
// sample exploration code
Filter = ROC( Close, 1 ) > 3 AND Volume > 1000000;

if ( LastValue( Cum( Filter ))) //check if filter has contents
fputs( Name(), fh ); // write ticker name

fclose( fh ); //close file
}
 
Last edited:
Hi,

I'm new to AFL coding and have been trying to code some basic strategies. Could somebody help me with one issue? Below is a section of the code:

Buy1 = C > Buyband;
Sell1 = (C < Sellband);
ApplyStop(stopTypeLoss, stopModePercent, 11, ExitAtStop = 0, True, 0);
Buy = ExRem(Buy1, Sell1);
Sell = ExRem(Sell1, Buy1);

The Buyband and Sellband are Bbands. When I backtest, although the ApplyStop function does give me an exit it does not give me re-entry again unless and until the Sell is triggered. The re-entry bars have been set to 0 but the issue still persists.

Will really appreciate the support.

Many thanks.
 

KelvinHand

Well-Known Member
Correct - You stated Output Blank so i fixed it, the AFL you provided stated that:

if ( LastValue( Cum( Filter ))) //check if filter has contents
fputs( Name(), fh ); // write ticker name

Actual you can export to external file after you exploration it through
<File>-><Export To Html/CSV> menu item.


Hello KelvinHand, I tried fputs( Name(), fh );
but it writes only the last stock in the exploration result.
The following code append the symbol rather that write the last symbol.
But the problem is it keep appending to the old data, you need to delete yourself.


PHP:
// create folder for exporting purposes

path = "C:\\DataExport\\";
fmkdir( path);


// open file for writing

fh = fopen( path+"explore.txt", "a" );


// sample exploration code
Filter = ROC( Close, 1 ) > 3 AND Volume > 1000000;

if (fh)
{
 
	if ( LastValue(Filter))
	{
		fputs( Name()+"\n", fh ); // write ticker name
	}
	fclose( fh ); //close file

}
 
Last edited:

bpr

Well-Known Member
Buy above previous High

PHP:
Buy = H > REF(HIGH,-1);
if my understanding is correct this means the current candle will close and then if the High is > previous high then the condition will satisfy and the trade will be triggered.

What if I want the trade to be triggered as soon as the High of the current candle crosses the previous high and not wait for the candle close.

Can somebody help me with this.
 
-- GetBaseIndex() but for SECTOR INDEX --

Someone that can help me to extract "Sector Index Data" from a given stock related to it's Industry() Sector() for analysis purposes...?

I use TC2k v7 service, so I want to use the Hemscott (old) Morningstar Industry Indexes that are already given by the -MG123- nomenclature in witch WHEN THE LAST NUMBER IS A "0", it represent's the Index of the Sector for the given Industry.

I know that with proper configuration on the Symbol -> Categories window, we can assign each INDUSTRY Index witch can be retrieved with the GetBaseIndex() function for studies as long as I know, but for the Sector one I don't know how to do it.

So, How can I get programatically from AFL not only the Industry Index by the given function, but as well the Sector one for the given stock ...?

I have read on forums and other AFL's that a way to do this all manually has something to do with "for" loops using CategoryGetSymbols() function as well with StrExtract() but don't know if this way could be the more "simpler-cleaner-fastest"...

Can someone help me with this AFL logic construction..?

Cheers!
 
Buy above previous High

PHP:
Buy = H > REF(HIGH,-1);
if my understanding is correct this means the current candle will close and then if the High is > previous high then the condition will satisfy and the trade will be triggered.

What if I want the trade to be triggered as soon as the High of the current candle crosses the previous high and not wait for the candle close.

Can somebody help me with this.
No! The code as written will not wait for candle close. However, your data feed provider may have a code that introduces delay and wait for a candle close before streaming data down into your amibroker instance.

However the real worry is not the candle close. How will you avoid all the previous fake calls?
 

bpr

Well-Known Member
No! The code as written will not wait for candle close. However, your data feed provider may have a code that introduces delay and wait for a candle close before streaming data down into your amibroker instance.

However the real worry is not the candle close. How will you avoid all the previous fake calls?
so in AFL H, L, O, C represent the last instantaneous value of the Current candle ?
 

arora

Well-Known Member
can somebody please explain me in english, In This Code(mentioned below) what conditions writer is using to make entry and exit, please help on what conditions writer has designed to make entry and exit.

_SECTION_BEGIN("Price");

SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));
GfxSetBkMode(0);
GfxSetOverlayMode(1);
//SetTradeDelays(1,1,1,1);
SetPositionSize(100,spsShares);

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

_SECTION_END();
NHours=Param("Number of Hours",30,1,50,1);
HoursC=TimeFrameGetPrice("O",inHourly,0);
NHoursDHLAvg=0;
for(i=1;i<=NHours;i++)
{
HourH=TimeFrameGetPrice("H",inHourly,-i);
HourL=TimeFrameGetPrice("L",inHourly,-i);
NHoursDHLAvg=NHoursDHLAvg+(HourH-HourL);
}
NHoursDHLAvg=NHoursDHLAvg/NHours;

TenDHLAvg= NHoursDHLAvg;

Buy= C>((HoursC)+((0.618)*(TenDHLAvg)));
Sell= C<((HoursC)-((0.618)*(TenDHLAvg)));

Cover= C>((HoursC)+((0.382)*(TenDHLAvg)));
Short= C<((HoursC)-((0.382)*(TenDHLAvg)));

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

BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorDarkRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorDarkRed, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorDarkRed, 0,H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorDarkRed, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
PlotShapes(IIf(Cover, shapeUpArrow, shapeNone),colorGreen, 0,L, Offset=-40);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorGreen, 0,L, Offset=-50);
PlotShapes(IIf(Cover, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
SetPositionSize(300,spsShares);

ApplyStop(0,1,10,1);
//-----------end--------------
Long=Flip(Buy,Short);
Shrt=Flip(Sell,Cover);

Edc=(
WriteIf (Buy , " BUY at "+C+" ","")+
WriteIf (Sell, " SEll at "+C+" ","")+
WriteIf (Cover , " Sell Stop at "+C+" ","")+
WriteIf (Short , " Buy Stop at "+C+" ","")
);
_SECTION_END();

BarColors =
IIf(BarsSince(Buy) < BarsSince(Short)
AND BarsSince(Buy)!=0, colorGreen,
IIf(BarsSince(Sell) < BarsSince(Cover)
AND BarsSince(Sell)!=0, colorRed, colorWhite));

//Plot the Candlestick charts
Plot(C, "Close", BarColors, styleNoTitle | ParamStyle("Style") | GetPriceStyle() ) ;

for( i = 0; i < BarCount; i++ )
{
//if( Buy ) PlotText( "BUY@" + C[ i ], i, C[ i ], colorWhite, colorBlue );
//if( Sell ) PlotText( "SELL@" + C[ i ], i, C[ i ], colorWhite, colorViolet );
// if( Cover ) PlotText( "Sell Stop@" + C[ i ]+ "\nSell Profit= " + ((SellPrice-CoverPrice)), i, L[ i ]-3, colorLightGrey, colorBlack );
//if( Short ) PlotText( "BuyStop@" + C[ i ]+ "\nBuy Profit= " + ((ShortPrice-BuyPrice)), i, H[ i ]+3, colorLightGrey, colorBlack );

}

_SECTION_BEGIN("Background text");
C11=ParamColor("up panel",colorBlack );
C12=ParamColor("dn panel",colorBlack );
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",12,1,20,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
GfxSetBkMode( 0 );
GfxSetOverlayMode(1);
GfxGradientRect(0,0,pxwidth, pxheight, C11, C12 );
GfxSelectFont("Tahoma", Status("pxheight")/C13 );
GfxSetTextColor(colorBrown);
GfxSetTextAlign( 6 );
//GfxTextOut( "LTP "+WriteVal(C,1.2), Status("pxwidth")/C14, Status("pxheight")/C15);
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor(colorBrown);
GfxSelectFont("Tahoma", 20, 800, False, False, 0);
GfxSetTextColor(colorYellow);
GfxTextOut(""+edc+"", Status("pxwidth")/1.15, Status("pxheight")/C15*0.3 );



please help........


just explain entry and exit conditions in english , request
 

Similar threads