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

[amibroker] Re: Plotting Sine Waves using Time Axis



PureBytes Links

Trading Reference Links

Thank you Steve for this coding, it was just what i was looking for!

I have added some code to add commentary to the chart, to describe the
cycle, (ie Hard up, Topping, Down ) but have seem to hit a snag
somewhere.  
As im relativly new to ami code, I used the MACD Commentary example in
the ami guide ( http://www.amibroker.com/guide/h_commentary.html  ) as
a basis, made changes and learnt along the way. Unfortunatly, its not
producing the commentary on the chart like i hoped.

 
Here is the changed formula.  

/////// start code ///////

_SECTION_BEGIN("Cycles");
// Cycles

// set chart options

SetBarsRequired( 10000, 10000 );

SetChartOptions( 0, chartShowDates );

Periods = Param( "Cycle Pds", 13, 1, 252, 1 );

XShift = Param( "Shift L/R", 0, -252, 252, 1 ) / 3.14159^2;

XFactor = Param( "FT Freq", 1, 0, 2, 0.001 );

YFactor = Param( "FT Amp", 1, 0, 1, 0.01 );

Color = ParamColor( "Color", colorBlue );

// calc and plot wave

X = 2 * 3.14159 / Periods / XFactor;

Y = sin( Cum( X ) - XShift ) * YFactor;

FineTunedPds = Periods * XFactor;

Plot( Y, NumToStr( FineTunedPds, 0.2 ) + " Bar Cycle", Color, 
styleLine|styleLeftAxisScale|styleNoLabel );




Plot  ( Y, " This cycle is", Color, 
styleLine|styleLeftAxisScale|styleNoLabel );

 "This Cycle is" ;
   
   avgcond1 = ( Y > -.80) == 1.1 ;
	avgcond2 = ( Y > .20) == 1.2 ;
	avgcond3 = ( Y > .80) == 1.3 ;
	avgcond4 = ( Y < .99) == 1.4 ;


   avgcond5 = ( y < .80) == 1.5 ;
	avgcond6 = ( y < -.20) == 1.6 ;
	avgcond7 = ( y < -.80) == 1.7 ;
	avgcond8 = ( y > -.99) == 1.8 ;


    WriteIf( avgcond1 == 1.1,
    "Hard Up",
    WriteIf( avgcond2 == 1.2,
    "Hard Up-Slowing",
    WriteIf( avgcond3 == 1.3,
    "Topping", 
	WriteIf( avgcond4 == 1.4,
    "Topped-Turning", "") ) ) ) +


    WriteIf( avgcond5 == -1.5,
    "Hard Down",
    WriteIf( avgcond6 == -1.6,
    "Hard Down-Slowing",
    WriteIf( avgcond7 == -1.7,
    "Bottoming", 
	WriteIf( avgcond8 == -1.8,
    "Bottomed-Turning", "") ) ) ) ;



Plot( 0, "", Color,
styleLine|styleDashed|styleLeftAxisScale|styleNoLabel );

Plot( 1, "", Color, styleNoLine|styleLeftAxisScale|styleNoLabel );

Plot( -1, "", Color, styleNoLine|styleLeftAxisScale|styleNoLabel );

// calc and plot vertical lines for pivots

Ym1 = Ref( Y, -1 );

Yp1 = Ref( Y, 1 );

Peaks = Y > Ym1 AND Y > Yp1;

Troughs = Y < Ym1 AND Y < Yp1;

Pivots = IIf( Peaks, YFactor, IIf( Troughs, -YFactor, Null ) );

Plot( Pivots, "", Color, 
styleHistogram|styleDashed|styleLeftAxisScale|styleNoLabel );

Plot( -Pivots, "", Color, 
styleHistogram|styleDashed|styleLeftAxisScale|styleNoLabel );

//////  end code  /////////



One idea i had in mind was to have this formula over multiple cycles,
and then allocate more weighting to the longer cycles before coming up
with an overal cycle commentary/result of either Hard Up, Topping or
Hard Down or Bottoming.  So i guess a 'ranking system' type code would
work for that? ...

Im finding the more i discover ami code, the more powerful it becomes!

Anyways, thanks for your help,

Jeff



--- In amibroker@xxxxxxxxxxxxxxx, "Steve Dugas" <sjdugas@xxx> wrote:
>
> Hi - Here is a pretty flexible tool for plotting cycles / sine
waves, hope 
> it helps
> 
> Steve
> 
> ***************************************8
> 
> // Cycles
> 
> // set chart options
> 
> SetBarsRequired( 10000, 10000 );
> 
> SetChartOptions( 0, chartShowDates );
> 
> Periods = Param( "Cycle Pds", 13, 1, 252, 1 );
> 
> XShift = Param( "Shift L/R", 0, -252, 252, 1 ) / 3.14159^2;
> 
> XFactor = Param( "FT Freq", 1, 0, 2, 0.001 );
> 
> YFactor = Param( "FT Amp", 1, 0, 1, 0.01 );
> 
> Color = ParamColor( "Color", colorYellow );
> 
> // calc and plot wave
> 
> X = 2 * 3.14159 / Periods / XFactor;
> 
> Y = sin( Cum( X ) - XShift ) * YFactor;
> 
> FineTunedPds = Periods * XFactor;
> 
> Plot( Y, NumToStr( FineTunedPds, 0.2 ) + " Bar Cycle", Color, 
> styleLine|styleLeftAxisScale|styleNoLabel );
> 
> Plot( 0, "", Color,
styleLine|styleDashed|styleLeftAxisScale|styleNoLabel );
> 
> Plot( 1, "", Color, styleNoLine|styleLeftAxisScale|styleNoLabel );
> 
> Plot( -1, "", Color, styleNoLine|styleLeftAxisScale|styleNoLabel );
> 
> // calc and plot vertical lines for pivots
> 
> Ym1 = Ref( Y, -1 );
> 
> Yp1 = Ref( Y, 1 );
> 
> Peaks = Y > Ym1 AND Y > Yp1;
> 
> Troughs = Y < Ym1 AND Y < Yp1;
> 
> Pivots = IIf( Peaks, YFactor, IIf( Troughs, -YFactor, Null ) );
> 
> Plot( Pivots, "", Color, 
> styleHistogram|styleDashed|styleLeftAxisScale|styleNoLabel );
> 
> Plot( -Pivots, "", Color, 
> styleHistogram|styleDashed|styleLeftAxisScale|styleNoLabel );
> 
> 
> 
> ----- Original Message ----- 
> From: "jeff.feder" <jeff@xxx>
> To: <amibroker@xxxxxxxxxxxxxxx>
> Sent: Wednesday, October 01, 2008 8:11 AM
> Subject: [amibroker] Plotting Sine Waves using Time Axis
> 
> 
> > Hello,
> >
> > I have been studying the works of Hurst and Millard and have been
> > basing my trading system around the principle of Cycles.
> >
> > I have come accross several Sine Wave Formulas, which plot the waves
> > in relation to price.
> >
> > Has anyone constructed Sine Waves that plot based on time, ie. perfect
> > sine wave curve, and if so, how is this written in AB code?
> >
> > My theory was just to use these as guides as to what stage the
> > different cycles are, at a certain point in time.
> >
> > Thansk for your help,
> >
> > Jeff
> >





------------------------------------

**** IMPORTANT ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

*********************
TO GET TECHNICAL SUPPORT from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com
*********************

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html

*********************************
Yahoo! Groups Links

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

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> 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/