Australian (ASX) Stock Market Forum

Amibroker FAQ

Play around with this a bit------from Ed's code. This provides you with a "flag" and the desired prices.


nbar = Param("nbar",5,2,50,1); // number of bars on each side

// define fractals
PHigh = H > Ref(HHV(H,nbar),-1) AND Ref(HHV(H,nbar),nbar) <= H;
PHighPrice = ValueWhen(PHigh,H);

PLow = L < Ref(LLV(L,nbar),-1) AND Ref(LLV(L,nbar),nbar) >= L;
PLowPrice = ValueWhen(PLow,L);
 
Add this for visualization ----- also Ed's code


// chart
GraphXSpace = 5;
SetChartOptions(0, chartShowDates);
chartflag = ParamToggle("Heikin Ashi","show|hide",1);
if (chartFlag)
{
Plot( C, "\nPrice",colorWhite, styleCandle );
}
else
{
HaClose = (O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "Modified " + Name(), colorWhite,
styleCandle );
}

PlotShapes(shapeSmallCircle*PLow,colorGreen,0,L,-10);
PlotShapes(shapeSmallCircle*PHigh,colorRed,0,H,10);
 
Add this for visualization ----- also Ed's code


// chart
GraphXSpace = 5;
SetChartOptions(0, chartShowDates);
chartflag = ParamToggle("Heikin Ashi","show|hide",1);
if (chartFlag)
{
Plot( C, "\nPrice",colorWhite, styleCandle );
}
else
{
HaClose = (O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "Modified " + Name(), colorWhite,
styleCandle );
}

PlotShapes(shapeSmallCircle*PLow,colorGreen,0,L,-10);
PlotShapes(shapeSmallCircle*PHigh,colorRed,0,H,10);


Thanks that makes it a lot easier to navigate.

So I have my two low pivots. Which function would I use to find the HHV in an interval?
 
Study on this ----- not Ed's code.

This gives you the values of the preceding, opposite-side pivot values. IOW, at the pivot-low, the prior-high price is known. At the pivot-high, the prior-low price is known.

PriorHigh = ValueWhen(PLow,PHighPrice);
PriorLow = ValueWhen(PHigh,PLowPrice);
 
Study on this ----- not Ed's code.

This gives you the values of the preceding, opposite-side pivot values. IOW, at the pivot-low, the prior-high price is known. At the pivot-high, the prior-low price is known.

PriorHigh = ValueWhen(PLow,PHighPrice);
PriorLow = ValueWhen(PHigh,PLowPrice);

Thanks again. Very helpful.
 
Perhaps these will help. Place this plot-code in a separate pane below the previous code (Ed's pivots)----then you'll be able to see the timing for the flags and arrays. Comment out these plot statements as desired.


Plot( PHigh, "High_flag", colorRed, styleHistogram | styleOwnScale );
Plot( PLow, "Low_flag", colorGreen, styleHistogram | styleOwnScale );

Plot( PHighPrice, "High",colorBlue );
Plot( PLowPrice, "Low",colorBrown );

Plot( PriorHigh,"Prior_H",colorGreen );
Plot( PriorLow,"Prior_L",colorViolet );
 
Perhaps these will help. Place this plot-code in a separate pane below the previous code (Ed's pivots)----then you'll be able to see the timing for the flags and arrays. Comment out these plot statements as desired.


Plot( PHigh, "High_flag", colorRed, styleHistogram | styleOwnScale );
Plot( PLow, "Low_flag", colorGreen, styleHistogram | styleOwnScale );

Plot( PHighPrice, "High",colorBlue );
Plot( PLowPrice, "Low",colorBrown );

Plot( PriorHigh,"Prior_H",colorGreen );
Plot( PriorLow,"Prior_L",colorViolet );

also handy thank you.

Is there a function which would work to find "HHV since the bar when the second last low pivot was formed"?
 
The "instance" number in the ValueWhen function is the key. It looks back the desired number of flags---then gathers the designated array.


TwoHighsAgo = ValueWhen(PLow,PHighPrice,2); // note the "instance" number
TwoLowsAgo = ValueWhen(PHigh,PLowPrice,2); // note the "instance" number


Good luck with your study GB --- this is a good example from which to learn. I'm new at this code stuff myself, but am glad I could help out a fellow student.
 
The "instance" number in the ValueWhen function is the key. It looks back the desired number of flags---then gathers the designated array.


TwoHighsAgo = ValueWhen(PLow,PHighPrice,2); // note the "instance" number
TwoLowsAgo = ValueWhen(PHigh,PLowPrice,2); // note the "instance" number


Good luck with your study GB --- this is a good example from which to learn. I'm new at this code stuff myself, but am glad I could help out a fellow student.

I'm looking at a double bottom system, which I've not had a look at before. Cheers. :)
 
Hello

using constant range bars in intraday trading ( market is India- NSE). using the below code for the buy - sell logic

please cud it be brushed up a bit for reducing the repititive buy - sell signal generation. [ in the image the range is 1250 or in dollar term - its 12.5 range]

HTML:
 _SECTION_BEGIN("Breakout Setting");
  
Buyperiods=Param("Breakout periods best is usually 18",5,1,100,1,1);
Sellperiods=Param("Exit Breakout",5,1,100,1,1);

Buy =Cross( C, Ref( HHV(H,Buyperiods), -1 )) ;
Sell=Cross(Ref(LLV(Low,Sellperiods),-1),C);

//Buy=Ref(Buy,-1); // entry on same bar
//Sell=Ref(Sell,-1);

Cover=Buy; // [B]need a better cover code here[/B]
Short=Sell; // [B]need a better exit code here[/B]
  
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);

