Australian (ASX) Stock Market Forum

Amibroker FAQ

Hi. Im trying to plot text below each swing on a swing chart. I would like to display the swing price level and the price differential between the current swing and the previous swing. I think you use the plottext function but I have no idea how to write the code and I need help

Is anyone familiar with this?

Thanks



/* Change this to 1 for two-bar mode */
twobarmode = 0;

outsidebar = Outside();
insidebar = H <= Ref( H, -1 ) AND L >= Ref( L, -1 ); // built-in inside() works with < > instead of <= >=

upbar = H > Ref( H, -1 ) AND L >= Ref( L, -1 );
downbar = L < Ref( L, -1 ) AND H <= Ref( H, -1 );

upbar2 = upbar OR ( outsidebar AND Ref( downbar, 1 ) ) ;
downbar2 = downbar OR ( outsidebar AND Ref( upbar, 1 ) );

Poi = outsidebar AND Ref( insidebar, 1 );
Poo = outsidebar AND Ref( outsidebar, 1 );
Pooi = Poo AND Ref( insidebar, 2 );
Poio = Poi AND Ref( outsidebar, 2 );
Poii = Poi AND Ref( insidebar, 2 );
Pooo = Poo AND Ref( outsidebar, 2 );
Poooi = Pooo AND Ref( insidebar, 3 );
Pooio = Pooi AND Ref( outsidebar, 3 );
Poioo = Poio AND Ref( outsidebar, 3 );

upbar3 = upbar2 OR ( Poi AND Ref( downbar, 2 ) );
downbar3 = downbar2 OR ( Poi AND Ref( upbar, 2 ) );

upbar4 = upbar3 OR ( Poo AND Ref( upbar, 2 ) );
downbar4 = downbar3 OR ( Poo AND Ref( downbar, 2 ) );

upbar5 = upbar4 OR ( Pooi AND Ref( upbar, 3 ) );
downbar5 = downbar4 OR ( Pooi AND Ref( downbar, 3 ) );

upbar6 = upbar5 OR ( Poio AND Ref( upbar, 3 ) );
downbar6 = downbar5 OR ( Poio AND Ref( downbar, 3 ) );

upbar7 = upbar6 OR ( Poii AND Ref( downbar, 3 ) );
downbar7 = downbar6 OR ( Poii AND Ref( upbar, 3 ) );

upbar8 = upbar7 OR ( Pooo AND Ref( downbar, 3 ) );
downbar8 = downbar7 OR ( Pooo AND Ref( upbar, 3 ) );

upbar9 = upbar8 OR ( Poooi AND Ref( downbar, 4 ) );
downbar9 = downbar8 OR (Poooi AND Ref( upbar, 4 ) );

upbar10 = upbar9 OR ( Pooio AND Ref( downbar, 4 ) );
downbar10 = downbar9 OR ( Pooio AND Ref( upbar, 4 ) );

upbar11 = upbar10 OR ( Poioo AND Ref( downbar, 4 ) );
downbar11 = downbar10 OR ( Poioo AND Ref( upbar, 4 ) );

fupbar = upbar11;
fdownbar = downbar11;

// Two-bar mode handling
fupbar = IIf( twobarmode, fupbar AND Ref( fupbar, 1 ), fupbar );
fdownbar = IIf( twobarmode, fdownbar AND Ref( fdownbar, 1 ), fdownbar );

/* Barcount since most recent up and down swings */
Us = BarsSince( fupbar );
Ds = BarsSince( fdownbar ) ;

Sd1 =IIf( Us==0, 1, IIf( Ds==0, -1, 0) );

Sd2 = IIf( Sd1 == 1, IIf( Ref( BarsSince(Sd1==1), -1) > Ref( BarsSince( Sd1 == -1), -1), 1, 0),
IIf( Sd1 == -1, IIf( Ref( BarsSince(Sd1==1),-1) < Ref( BarsSince( Sd1 == -1),-1), -1, 0), 0 ) );

