[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Syntax Question



PureBytes Links

Trading Reference Links


Hi William,

I am trying to detect specific patterns in charts.  As you probably
know from technical analysis, a trend is confirmed as soon as you make
a higher low and break above the intermediate peak.  As well, a trend
ends as soon as you make a lower peak and break below the intermediate
 trough.  These statements are true for long term trends as well as
for intermediate trends within long term trends, etc.

I was hoping to test for the troughs and peaks based on the actual
charts intrinsic volitility.  But I apparently can't fool the
"percent" parameter in the peak and trough functions even using nested
iif statements to assign a percentage based on the ATR.  I have it
hard coded for now at 10%.  I added the zigag to the price chart so
that one can see the troughs and peaks as they develop.  But I
obviously don't understand the "parameter" function because it is
strictly following the chart pattern, and not the percent I have coded
in at the top of the formula. Maybe if I can get that to work, I can
use it to visually tweak the percent. Additionally, buy and sell
arrows should be appearing in places on the chart where they don't, so
something else is amiss as well.  I seem to be getting only the latest
signal unless the volume parameters aren't being met.  Not sure there.

For anyone interested, I also set a minimum threshold for 50 day
average daily volume, and require the 10 day daily volume to be 50%
higher than the 50 day number.  Price parameters can also be added if
so desired to remove low or high priced stocks.

There are more elegant ways to code this stuff than what I am doing,
but I'm still a beginner.  Anyway, if I thought I knew what I was
doing, I'd put it in the AFL Library.  The principle is a sound one. 
You are looking for stocks that are establishing uptrends on expanding
volume.  This is where big winners begin.  Right now it essentially
picking up stocks breaking out of pullback bases.  However, in October
to November time frame it would have picked up some great smallcap
winners.  My theory:  KISS.  Simple systems based on repeating
patterns, confirmed by earnings growth, small float, and insider
holdings are where the big winners lie.  Here is the code for anybody
that wants to use it or develop it further.  CAVEAT:  This code is
based on the latest Beta version, 4.68.2:

_SECTION_BEGIN("1-2-3");

// Set peak and trough percentage for tests.

Percent = 10;

// Calculate Volume parameters for minimum average volume and
expanding volume interest.

Volume_Condition_One =  IIf ( MA ( V, 50 ) > 100000, 1, 0 );
Volume_Condition_Two =  IIf ( MA ( V, 10 ) > 1.5 * MA ( V, 50 ), 1, 0 );

// Calculate the peaks and troughs for the buy and sell signals.

One_Peak_Back = LastValue ( Peak ( H, Percent, 1 ) );

Two_Peak_Back = LastValue ( Peak ( H, Percent, 2 ) );

One_Trough_Back = LastValue ( Trough ( L, Percent, 1 ) );
Two_Trough_Back = LastValue ( Trough ( L, Percent, 2 ) );

// Calculate the buy conditions.

Buy_Condition_One = IIf ( One_Trough_Back > Two_Trough_Back, 1, 0 );
Buy_Condition_Two = IIf ( C > One_Peak_Back, 1 , 0 );

// Calculate the sell conditions.

Sell_Condition_One = IIf ( L < One_Trough_Back, 1, 0 );

// Test for buy and sell signals.

Buy = ( Volume_Condition_One + Volume_Condition_Two +
Buy_Condition_One + Buy_Condition_Two) == 4;
Sell = Sell_Condition_One == 1;

Buy = ExRem ( Buy, Sell );
Sell = ExRem ( Sell, Buy );
_SECTION_END();

// Plot values of peaks and troughs.

_SECTION_BEGIN("Price1");
SetChartOptions(0,chartShowArrows);
Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo
%g, Close
%g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) );
GraphXSpace = 5;
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle |
ParamStyle("Style", styleCandle, maskPrice ) );
_SECTION_END();

_SECTION_BEGIN("MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 50, 2, 200, 1, 10 );
GraphXSpace = 5;
Plot( MA( V, Periods ), _DEFAULT_NAME(), ParamColor( "Color",
colorCycle ),
styleLeftAxisScale );
_SECTION_END();

_SECTION_BEGIN("Volume");
GraphXSpace = 5;
Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorBlueGrey ),
styleHistogram | styleOwnScale | styleThick | styleLeftAxisScale );
_SECTION_END();