//BuyPrice=O;//ValueWhen(Buy,C,1);
//SellPrice=O;//ValueWhen(Sell,C,1);

SellPrice = Min(Ref(C,-1),Open); //.
BuyPrice = Max(Ref(C,-1),Open); // 

//Cover=ExRem(Cover,Exit);
//Exit=ExRem(Exit,Cover);

PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), 51, layer = 0,yposition = Low, offset = -15);
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), 42, layer = 0, yposition = High, offset = -15);

//PlotShapes( IIf( Exit, shapeDigit7, shapeNone ), 51, layer = 0, ypo
//PlotShapes( IIf( Cover, shapeDigit4, shapeNone ), 25, layer = 0,yposition = sition = High, offset = 15);

TrailStop = HHV( C - 2 * ATR(10), 15 ); 
ProfitTaker = EMA( H, 13 ) + 2 * ATR(10); 

/* plot price chart and stops */ 
Plot( TrailStop, "Trailing stop", colorBrown, styleThick | styleLine  ); 
Plot( ProfitTaker, "Profit taker", colorLime, styleThick ); 

 _SECTION_END();




waiting for ur reply

rgds
sr
 

Attachments

  • bnf 17012013.png
    bnf 17012013.png
    18 KB · Views: 6
  • bnf 17012013.png
    bnf 17012013.png
    30.7 KB · Views: 3
Actually want some other code part along the buy - sell logic which will try to reduce the excessive generation of the signals

can we use the trendline multiframe by Ed as a confirming tools/logic here?

bnf trendline 17012013.png

the code attached here

HTML:
("Trendlines Multitimeframe ");
 // Amibroker AFL code by Edward Pottasch, 6/8/2011

also the hl or lh part here can be used as cover/exit code? and if yes how can we incorporate it with the cover/short/exit part?

rgds
sr
 
Hi sr114,

Not really sure who the "we" are (alluded to, in your post), but I'll play along. Besides, it's a decent topic and I don't have much going on this weekend;~).

First off, why the usage of ConstantRangeBars (CRB) ? Yes, it seems obvious that for a range-breakout system that those would be reasonable......but, does the methodology work with ConstantVolumeBars (or just "regular" bars)? I'm not trying to be an ***hole, just curious.

Second, as to the usage of Ed's trendline stuff: Do trendlines applied to CRB charts behave in the same manner (wrt any possible advantage to the trader) as the "standard" trendlines that are most commonly studied? Lots of rhetorical questions here.......simply thinking out loud.

Later,
RutheezKey
 
Hi sr114,