g0 = ValueWhen( Sd2, Sd2 ); /* sample and hold non-zero values */

/* shift back one bar, add one dummy swing at the end and shift forward */
/* to ensure proper handling of the last swing */
lastbar = Cum(1) == LastValue( Cum(1) );
swinglevel = IIf( g0 == -1, HighestSince( Sd2 == 1, H ), LowestSince( Sd2 == -1, L ) );
swinglevel = IIf( lastbar, IIf( g0 == -1, LowestSince( Sd2 == -1, L ), HighestSince( Sd2 == 1, H )), Ref( swinglevel, 1 ) );

/* Gann Swing chart drawn here */
myGraph1 = Ref( ValueWhen( Ref( Sd2 != 0, 1 ) OR lastbar, swinglevel ,
0 ), -1 );
Plot( myGraph1, "graph1", colorBlack, styleStaircase|styleSwingDots);
GraphXSpace = 5;

/* Colourized price bars drawn here */
/* graph0 = close; */
/* graph0style = 128; */
/* barcolor = IIF( outsidebar, 1, IIF( downbar, 4, IIF( upbar, 5, 0 ) ) ); */
/* graph0barcolor = ValueWhen( barcolor != 0, barcolor ); */
 
I'm trying to code an exploration that looks for compressed price movement. In essence, I am creating a channel built from a linear regression line that I want to see price confined by. It works when setting N = 1 but setting N to anything larger with the hopes of looking at how it performed in the past doesn't seem to work. I am guessing this is because "Upper" and "Lower" are null in all but the most recent portion of the respective arrays. Can anyone look at my code and help me out?

Code:
LookBack = Optimize("LookBack", 13, 1, 240, 1);
SlopeThresh = Optimize("SlopeDiff", 0.07, 0.01, 0.5, 0.05);
VolatilityThresh = Optimize("VolatilityThresh", 0.0025, 0.05, 1, 0.05);
Shift = Param("Shift", 0, 0, 500, 1); 

x = Cum(1);
lastx = LastValue( x ) - Shift; 
Intercept = LinRegIntercept( C, LookBack );
Slope = LinRegSlope( C, LookBack );

aa = LastValue( Ref(Intercept, 0 - Shift), False ); 
bb = LastValue( Ref(Slope, 0 - Shift), False ); 
LinRegLine = aa + bb * ( x - (lastx - LookBack + 1 ) ); 

width = VolatilityThresh * MA(C, LookBack);
Upper = IIf( x > (lastx - LookBack) AND BarIndex() < lastx, LinRegLine + width , Null ) ;
Lower = IIf( x > (lastx - LookBack) AND BarIndex() < lastx, LinRegLine - width , Null ) ;

printf( "Upper = %5.2f\n", Upper );
printf( "Lower = %5.2f\n", Lower );

ChannelColor = ParamColor("ChannelColor", colorGreen ); 

Plot( Upper, "Upper", ChannelColor ); 
Plot( Lower, "Lower", ChannelColor ); 

// check for channel slope
SlopeOk = abs( LastValue( Ref(Slope, -1), False ) ) <= SlopeThresh;

Didbreak = 0;

// check for channel break
i = 1;
while(LastValue(i, False) < LookBack)
{
	DidBreak = IIf(Ref(High, 0 - i) > Ref(Upper, 0 - i) OR Ref(Low, 0 - i) < Ref(Lower, 0 - i), 1, 0); 
	
	printf("High[%5.2f] = %5.2f\n", 0 - i, Ref(High, 0 - i));
	printf("Upper[%5.2f] = %5.2f\n", 0 - i, Ref(Upper, 0 - i));
	printf("Low[%5.2f] = %5.2f\n", 0 - i, Ref(Low, 0 - i));
	printf("Lower[%5.2f] = %5.2f\n", 0 - i, Ref(Lower, 0 - i));
	printf("DidBreak = %5.2f\n", LastValue(DidBreak, False));

	Temp = IIf( LastValue(DidBreak, False), LookBack, i); 
	i = Temp + 1;
}


