Simple Coding Help - No Promise.

trash

Well-Known Member
I have modifed this code bit to get amibroker data to Ninjatrader format
I getting error in ln42 that 3rd last line
Saying Syntax error,unexpected ')'.Is there senucolon missing at the end of the previous line?

Solved by removing } extra at end :p

Nothing is solved. Do you even understand what you are doing? I'm gonna answer the question... No, you don't.
Why do you add two loops? It makes no sense at all.


Code:
bir = Status( "barinrange" );
lbr = Status( "LastBarInRange" );

if ( Status( "action" ) == actionExplore ) { 
	fh = fopen( "C:\\OHLC" + Name() + ".txt", "a" ); 

	if( fh ) {
		y = Year();
		m = Month();
		d = Day();
		tn = TimeNum();

		for( i = 0; i < BarCount; i++ )	{
			if( bir[i] ) {
				dts = StrFormat( "%02.0f%02.0f%02.0f %06.0f;", y[ i ], m[ i ], d[ i ], tn[ i ] );
				qs = StrFormat( "%.2f;%.2f;%.2f;%.2f;%g\n", O[ i ], H[ i ], L[ i ], C[ i ], V[ i ] );
				fputs( dts + qs, fh );
			}
		}
		fclose( fh );
	}
}

Filter = lbr;

SetOption( "NoDefaultColumns", True );
AddTextColumn( "Export finished", "Status", 1, colorWhite, colorDarkGreen, 90 );
 
Last edited:

Snake.Head

Well-Known Member
Thanks for help and pointing out mistake
I am trial and error learning,
I small change in code that is add \
fopen( "C:\\OHLC"+Name()+".txt", "a");

Instead of fopen( "C:\\OHLC" + Name() + ".txt", "a" );

With above it would affix OHLC to Symbol Name

Nothing is solved. Do you even understand what you are doing? I'm gonna answer the question... No, you don't.
Why do you add two loops? It makes no sense at all.


Code:
bir = Status( "barinrange" );
lbr = Status( "LastBarInRange" );

if ( Status( "action" ) == actionExplore ) { 
	fh = fopen( "C:\\OHLC" + Name() + ".txt", "a" ); 

	if( fh ) {
		y = Year();
		m = Month();
		d = Day();
		tn = TimeNum();

		for( i = 0; i < BarCount; i++ )	{
			if( bir[i] ) {
				dts = StrFormat( "%02.0f%02.0f%02.0f %06.0f;", y[ i ], m[ i ], d[ i ], tn[ i ] );
				qs = StrFormat( "%.2f;%.2f;%.2f;%.2f;%g\n", O[ i ], H[ i ], L[ i ], C[ i ], V[ i ] );
				fputs( dts + qs, fh );
			}
		}
		fclose( fh );
	}
}

Filter = lbr;

SetOption( "NoDefaultColumns", True );
AddTextColumn( "Export finished", "Status", 1, colorWhite, colorDarkGreen, 90 );
 

KelvinHand

Well-Known Member
PHP:
/*
 Kelvinhand: 2015 Oct 7th
  - To export amibroker data to Ninjatrader accepted formats:
    1. Tick:  Each tick must be on its own line and fields must be separated by semicolon.
        => YYYYMNDD hhmmss;price;volume

    2. Minute Bars: Each bar must be on its own line and fields must be separated by semicolon. Only 1 minute bars can be imported.
        => YYYYMNDD hhmmss;Open;High;Low;Close;Volume

    3. Daily Bars: Each bar must be on its own line and fields must be separated by semicolon. Only 1 day bars can be imported.
        => YYYYMNDD;Open;High;Low;Close;Volume

     * Option to generate HTF bars from the imported LTF data, e.g., tick data import can simultaneously generate minute and daily bars and 1 minute data 
        import can simultaneously generate daily bars. 
     * NT maintains separate databases for tick, one minute and daily quotes. So you have to either import these type of data separately or select the options 
        to generate "Minute" bars or "Day" bars while importing LTF data.

  - Modified upon Trash modification.
  - Folder is given on top of the Code, reason is the result may not export to root dir c:/
  - Simplified it & more readable 
  - Show Total count of files exported
  - User Input

*/
Prefix = ParamStr("Prefix","OHLC_");
Folder = ParamStr("Folder","C:/Temp/");
Ext = ParamStr("File Extension", ".txt");
Exported = "";
x = False;
if ( Status( "action" ) == actionExplore ) 
{ 
    exist = fmkdir( folder);  //Create if not folder exist, else return true if exist
    
    
    fh = fopen( Folder+Prefix+Name()+Ext, "a"); 
    if( fh ) 
    { 
        
        yy = Year();    mn = Month();    dd = Day(); 
        hh = Hour();    mm = Minute();    ss=Second();

        // ### For Minute Bar Format Only ###
        for( i = 0; i < BarCount; i++ ) 
        { 
            dt = StrFormat("%02.0f%02.0f%02.0f",  yy[i], mn[i], dd[i]);
            ohlcv= StrFormat(";%.2f;%.2f;%.2f;%.2f;%.0f\n",  O[i],H[i],L[i],C[i],V[i]);
            
            
            /*if (NjFormat=="Minute") */  //-- reserved
              dt  += StrFormat(" %02.0f%02.0f%02.0f",  hh[i],mm[i],ss[i]);
            
            fputs( dt + ohlcv, fh ); 
        }
        fclose( fh ); 
        Exported = Folder+Prefix+Name()+Ext;
        x = true;
    }
    
}