Not really sure who the "we" are (alluded to, in your post), but I'll play along. Besides, it's a decent topic and I don't have much going on this weekend;~).

First off, why the usage of ConstantRangeBars (CRB) ? Yes, it seems obvious that for a range-breakout system that those would be reasonable......but, does the methodology work with ConstantVolumeBars (or just "regular" bars)? I'm not trying to be an ***hole, just curious.

Second, as to the usage of Ed's trendline stuff: Do trendlines applied to CRB charts behave in the same manner (wrt any possible advantage to the trader) as the "standard" trendlines that are most commonly studied? Lots of rhetorical questions here.......simply thinking out loud.

Later,
RutheezKey

Hi Rutheezkey

actually here we means the user - its not intended for any 1 particular.

now to ur queries:

1. CRB - yes using the constant range bars here helps for the trading. it helps to override the sudden spikes in the regular time based bars.

in case of CVB - i never used it - so cud not be able to comment on that.

the range breakout system is both applicable in crb as well as regular bars. in fact both r well behaved in the range breakout system

2. the Ed's trendline - i am a great fan of this tool. and i regularly use it in eod as well as in intraday analysis.
yes Ed's trendline is applicable to both crb as well as regular bars - but is well represented / managed in the crb rather than the regular bars as the sudden spikes ( which occurs regularly in our market - India) are well contained in the ranges rather than the regular bars where it shows a wide fluctuation.

lastly the trendline mixed with the fibo - helps me to ascertain the entry as well as the exit point alon with the reversal points.

hope that in short i am able to replies ur question.

rgds
sr
 
I am always happy to help anyone with writing AFL for AB. I am a regular in the AB yahoo group, AB website forum, RC and other places.

"I am new to AB(with little programming experience) and want to develop a rotational trading system using the EnableRotationalTrading command - however am unable to get the program set to the data list I want to use - have tried the Filters and Symbols select, etc, but never get, say, the S&P500. I would appreciate your help. Paul
 
"I am new to AB(with little programming experience) and want to develop a rotational trading system using the EnableRotationalTrading command - however am unable to get the program set to the data list I want to use - have tried the Filters and Symbols select, etc, but never get, say, the S&P500. I would appreciate your help. Paul

Start a new database. Import the current list of S&P 500 stocks and go from there. Just realize that using today's list of the top 500 will have some built in survivorship bias. Does that help?
 
This might be a big ask, not sure. How would one go about using this point and figure code to find a double or triple top, then create a buy signal in the normal linear time scale chart? Thanks.



Code:
_SECTION_BEGIN( "Point & Figure w Values adj" );
//mandeep Singh 05-Jan-2009
GfxSetBkColor(colorBlack);
GfxSetTextColor( colorOrange );
GfxSelectFont("Times New Roman", 10, 700, True );
GfxTextOut("man4urheart.blogspot.com", 10 , 0 );

GraphXSpace = 5;

SetChartBkColor( ParamColor( "BackGroundColor", colorBlack) );

//GraphColor = ParamColor("GarphColor",colorLightGrey);

GridColor = ParamColor( "GridColor", colorLightGrey );

Scaling = ParamList( "Scaling Method", "Traditional|Percentage|AVG True Range" );

if ( scaling == "Traditional" )
{
Box = Param( "Box", 1, 0.2, 100, 0.1 );

}
else

if ( scaling == "Percentage" )
Box = Param( "Box ", 1, 0.2, 10, 0.1 ) / 100 * LastValue( C );
else
if ( scaling == "AVG True Range" )
Box = Param( "Box", 1, 0.3, 5, 0.1 ) * LastValue( ATR ( 20 ) );

shiftChart = 0;
shiftLastClose = 1;
shiftGrid = 7;
shiftPriceAxis = 2;

Reverse = Param( "Reverse", 3, 1, 5 );

j = 0;

PFL[0] = Box * ceil( Low[0] / Box ) + Box;

PFH[0] = Box * floor( High[0] / Box );

direction = 0;

for ( i = 1; i < BarCount; i++ )