Score = 0 ;
AddColumn(C, "Close");
AddColumn(width, "Width");

Filter = SlopeOk AND LastValue(DidBreak, False) <= 0;

PlotShapes( IIf( Filter, shapeHollowCircle, shapeNone ), colorOrange, 0, High);

Here is a pic of what I have going so far...
compression_channel.png
 
I think you use the plottext function but I have no idea how to write the code and I need help.

Pennies, this is a plot text code. Just substitute the Buy/Sell.

Dist = 2.5*ATR(30);
for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy" + C[ i ], i, L[ i ]-Dist, colorWhite );
if( Sell ) PlotText( "Sell" + C[ i ], i, H[ i ]+Dist, colorBlack );
}
 
Thanks wysiwyg.

Im afraid Im pretty poor at AFL. That is similar to the code that is listed in the examples on the bottom of the plottext page at amibroker. Ive looked at it but I have no idea what Im doing or how to change it so that it will plot the swing price level and the price differential between the current swing and the previous one as text below or above each swing.:banghead:
 
Ive managed to plot "mytext" above and below each swing with this afl but Im stuck now. Can anyone help me convert the "my text part" to show the current swing level as well as the price range differential between this swing and the previous one. I dont know what to do to get that happening :confused:

The afl I have made is

textUPStartX = myGraph1 > Ref( MyGraph1, -1);
textDNStartX = myGraph1 < Ref( MyGraph1, -1);
dist = 0.5*ATR(10);

for( i = 0; i < BarCount; i++ )
{
if( textUPStartX ) PlotText( "MyText1" , i, myGraph1 [ i ]+dist,
colorGreen );
if( textDNStartX ) PlotText( "MyText2" , i, myGraph1 [ i ]-dist,
colorRed );
}
 
Hi

Ok Ive spent all day trying to do this and Ive sort of managed to get the swing price levels to plot ok although I only wanted to plot the swings that appear on my chart using a 2 day setting and this tends to plot others as well. The main thing I need help with now is "How do I plot the amount that the current swing on my chart varies in price from the previous swing" Im after the range from high to low to be plotted in text on the chart below where the price is plotted. (Previous swing high 4800 - current swing low 4720 then Plot Range 80) Can anyone help me with this please.

_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( "pivot" );
price = ParamToggle( "Plot Price", "Off|On", 1 );
num = Param( "trend", 4, 1, 10, 1 );
dist = 0.5 * ATR( 10 );
rightfig = Param( "rightfig ", 7, 1, 10, 1 );
xspace = Param( "GraphXSpace ", 10, 1, 20, 1 );

mHHV = HHV( H, num );
mLLV = LLV( L, num );

FirstVisibleBar = Status( "FirstVisibleBar" );
Lastvisiblebar = Status( "LastVisibleBar" );

for ( b = Firstvisiblebar + num; b <= Lastvisiblebar AND b < BarCount - num;
b++ )
{
i = num;
ml = 0;
mu = 0;

while ( i > 0 )
{

if ( L < L[b+i] )
{
ml++;
}


if ( H > H[b+i] )
{
mu++;
}

i--;
}


if ( ml == num AND L == mLLV )
{
PlotText( "\n *\n", b, L, colorGreen );

if ( price == 1 )
{
p = StrRight( NumToStr( L, 4.1 ), rightfig );
PlotText( "\n\n" + p, b - 2 , L , colorGreen );
}
}


if ( mu == num AND H == mHHV )
{
PlotText( " *\n", b, H, colorRed );

if ( price == 1 )
{
p = StrRight( NumToStr( H, 4.1 ), rightfig );
PlotText( p , b - 2 , H + dist + 1, colorRed );
}
}
}



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


/* Gann Swing chart v4 */
/* Last modified 24 Feb 2001 */
/* AFL implementation by */
/* (C)2001 Tomasz Janeczko */
/* one and two - bar reversal version */