_SECTION_BEGIN("MA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 200, 1, 10 );
GraphXSpace = 5;
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color",
colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

_SECTION_BEGIN("MA2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 200, 1, 10 );
GraphXSpace = 5;
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color",
colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

_SECTION_BEGIN("Zig");
GraphXSpace = 5;
P = ParamField ( "Price field", -1 );
Periods = Param ( "Periods", Percent, Percent, 200, 1, 10 );
Plot ( Zig ( ( ( H + L ) / 2 ), Periods ), _DEFAULT_NAME(),
ParamColor( "Color", colorCycle ), ParamStyle ( "Style" ) ); 
_SECTION_END();



--- In amibroker@xxxxxxxxxxxxxxx, William Peters <william@xxxx> wrote:
> Bret,
> 
> I get the impression you might be going about whatever your trying to
> do in the wrong way. Perhaps if you can briefly explain what it is you
> are trying to achieve then someone could suggest an approach.
> 
> You might get some ideas from this simplified example (variable
%change per ticker):
> 
> Range = 1;
> if ( Name() == "A" ) {
>    Range = 8;
> }
> else if ( Name() == "AAP" ) {
>    Range = 7;
> }
> 
> One_Peak_Back = LastValue( Peak( H, Range, 1 ) );
> Filter = Range != 1;
> 
> AddColumn( Close, "Close  " );
> AddColumn( Range, "Range  " );
> AddColumn( One_Peak_Back, "One_Peak_Back" );
> 
> 
> Regards,
> William Peters (AmiBroker Group Moderator)
> www.amitools.com
> 
> 
> 
> 
> Thursday, February 3, 2005, 11:37:21 PM, you wrote:
>   
> QRSA>  Thanks William.
> 
> QRSA>  I tried using nested iif statements to select a value for the
percent,
> QRSA>  but that still doesn't work.  I'll look around and see if I
can find
> QRSA>  this setup anywhere else.
> 
> QRSA>  Bret 
> 
> 
> QRSA>  --- In amibroker@xxxxxxxxxxxxxxx, William Peters
<william@xxxx> wrote:
>  >> Hi,
>  >> 
>  >> QRSA>  Range = round ( MA ( 100*ATR ( 50 ) / C, 10 ) );
>  >> 
>  >> The above statement returns an array of numbers when the Peak
> QRSA>  function requires a
>  >> non arrayed number for the middle argument.
>  >> 
>  >> 
>  >> Regards,
>  >> William Peters (AmiBroker Group Moderator)
>  >> www.amitools.com
>  >> 
>  >> 
>  >> 
>  >> 
>  >> Thursday, February 3, 2005, 9:22:13 PM, you wrote:
>  >>   
>  >> QRSA>  I have the following bit of code to find a peak and value
> QRSA>  based on
>  >> QRSA>  ATR.  For some reason, this gives me an error even though
I am
>  >> QRSA>  rounding the "Range" to be an integer value.  If I hardcode a
> QRSA>  percent
>  >> QRSA>  into the Peak function it works.  Anybody see the problem? 
> QRSA>  TIA, Bret
>  >> 
>  >> QRSA>  Range = round ( MA ( 100*ATR ( 50 ) / C, 10 ) );
>  >>   
>  >> QRSA>  One_Peak_Back = LastValue ( Peak ( H, Range, 1 ) );
> 
> 
> 
>   
> 
> QRSA>  Check AmiBroker web page at:
> QRSA> http://www.amibroker.com/
> 
> QRSA>  Check group FAQ at:
> QRSA> http://groups.yahoo.com/group/amibroker/files/groupfaq.html
> 
>     
> 
> QRSA> Yahoo! Groups Links
> QRSA> To visit your group on the web, go to:
> QRSA> http://groups.yahoo.com/group/amibroker/
> QRSA>   To unsubscribe from this group, send an email to:
> QRSA> amibroker-unsubscribe@xxxxxxxxxxxxxxx
> QRSA>   Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service.





------------------------ Yahoo! Groups Sponsor --------------------~--> 
What would our lives be like without music, dance, and theater?
Donate or volunteer in the arts today at Network for Good!
http://us.click.yahoo.com/Tcy2bD/SOnJAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/