Filter = true;
SetOption( "NoDefaultColumns", True );


AddTextColumn( Exported, "File Exported", 1, colorWhite, colorDarkGreen, 200 ); 
AddColumn(x, "Total", 1.0, colorDarkGreen, colorDarkGreen); 
AddSummaryRows( 16, 1.0 );
 
Last edited:

Rkji

Well-Known Member
Hi

Can anyone write or find similar afl to these below?

First one does not have the afl code & second one applies to chart
but I felt it could be improved. Also it has errors in backtesting.
Looks interesting though as SL & TP is auto calculated.

Trendline Scanner

Trendline Breakout

Trendlines are a traders biggest tool & it does makes lot of sense to develop or find a nice afl for same.

Thanks
 
Hi,

can anyone give me afl which creates csv file of the scan or exploration results.

For eg - if I run scan based on macd crossovers - a csv file should automatically get created of the results
 

trash

Well-Known Member
Hi,

can anyone give me afl which creates csv file of the scan or exploration results.

For eg - if I run scan based on macd crossovers - a csv file should automatically get created of the results
You have to save an analysis to a project file and then run that project file via OLE automation. http://amibrokerforum.proboards.com/thread/57/analysis-project-files-apx?page=1&scrollTo=182

The OLE automation has to run from outside of AB (via .js., vbs, .exe, .py, ...).
However you may run such automation script within an AFL program via ShellExecute function.
I.e.

Code:
if( ParamTrigger( "Run OLE script", "Click here" ) )
	ShellExecute( "NewAA_OLE.js", "", "Scripts", 0 );
 

hmp

Well-Known Member
Hi can somone pl. add exploration feature in the following afl?It gives error while scanning.
Thanks & regards
Code:
 _SECTION_BEGIN("Stupid Functions");

function HAI_F1(no)
{
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
return (IIf(avn==1,sup,res));
}

function HAI_F2(no)
{
return (Cross(C,HAI_F1(no)));
}

function HAI_F3(no)
{
return (Cross(HAI_F1(no),C));
}

function HAI_F4(no)
{
prev=AMA2(C,1,0);
d=IIf(C>Ref(Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),-1),Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))),
IIf(C<Ref(Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))),-1),Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),PREV));
a=Cross(Close,d);
b=Cross(d,Close);
return (IIf(BarsSince(a)<BarsSince(b),1,0));
}

function HAI_F5(no)
{
state = HAI_F4(no);
s=state>Ref(state,-1);
ss=state<Ref(state,-1);
return (state==Ref(state,-1));
}


function HAI_F6(p,n,s,m)
{
return (PDI(p)>MDI(n)AND Signal(s)<MACD(m));
}

function HAI_F7(p,n,s,m)
{
return (MDI(n)>PDI(p)AND Signal(s)>MACD(m));
}


_SECTION_END();


_SECTION_BEGIN("Swing");

no = 22;
sloss = HAI_F1(no);
a = HAI_F2(no);
b = HAI_F3(no);
state = HAI_F4(no);
sss = HAI_F5(no);
uptrend = HAI_F6(20,10,29,22);
downtrend = HAI_F7(20,10,29,13);

style = a * styleStaircase + b * styleStaircase;
PlotShapes(a,style, IIf(a,colorGreen,colorRed), 0, IIf(a,Low,High));
_SECTION_END();

col=IIf(state == 1 ,51,IIf(state ==0,4,1));
Plot(C,"",Col,64);
PlotShapes( shapeUpArrow * a, colorGreen,0,L);
PlotShapes( shapeDownArrow * b, colorRed,0,H);

Filter = a OR b OR sss ;
AddColumn(C,"close",1.2);
AddColumn( IIf( a, 66,1 ), "buy", formatChar, 1, bkcolor =IIf (a,colorYellow, colorPink ));
AddColumn( IIf( b, 83,1 ), "sell", formatChar, 1, bkcolor =IIf (b,colorPink, colorYellow ));
AddColumn( IIf( sss, 87,1 ), "wait", formatChar, 1, bkcolor =IIf (sss,colorYellow, colorRed ));

_SECTION_BEGIN("www.IntradayAFL.com");
_N(Title = EncodeColor(colorWhite) + "{{NAME}} - {{INTERVAL}} {{DATE}} " );
_SECTION_END();

_SECTION_BEGIN("Intraday AFL System");
Buy = a;
Sell = b;

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

dist = ATR(20);
for (i=0; i<BarCount; i++) {
if ( Buy[i] )
PlotText("Buy:" + O[ i ], i, L[ i ]-3*dist[i], colorGreen);
if ( Sell[i] )
PlotText("Sell:" + O[ i ], i, H[ i ]+3*dist[i], colorRed);
}
_SECTION_END();