/* Change this to 1 for two-bar mode */
twobarmode = 1;

outsidebar = Outside();
insidebar = H <= Ref( H, -1 ) AND L >= Ref( L, -1 ); // built-in inside() works with < > instead of <= >=

upbar = H > Ref( H, -1 ) AND L >= Ref( L, -1 );
downbar = L < Ref( L, -1 ) AND H <= Ref( H, -1 );

upbar2 = upbar OR ( outsidebar AND Ref( downbar, 1 ) ) ;
downbar2 = downbar OR ( outsidebar AND Ref( upbar, 1 ) );

Poi = outsidebar AND Ref( insidebar, 1 );
Poo = outsidebar AND Ref( outsidebar, 1 );
Pooi = Poo AND Ref( insidebar, 2 );
Poio = Poi AND Ref( outsidebar, 2 );
Poii = Poi AND Ref( insidebar, 2 );
Pooo = Poo AND Ref( outsidebar, 2 );
Poooi = Pooo AND Ref( insidebar, 3 );
Pooio = Pooi AND Ref( outsidebar, 3 );
Poioo = Poio AND Ref( outsidebar, 3 );

upbar3 = upbar2 OR ( Poi AND Ref( downbar, 2 ) );
downbar3 = downbar2 OR ( Poi AND Ref( upbar, 2 ) );

upbar4 = upbar3 OR ( Poo AND Ref( upbar, 2 ) );
downbar4 = downbar3 OR ( Poo AND Ref( downbar, 2 ) );

upbar5 = upbar4 OR ( Pooi AND Ref( upbar, 3 ) );
downbar5 = downbar4 OR ( Pooi AND Ref( downbar, 3 ) );

upbar6 = upbar5 OR ( Poio AND Ref( upbar, 3 ) );
downbar6 = downbar5 OR ( Poio AND Ref( downbar, 3 ) );

upbar7 = upbar6 OR ( Poii AND Ref( downbar, 3 ) );
downbar7 = downbar6 OR ( Poii AND Ref( upbar, 3 ) );

upbar8 = upbar7 OR ( Pooo AND Ref( downbar, 3 ) );
downbar8 = downbar7 OR ( Pooo AND Ref( upbar, 3 ) );

upbar9 = upbar8 OR ( Poooi AND Ref( downbar, 4 ) );
downbar9 = downbar8 OR (Poooi AND Ref( upbar, 4 ) );

upbar10 = upbar9 OR ( Pooio AND Ref( downbar, 4 ) );
downbar10 = downbar9 OR ( Pooio AND Ref( upbar, 4 ) );

upbar11 = upbar10 OR ( Poioo AND Ref( downbar, 4 ) );
downbar11 = downbar10 OR ( Poioo AND Ref( upbar, 4 ) );

fupbar = upbar11;
fdownbar = downbar11;

// Two-bar mode handling
fupbar = IIf( twobarmode, fupbar AND Ref( fupbar, 1 ), fupbar );
fdownbar = IIf( twobarmode, fdownbar AND Ref( fdownbar, 1 ), fdownbar );

/* Barcount since most recent up and down swings */
Us = BarsSince( fupbar );
Ds = BarsSince( fdownbar ) ;

Sd1 =IIf( Us==0, 1, IIf( Ds==0, -1, 0) );

Sd2 = IIf( Sd1 == 1, IIf( Ref( BarsSince(Sd1==1), -1) > Ref( BarsSince( Sd1 == -1), -1), 1, 0),
IIf( Sd1 == -1, IIf( Ref( BarsSince(Sd1==1),-1) < Ref( BarsSince( Sd1 == -1),-1), -1, 0), 0 ) );

g0 = ValueWhen( Sd2, Sd2 ); /* sample and hold non-zero values */