{

if ( direction[j] == 0 )

{

if ( Low[i] <= PFL[j] - Box )

{

PFL[j] = Box * ceil( Low[i] / Box );

}

else

{

if ( High[i] >= PFL[j] + Reverse*Box )

{

j++;

direction[j] = 1;

PFH[j] = Box * floor( High[i] / Box );

PFL[j] = PFL[j - 1] + Box;

}

}

}

else

{

if ( High[i] >= PFH[j] + Box )

{

PFH[j] = Box * floor( High[i] / Box );

}

else

{

if ( Low[i] <= PFH[j] - Reverse * Box )

{

j++;

direction[j] = 0;

PFH[j] = PFH[j - 1] - Box;

PFL[j] = Box * ceil( Low[i] / Box );

}

}

}

}

delta = BarCount - j - 1;

direction = Ref( direction, - delta );

Hi = Ref( PFH, -delta ) + Box / 2;

Lo = Ref( PFL, -delta ) - Box / 2;

Cl = IIf( direction == 1, Hi, Lo );

Op = IIf( direction == 1, Cl - Box, Cl + Box );

Graphcolor = IIf( direction == 1, ParamColor( "X_Color",colorBrightGreen ),

ParamColor( "O_Color", colorRed ) );

PlotOHLC( Op, Hi, Lo, Cl, "", GraphColor , stylePointAndFigure | styleNoLabel, 0, 0 , shiftChart );

PlotOHLC( Op, Hi, Lo, Cl, "", GraphColor , stylePointAndFigure | styleNoLabel, 0, 0 , shiftChart );

Last = Ref( LastValue( C ), -( BarCount - 1 ) );

Plot( Last, "", colorRed, styleNoLine | styleDots, 0 , 0,shiftLastClose );

// selected value

Value = IIf( direction > 0, SelectedValue( Hi ) - box / 2,SelectedValue( Lo ) + box / 2 );


//----------------------------------------------------------

// GRID CONSTRUCTION

//----------------------------------------------------------

PlotGridLines = ParamToggle( "PlotdGrid", "Yes! |No", 1 ) ;

if ( PlotGridLines ==1)

{

begin = SelectedValue( BarIndex() );

end = LastValue( BarIndex() );

period = end - begin + 1;

if ( begin < end )

{

ScreenHigh = LastValue( HHV( cl, period ) );

ScreenLow = LastValue( LLV( Cl, period ) );

top = LineArray( begin - shiftGrid, screenHigh, end, screenhigh, 0 ,
1 );

Bot = LineArray( begin - shiftGrid, screenlow, end, screenLow, 0, 1 );

Plot( top, "", gridColor, styleLine | styleNoLabel , 0, 0, shiftGrid );

//Plot( bot, "", gridColor,styleLine|styleNoLabel, 0 , 0 , shiftGrid);

VerticalGrid = IIf ( BarIndex() >= begin, IIf( direction == 1,
screenHigh,
screenLow ), Null );

Plot ( VerticalGrid, "", gridColor, styleStaircase | styleNoLabel,
0, 0, 1
);

format = 8.2;

for ( n = LastValue( bot ); n < LastValue( top ) - 0.5*box; n = n +
box )

{

Plot( bot , "", gridColor, styleLine | styleNoLabel, 0, 0 , shiftGrid );

text = NumToStr( LastValue( bot ) + 0.5 * box, format );

xposition = BarCount + shiftPriceaxis;

yPosition = LastValue( bot ) + 0.27 * box;

PlotText( text, xPosition , yPosition, colorWhite );

bot = bot + box;

Graphcolor = IIf( direction == 1, ParamColor( "X_Color",
colorBrightGreen ),

ParamColor( "O_Color", colorRed ) );

PlotOHLC( Op, Hi, Lo, Cl, "", GraphColor , stylePointAndFigure | styleNoLabel, 0, 0 , shiftChart );

}

}

}



//----------------------------------------------------------

// TITLE

//----------------------------------------------------------

Title = "\n" +

" Instrument : " + Name() + FullName() + "\n " +

"Formula : " + " Point & Figure (High/Low Range)" + "\n " +

"Box : " + NumToStr( Box, 4.4 ) + " " +

"Reverse : " + NumToStr( Reverse, 2.0 ) + "\n " +