_SECTION_BEGIN("Trend");

Plot( 2, /* defines the height of the ribbon in percent of pane width */"ribbon",
IIf( uptrend, colorGreen, IIf( downtrend, colorRed, 0 )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
_SECTION_END();

//d = Close > Ref( ChandelierHL(ATR(3),20), -1);
//e =Close < Ref( ChandelierHL(ATR(3),20), -1);
//f = Close < Ref( ChandelierHL(ATR(3),20), -1);
//g = Close > Ref( ChandelierHL(ATR(3),20), -1);

Buy = a AND uptrend ;
Short = b AND downtrend ;
Sell = b AND downtrend ;
Cover = a AND uptrend;

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

Filter=Buy OR Sell;
Filter= Cover OR Short;

AddColumn( Buy, "Buy", 1);
AddColumn(Sell, "Sell", 1);
AddColumn(Close,"Close",1.2);
AddColumn(Volume,"Volume",1.0);

// Plot the Buy and Sell arrows.
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes(shape, IIf(Buy,colorGreen,colorRed), 0, IIf(Buy,Low,High));

//Plot(sloss,"Swing",colorYellow,styleStaircase);

//SetChartBkGradientFill( ParamColor("BgTop", ColorRGB( 172,172,172 )),

//ParamColor("BgBottom", ColorRGB( 172,172,172 )),ParamColor("titleblock",ColorRGB( 172,172,172 )));
//Alerts
AlertIf( Buy, "SOUND C:\\Windows\\Media\\tada.wav", "Buy",1,1+2+4+8);
AlertIf( Short, "SOUND C:\\Windows\\Media\\notify.wav", "Short",2,1+2+4+8);

GraphXSpace = 5;

/* -------------------------------------------------------------------------------------- */

SetChartBkColor(colorDarkOliveGreen );
SetChartOptions(0,chartShowArrows|chartShowDates);

/* -------------------------------------------------------------------------------------- */

////////////////////////////////////////////////////////////////////////////////////////////////
messageboard = ParamToggle("Message Board","Show|Hide",0);
showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0);

style = a * styleStaircase + b * styleStaircase;

PlotShapes(a,style, IIf(a,colorGreen,colorRed), 0, IIf(a,Low,High));
if (showsl == 0) Plot(sloss,"Stop Loss",colorCustom14,styleDots);
exitlong = Cross(sloss, H);
PlotShapes(exitlong * shapeNone, colorBlack,0,H,-10);
exitshort = Cross(L, sloss);
PlotShapes(exitshort * shapeNone, colorBlack,0,L,-15);

Buy = exitshort;
Sell = exitlong;
//Short = Sell;
//Cover = Buy;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
//Short = ExRem(Short, Cover);
//Cover = ExRem(Cover, Short);
AlertIf( Buy, "", "BUY @ " + C, 1 );
AlertIf( Sell, "", "SELL @ " + C, 2 );

for (i=BarCount-1; i>1; i--) {
if (Buy[i] == 1) {
entry = O[i];
sig = "BUY";
sl = sloss[i];
tar1 = entry + (entry * .0040);
tar2 = entry + (entry * .0085);
tar3 = entry + (entry * .0179);
bars = i;
i = 0;
}
if (Sell[i] == 1) {
sig = "SELL";
entry = O[i];
sl = sloss[i];
tar1 = entry - (entry * .0040);
tar2 = entry - (entry * .0085);
tar3 = entry - (entry * .0212);
bars = i;
i = 0;
}
}

Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, sloss[BarCount-1], Ref(sloss, -1));
sl = ssl[BarCount-1];

printf("Last " + sig + " Signal came " + (BarCount-bars) + " bars ago");
printf("\n" + sig + " @ : " + entry + "\nStop Loss : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"+ "\nTarget_1 : " + tar1 + "\nTarget_2 : " + tar2 + "\nTarget_3 : " + tar3);
printf("\nCurrent P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2));

if (messageboard == 0) {
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if (sig =="BUY")
GfxSelectSolidBrush( colorGreen ); // this is the box background color
else
GfxSelectSolidBrush( colorRed ); // this is the box background color

pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 05;
x2 = 200;

y = Status( "pxchartheight" );

GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 143, x2, y , 7, 7 ) ;
GfxTextOut( ( " www.IntradayAFL.com "), 10, y-140) ;
GfxTextOut( Name(),13,y-120);

GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-100);
GfxTextOut( ("Trailing SL : " + sl + " "), 13, y-80);
GfxTextOut( ("TGT:1 : " + tar1), 13, y -60);
GfxTextOut( ("TGT:2 : " + tar2), 13,y-40);
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 13, y-20);;
}
 
Hi Experts,

Can someone share the AFL to mark Minor & Visual Pivots on Amibroker charts as given in this image-



Thanks
 
Hello Seniors,

Can someone provide an afl which is based on price action HH and HL or LH and LL and their breakouts in consolidation.

which gives buy and sell signals should be compatible on 5min and higher time frames charts.

My regards
Vk2u
 
Last edited:

Similar threads