/* shift back one bar, add one dummy swing at the end and shift forward */
/* to ensure proper handling of the last swing */
lastbar = Cum(1) == LastValue( Cum(1) );
swinglevel = IIf( g0 == -1, HighestSince( Sd2 == 1, H ), LowestSince( Sd2 == -1, L ) );
swinglevel = IIf( lastbar, IIf( g0 == -1, LowestSince( Sd2 == -1, L ), HighestSince( Sd2 == 1, H )), Ref( swinglevel, 1 ) );

/* Gann Swing chart drawn here */
myGraph1 = Ref( ValueWhen( Ref( Sd2 != 0, 1 ) OR lastbar, swinglevel ,
0 ), -1 );
Plot( myGraph1, "graph1", ParamColor("SwingColor", colorBlueGrey ),
styleStaircase|styleSwingDots, Null, Null, 0, Zorder=1);
GraphXSpace = 5;

_SECTION_END();SwingData.gif
 
Can anyone help me PLEASE. Graham Kavanagh is not accepting any work at the moment so I really need help. If its easier to convert the "mytext1" and "mytext2" part of this formula so that it displays the range (Difference in price between current swing and the last swing), Swing price level on the chart that would be better. Any guidance at all would be appreciated :)

textUPStartX = myGraph1 > Ref( MyGraph1, -1);
textDNStartX = myGraph1 < Ref( MyGraph1, -1);
dist = 0.5*ATR(10);

for( i = 0; i < BarCount; i++ )
{
if( textUPStartX ) PlotText( "MyText1" , i, myGraph1 [ i ]+dist,
colorGreen );
if( textDNStartX ) PlotText( "MyText2" , i, myGraph1 [ i ]-dist,
colorRed );
}

MytextSwing.gif
 
Hi Pennies I'm not a programmer but saw this on a afl which you may be able to convert somehow for what you want. This little script displays the price and % change where you click on the graph...will be interested how you get on.

_SECTION_BEGIN("Magnified Market Price");
FS=Param("Font Size",10,11,100,1);
GfxSelectFont("Arial", FS, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ColorRGB( 160, 0, 80 ) );
//GfxSetTextColor( ParamColor("Color",colorViolet) );
Hor=Param("Horizontal Position",80,1,1200,1);
Ver=Param("Vertical Position",222,1,1200,1);
GfxTextOut(""+C,Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,3);
GfxSelectFont("Arial", 10, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ColorRGB( 160, 0, 80 ) );
//GfxSetTextColor(ParamColor("Color",colorViolet) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor+5, Ver+45 );
_SECTION_END();
 
Thanks for that xyz246. I will try and decipher that later :)

I think Amibroker is a fantastic program but for me the AFL coding is the weak link. I find it pretty hard. Its almost got to the point where I buy a different charting package but I really do like this one. Im not sure if what Im trying to do is easy or hard but judging from the replies I think its hard. I will keep trying. I really appreciate that you took the time to reply.
 
Hi Pennies, and all --

I am not trying to make your job any harder, but as far as programming goes, it really does not matter which trading system development platform you decide to use. In order to develop profitable trading systems, you will need to become proficient in programming its language. You will not find systems in magazines or on websites that will do everything you want exactly as you want them done.

You might as well begin using a development platform that has the power to implement the ideas you will eventually want to code and test. Not all of them do have that power. AmiBroker does. There is a large library of code available on the AmiBroker website to help you get started. And join the Yahoo AmiBroker Forum.

You will also need to become enough of a statistician to understand and apply statistical tests to tell when your system is working and when it is broken.

Thanks for listening,
Howard
 
Can anyone help me PLEASE. Graham Kavanagh is not accepting any work at the moment so I really need help. If its easier to convert the "mytext1" and "mytext2" part of this formula so that it displays the range (Difference in price between current swing and the last swing), Swing price level on the chart that would be better. Any guidance at all would be appreciated :)

textUPStartX = myGraph1 > Ref( MyGraph1, -1);
textDNStartX = myGraph1 < Ref( MyGraph1, -1);
dist = 0.5*ATR(10);