"ATR : " + WriteVal( LastValue( ATR( 100 ) ), format = 4.4 );

_SECTION_END();




//Formula:

_SECTION_BEGIN( "Point & Figure w Values adj" );
//mandeep Singh 05-Jan-2009

GfxSetBkColor(colorBlack);
GfxSetTextColor( colorOrange ); 
GfxSelectFont("Times New Roman", 10, 700, True );
GfxTextOut("man4urheart.blogspot.com", 10 , 0 );
 
GraphXSpace = 5;

SetChartBkColor( ParamColor( "BackGroundColor", colorBlack) );

//GraphColor = ParamColor("GarphColor",colorLightGrey);
 
GridColor = ParamColor( "GridColor", colorLightGrey );
 
Scaling = ParamList( "Scaling Method", "Traditional|Percentage|AVG True Range"
);
 
if ( scaling == "Traditional" )
 {
Box = Param( "Box", 1, 0.2, 100, 0.1 );

 }
else
 
if ( scaling == "Percentage" )
	Box = Param( "Box ", 1, 0.2, 10, 0.1 ) / 100 * LastValue( C );
else
if ( scaling == "AVG True Range" )
Box = Param( "Box", 1, 0.3, 5, 0.1 ) * LastValue( ATR ( 20 ) );

shiftChart = 0;
shiftLastClose = 1;
shiftGrid = 7;
shiftPriceAxis = 2;
 
Reverse = Param( "Reverse", 3, 1, 5 );
 
j = 0;
 
PFL[0] = Box * ceil( Low[0] / Box ) + Box;
 
PFH[0] = Box * floor( High[0] / Box );
 
direction = 0;
 
 for ( i = 1; i < BarCount; i++ )
 
 {
 
if ( direction[j] == 0 )
 
 {
 
 if ( Low[i] <= PFL[j] - Box )
 
 {
 
 PFL[j] = Box * ceil( Low[i] / Box );
 
 }
 
 else
 
 {
 
 if ( High[i] >= PFL[j] + Reverse*Box )
 
 {
 
 j++;
 
 direction[j] = 1;
 
 PFH[j] = Box * floor( High[i] / Box );
 
 PFL[j] = PFL[j - 1] + Box;
 
 }
 
 }
 
}

 else
 
 {
 
 if ( High[i] >= PFH[j] + Box )
 
 {
 
 PFH[j] = Box * floor( High[i] / Box );
 
 }
 
 else
 
 {
 
 if ( Low[i] <= PFH[j] - Reverse * Box )
 
 {
 
 j++;
 
 direction[j] = 0;
 
 PFH[j] = PFH[j - 1] - Box;
 
 PFL[j] = Box * ceil( Low[i] / Box );
 
 }
 
 }
 
 }
 
 }
 
 delta = BarCount - j - 1;
 
 direction = Ref( direction, - delta );
 
 Hi = Ref( PFH, -delta ) + Box / 2;
 
 Lo = Ref( PFL, -delta ) - Box / 2;
 
 Cl = IIf( direction == 1, Hi, Lo );
 
 Op = IIf( direction == 1, Cl - Box, Cl + Box );
 
 Graphcolor = IIf( direction == 1, ParamColor( "X_Color",colorBrightGreen ),
 
 ParamColor( "O_Color", colorRed ) );
 
 PlotOHLC( Op, Hi, Lo, Cl, "", GraphColor , stylePointAndFigure | styleNoLabel,
0, 0 , shiftChart );
 
 PlotOHLC( Op, Hi, Lo, Cl, "", GraphColor , stylePointAndFigure | styleNoLabel,
0, 0 , shiftChart );
 
 Last = Ref( LastValue( C ), -( BarCount - 1 ) );
 
 Plot( Last, "", colorRed, styleNoLine | styleDots, 0 , 0,shiftLastClose );
 
 // selected value
 
 Value = IIf( direction > 0, SelectedValue( Hi ) - box / 2,SelectedValue( Lo )
+ box / 2 );
 

