Hi All,
Here is a sample code with a number
of options for managing the look of your charts. Maybe someone will
find some useful features that they can adapt . Try dropping it
twice on the same pane and then play around with the parameters - I like
the ability to manage multiple titles/lines from the params dialog. If
anyone can figure out how to *automatically* detect whether Title is already
defined or not, please let me know and I will add it to the code.
Thanks!
Steve
PS - Watch out
for line wrap.
// Filename: Price Current.afl
// Task: Plots price for current ticker.
// AA Settings: Chart only.
// -Apply To:
// -Range:
// -Button:
// Notes:
// set bars for QuickAFL
SetBarsRequired ( 100000, 100000 );
// get price fields
FieldName = ParamList(
"Field", "Open|High|Low|Close|Avg (HLC/3)|Avg (OHLC/4)|Avg
(OC/2)|Avg (HL/2)", 3 );
CompFieldName = ParamList( "- Versus",
"Open|High|Low|Close|Avg (HLC/3)|Avg
(OHLC/4)|Avg (OC/2)|Avg (HL/2)" );
CompFieldLB = Param(
"- Bars Ago", 0, 0, 10, 1
);
// translate field to plot
if ( FieldName == "Open" )
Field = Open;
else if ( FieldName == "High" )
Field = High;
else if ( FieldName == "Low" )
Field = Low;
else if ( FieldName == "Close" )
Field = Close;
else if ( FieldName == "Avg (HLC/3)" )
Field = Avg;
else if ( FieldName == "Avg (OHLC/4)" )
Field = ( Open + High + Low + Close ) /
4;
else if ( FieldName == "Avg (OC/2)" )
Field = ( Open + Close ) / 2;
else if ( FieldName == "Avg (HL/2)" )
Field = ( High + Low ) / 2;
// translate comparison field (for coloring indicator)
if ( CompFieldName == "Open" )
CompField = Open;
else if ( CompFieldName == "High" )
CompField = High;
else if ( CompFieldName == "Low" )
CompField = Low;
else if ( CompFieldName == "Close" )
CompField = Close;
else if ( CompFieldName == "Avg (HLC/3)" )
CompField = Avg;
else if ( CompFieldName == "Avg (OHLC/4)" )
CompField = ( Open + High + Low + Close ) /
4;
else if ( CompFieldName == "Avg (OC/2)" )
CompField = ( Open + Close ) / 2;
else if ( CompFieldName == "Avg (HL/2)" )
CompField = ( High + Low ) / 2;
// adjust CompField for lookback periods
CompField = Ref(
CompField, -CompFieldLB );
// get/set colors
UpColor = ParamColor(
"Up Color",
colorBlack );
DownColor = ParamColor(
"Down Color",
colorBlack );
UnchColor = ParamColor(
"Unch Color",
colorBlack );
Color = IIf( Field >
CompField, UpColor, IIf(
Field < CompField, DownColor, UnchColor ) );
// get/set style
>ParamStyle(
"Style",
styleCandle, maskAll );
// make adjustments for tickers without genuine continuous
quotes
if ( LastValue( Cum( High ) == Cum( Low ) OR High ==
Null ) )
{
if ( CompFieldLB
== 0 )
CompField = Ref(
CompField, -1 );
Color = IIf( Field >
CompField, UpColor, IIf(
Field < CompField, DownColor, UnchColor ) );
>styleDots;
}
// get/set charting options
SetChartOptions ( 0, chartShowDates|chartShowArrows
);
GraphXSpace = Param( "GraphXSpace",
0, 0, 25, 1 );
GraphZOrder = ParamToggle( "GraphZOrder",
"0|1"
);
if ( ParamToggle( "Default Name/Title", "Default Name|Title" ) )
UseTitle = True;
else
UseTitle = False;
if ( ParamToggle( "-
Start New Line?", "No|Yes" ) )
NewLine = "\n";
else
NewLine = "";
if ( ParamToggle( "- If
Using Title", "No Existing
Title/Overwrite Existing Title|Append To Existing Title ( Returns Error If None
)" ) )
AppendTitle = True;
else
AppendTitle = False;
// plot indicator/set title
if ( UseTitle )
{
Plot( Field, NewLine +
_SECTION_NAME() +
" (" + FieldName +
")", Color,
style|styleNoTitle );
if ( AppendTitle
)
_N( Title =
Title + NewLine + StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} O
%g, H %g, L %g, C %g (%.1f%%) {{VALUES}}",
Open, High, Low, Close, SelectedValue( ROC( C, 1 ) ) ) );
else
_N( Title =
NewLine + StrFormat(
"{{NAME}} - {{INTERVAL}} {{DATE}} O %g, H %g,
L %g, C %g (%.1f%%) {{VALUES}}",
Open, High, Low, Close, SelectedValue( ROC( C, 1 ) ) ) );
}
else
Plot( Field, NewLine +
_SECTION_NAME() +
" (" + FieldName +
")", Color, style
);
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For other support material please check also:
http://www.amibroker.com/support.html
YAHOO! GROUPS LINKS
|