for( i = 0; i < BarCount; i++ )
{
if( textUPStartX ) PlotText( "MyText1" , i, myGraph1 [ i ]+dist,
colorGreen );
if( textDNStartX ) PlotText( "MyText2" , i, myGraph1 [ i ]-dist,
colorRed );
}

MytextSwing.gif


pennies,

You are almost there and have done the hard work. Just modify the loop along these lines (you might have to fiddle to get things lined up and with the correct sign):

Bill

for( i = etc. )
{
delta[ i ] = iif( mygraph1[ i ] != mygraph1[ i - 1 ], mygraph1[ i ] - mygraph1[ i - 1 ], 0 );
if( textupstartx[ i ] ) plottext( "" + delta[ i ], i, mygraph[ i ] + dist[ i ], colorgreen );
if(textdnstartx[ i ] ) plottext( etc. ...
}
 
I thought I was doing something that would be quite simple but not to be.

I use e-signal RT data, amibroker and windows 7.

I want to make my own index composite of ASX (S&P) 200 stocks in amibroker, then a intraday advance decline line and intraday cumulative tick chart for this ASX200 index.

I can't get past the first one! I'm trying to use AddToComposite to make a composite index from the 200 stocks that make up the ASX(S&P200)

AFL Code:

Var=Close;
AddToComposite(InWatchList(0)*Var,"~Watch1Comp","X");
Buy=Sell=Short=Cover=0;
Filter=1;
[Waz]

It seems to work and I get a composite for the stocks in the watchlist but I get the following error (because I want to run this on 5 min intervals this error will become very annoying):

Error 32.
Syntax error, probably missing semicolon at the end of the previous line

This is where I'm getting the information from on AddToComposite
http://www.amibroker.org/userkb/2007/12/31/introduction-to-the-atc/

If anyone could help me in achieving this it would be great, this stuff will most likely help your trading as well.

- composite index from ASX (S&P) 200 stocks
- intraday advance decline line asx200
- intraday cumulative tick chart asx200

Cheers,

Quinn
 
Managed to get that stuff sorted. Just wondering if anyone knows AFL to search for price on previous tick?

"the previously traded price before current/last price."
 
T0 all you A/B formula gurus,
Please help me get started by coding this simple system,i have tried with the code wizard etc but cant seem to get off first base.
i want to be given a buy signal using weekly close when the price has risen and closed above its 15 sma within standard Bollinger Bands,corrected back to the 15 sma line without closing below it and then retraces to the previous peak and closes above it.
This new closing high gives an on notice signal which is confirmed to a buy signal on the PDI crossing above the MDI.
To exit, the price must close below its 15 sma to go on notice,with a confirmed sell signal on the PDI crossing below the MDI.
Also being able to use the explore function on this system would be an added bonus.
It was capn black who helped me decide originally to purchase A/B,so if your still out there capn---------HEEEEEEEEEELP :confused::banghead:

SPARFARKLE
 
Hope someone knows the reason here please.

Something has me stumped with the following SetForeign function because the position sizing code malfunctions when SetForeign is used :-

SetForeign("^ATOI", True, False);
Buy = stochk() > 80;
RestorePriceArrays(True);

According to the docs. the tradeprices part of which I have false

SYNTAX = SetForeign( ticker, fixup = True, tradeprices = False )

tradeprices parameter controls if trade price arrays should be replaced too. If it is set to TRUE, then not only OHLC, V, OI, Avg arrays are set to foreign symbol values, but also BuyPrice, SellPrice, ShortPrice, CoverPrice, PointValue, TickSize, RoundLotSize, MarginDeposit variables are set to correspond to foreign security.

See I only want an indicator state (i.e. stochk > 80) from the Foreign ticker but using SetForeign messes the position sizing up.
 
Hi all

Trying to Setup the ASX data in Amibroker, Im just not sure how to add the date, can anyone help me with providing me instruction please ?

thank you
 
Top