//----------------------------------------------------------
 
 // GRID CONSTRUCTION
 
 //----------------------------------------------------------
 
 PlotGridLines = ParamToggle( "PlotdGrid", "Yes! |No", 1 ) ;
 
 if ( PlotGridLines ==1)
 
 {
 
 begin = SelectedValue( BarIndex() );
 
 end = LastValue( BarIndex() );
 
 period = end - begin + 1;
 
 if ( begin < end )
 
 {
 
 ScreenHigh = LastValue( HHV( cl, period ) );
 
 ScreenLow = LastValue( LLV( Cl, period ) );
 
 top = LineArray( begin - shiftGrid, screenHigh, end, screenhigh, 0 ,
1 );
 
 Bot = LineArray( begin - shiftGrid, screenlow, end, screenLow, 0, 1 );
 
 Plot( top, "", gridColor, styleLine | styleNoLabel , 0, 0, shiftGrid );
 
 //Plot( bot, "", gridColor,styleLine|styleNoLabel, 0 , 0 , shiftGrid);
 
 VerticalGrid = IIf ( BarIndex() >= begin, IIf( direction == 1,
screenHigh,
 screenLow ), Null );
 
 Plot ( VerticalGrid, "", gridColor, styleStaircase | styleNoLabel,
0, 0, 1
 );
 
 format = 8.2;
 
 for ( n = LastValue( bot ); n < LastValue( top ) - 0.5*box; n = n +
box )
 
 {

 Plot( bot , "", gridColor, styleLine | styleNoLabel, 0, 0 , shiftGrid );
 
 text = NumToStr( LastValue( bot ) + 0.5 * box, format );
 
 xposition = BarCount + shiftPriceaxis;
 
 yPosition = LastValue( bot ) + 0.27 * box;
 
 PlotText( text, xPosition , yPosition, colorWhite );
 
 bot = bot + box;
 
 Graphcolor = IIf( direction == 1, ParamColor( "X_Color",
colorBrightGreen ),
 
 ParamColor( "O_Color", colorRed ) );
 
 PlotOHLC( Op, Hi, Lo, Cl, "", GraphColor , stylePointAndFigure | styleNoLabel,
0, 0 , shiftChart );
 
 }
 
 }
 
 }
 
 
 
 //----------------------------------------------------------
 
 // TITLE
 
 //----------------------------------------------------------
 
 Title = "\n" +
 
 " Instrument : " + Name() + FullName() + "\n " +
 
"Formula : " + " Point & Figure (High/Low Range)" + "\n " +
 
 "Box : " + NumToStr( Box, 4.4 ) + " " +
 
 "Reverse : " + NumToStr( Reverse, 2.0 ) + "\n " +
 
 "ATR : " + WriteVal( LastValue( ATR( 100 ) ), format = 4.4 );
 
 _SECTION_END();
 
I recently purchased AmiBroker and I was hoping someone could tell me how to download stock data history and have the stocks seperated in to their respective sectors?
 
I recently purchased AmiBroker and I was hoping someone could tell me how to download stock data history and have the stocks seperated in to their respective sectors?

What data source are you using?

Premium Data has scripts to automatically assign stocks to sectors etc.

http://www.premiumdata.net/

It's also possible to sort data into sectors with Bodhi Gold from Justdata too.

http://www.justdata.com.au

If you're using ASCII data then Amibroker now supports automatically importing sector data with your price and volume data. Scroll to the (near) bottom of the page below to the section titled "Making it automatic".

http://www.amibroker.com/guide/h_categories.html

Someone was providing a sector list for the ASX on the Amibroker list a few years ago but haven't noticed it being updated recently.
 
Thanks. I was hopeing I could do it through Yahoo for free.

Ok, I haven't any experience with Yahoo data but I think there's others here who use it. Amiquote is the automated importer for Yahoo data in Amibroker.

The bottom of the categories tutorial I posted above gives instructions on using it to assign stocks to the sector and industry groups however that only appears to be for US stocks. Not sure if there's an automated way for ASX stocks.

ASCII data is quite easy to manipulate so if you can find a list of stocks with their sector codes then it could be imported into Amibroker using the ASCII importer. Just be a matter of setting up the correct import parameters eg. allow no quote data etc.
 
Top