PureBytes Links
Trading Reference Links
|
Very useful. thank you all!
--- In amibroker@xxxxxxxxxxxxxxx, "Dan Clark" <dan_public@xxx> wrote:
>
> Steve and jnz,
>
>
>
> Here's some code that NW Trader provided. I converted it to a
function.
> The first portion of the code is the function. The second portion
is the
> chart section that calls it.
>
>
>
> It looks bad below, so copy it to AB's code editor and the tables
should be
> correct. Also, watch out for line wraps.
>
>
>
> Regards,
>
>
>
> Dan.
>
>
>
>
>
> function PlotLinearRegression(CurSymbolPrice, PlotLRBool,
PlotLRSD1Bool,
> PlotLRSD2Bool,
>
>
> DaysBack, Shift, LRSTitleUpColor, LRSTitleDownColor, LRColor,
LRStyle,
>
>
> LRSDPeriods, LRSDColor, LRSDStyle,
>
> LRSDPeriods2, LRSDColor2, LRSDStyle2,
>
>
> SmoothPds
>
>
)
>
> {
>
> //P = ParamField("Price
> field",-1);
>
>
>
> // =============================== Math Formula
> =============================================================
>
>
>
> x = Cum(1);
>
> lastx = LastValue( x ) - shift;
>
> aa = LastValue( Ref(LinRegIntercept( CurSymbolPrice ,
Daysback),
> -shift) );
>
> bb = LastValue( Ref(LinRegSlope( CurSymbolPrice ,
Daysback ), -shift)
> );
>
> y = Aa + bb * ( x - (Lastx - DaysBack +1 ) );
>
>
>
> LRSlope = LinRegSlope(
CurSymbolPrice ,
> Daysback) ;
>
> SlopeAngle = bb;
>
>
>
> //==================Plot the Linear Regression Line
> ==========================================================
>
> //LRColor = ParamColor("LR Color", colorCycle );
>
> //LRStyle = ParamStyle("LR Style");
>
>
>
> LRLine = IIf( x > (lastx - Daysback) AND BarIndex() <
Lastx, y, Null
> );
>
>
>
> Plot( LRLine , "LinReg", LRCOLOR, LRSTyle +
styleNoLabel ); //
> styleDots );
>
> // Plot( LRLine , "LinReg", LRCOLOR, LRSTYLE|styleLine +
styleNoRescale
> + styleNoTitle + styleNoLabel ); // styleDots );
>
> // ========================== Plot 1st SD Channel
> ===============================================================
>
>
>
> LRSDPeriods = Param("Standard Deviation", 1.5, 0, 6, 0.1);
>
> SD = LRSDPeriods/2;
>
>
>
> width = LastValue( Ref(SD * StDev(CurSymbolPrice ,
Daysback),-shift)
> ); // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET
>
> SDU = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx,
y+width ,
> Null ) ;
>
> SDL = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-
width ,
> Null ) ;
>
>
>
> //LRSDColor = ParamColor("SD Color", colorCycle );
>
> //LRSDStyle = ParamStyle("SD Style");
>
>
>
> Plot( SDU , "Upper Lin Reg", LRSDColor, LRSDStyle +
styleNoRescale +
> styleNoTitle + styleNoLabel );
>
> Plot( SDL , "Lower Lin Reg", LRSDColor, LRSDStyle +
styleNoRescale +
> styleNoTitle + styleNoLabel);
>
>
>
>
>
> // ========================== Plot 2d SD Channel
> ===============================================================
>
> ATRRaw = ATR(Daysback);
>
> ATRMultiplier = Param("ATR Multiplier", 1, .1, 10, .1, .1);
>
> //Make this a single value to
>
> ATRWeighted = ATRRaw * ATRMultiplier;
>
>
>
> //LRSDPeriods2 = Param("2d Standard Deviation", 2.0, 0, 6,
0.1);
>
> SD2 = LRSDPeriods2/2;
>
>
>
> //width2 = ATRWeighted * LastValue( Ref(SD2*StDev(p,
> Daysback),-shift) ); // THIS IS WHERE THE WIDTH OF THE CHANELS IS
SET
>
> width2 = LastValue( Ref(SD2*StDev(CurSymbolPrice ,
Daysback),-shift)
> ); // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET
>
> SDU2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx,
y+width2 ,
> Null ) ;
>
> SDL2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-
width2 ,
> Null ) ;
>
>
>
> //LRSDColor2 = ParamColor("2 SD Color", colorCycle );
>
> //LRSDStyle2 = ParamStyle("2 SD Style");
>
>
>
> Plot( SDU2 , "Upper Lin Reg", LRSDColor2, LRSDStyle2 +
> styleNoRescale + styleNoTitle + styleNoLabel);
>
> Plot( SDL2 , "Lower Lin Reg", LRSDColor2, LRSDStyle2 +
> styleNoRescale + styleNoTitle + styleNoLabel );
>
> // ============================ End Indicator Code
> ==============================================================
>
>
>
> return SlopeAngle;
>
>
>
> }
>
>
>
>
>
> _SECTION_BEGIN("Linear Regression");
>
> // Linear Regression Line with 2 Standard Deviation Channels
Plotted Above
> and Below
>
> // Written by Patrick Hargus, with critical hints from Marcin
Gorzynski,
> Amibroker.com Technical Support
>
> // Designed for use with AB 4.63 beta and above, using drag
and drop
> feature.
>
> // Permits plotting a linear regression line of any price field
available
> on the chart for a period determined by the user.
>
> // 2 Channels, based on a standard deviation each determined by
the
> user, are plotted above and below the linear regression line.
>
> // A look back feature is also provided for examining
how the
> indicator would have appeared on a chart X periods in the past.
>
>
>
> CurDatabase = GetDatabaseName();
>
> if (CurDatabase == "InteractiveBrokers")
>
> {
>
> DefaultLRPeriod = 400;
>
> MinLRPeriod = 10;
>
> MaxLRPeriod = 1400;
>
> IncrementLRPeriod = 10;
>
> }
>
> else
>
> {
>
> DefaultLRPeriod = 21;
>
> MinLRPeriod = 1;
>
> MaxLRPeriod = 200;
>
> IncrementLRPeriod = 1;
>
> }
>
>
>
> PlotLRSD1Bool = ParamToggle("Plot LR Std Dev Narrow?",
> "No|Yes", 1);
>
> PlotLRSD2Bool = ParamToggle("Plot Std Dev
Wide?", "No|Yes", 1);
>
>
>
>
> Daysback = Param("Period for Liner Regression
> Line",DefaultLRPeriod,MinLRPeriod,MaxLRPeriod ,IncrementLRPeriod);
>
> shift = Param("Look back period",0,0,240,1);
>
> LRSTitleUpColor = ParamColor("LR Slope Title Up Color",
colorLime );
>
> LRSTitleDownColor = ParamColor("LR Slope Title Down Color",
colorRed );
>
>
>
> LRColor = ParamColor("LR Color",
colorCycle );
>
> LRStyle = ParamStyle("LR Style");
>
>
>
> LRSDPeriods = Param("LR Std Dev Wide", 1.5, 0, 6, 0.1);
>
> LRSDColor = ParamColor("SD Color", colorCycle );
>
> LRSDStyle = ParamStyle("SD Style");
>
>
>
> LRSDPeriods2 = Param("Std Dev Narrow", 2.0, 0, 6, 0.1);
>
> LRSDColor2 = ParamColor("2 SD Color", colorCycle );
>
> LRSDStyle2 = ParamStyle("2 SD Style");
>
>
>
>
>
> //Init
>
> CurSymbolPrice = 0;
>
>
>
> if ( PlotLRBool
>
> AND PlotSymbolBool
>
> AND CurSymbolType != "NewHiLow"
>
> AND CurSymbolType != "DMF"
>
> AND CurSymbolType != "AD"
>
> )
>
> {
>
> //First get the Current Symbol price that we are using
>
> if ( CurSymbolType == "Price"
>
> OR CurSymbolType == "Index"
>
> OR CurSymbolType == "MutualFund")
>
> {
>
> CurSymbolPrice = C;
>
> }
>
>
>
> if (CurSymbolType == "DMF")
>
> {
>
> CurSymbolPrice = C ;
>
> CurSymbolPrice = EMA(CurSymbolPrice ,
SmoothPds);
>
> }
>
> else if (CurSymbolType == "NewHiLow")
>
> {
>
> CurSymbolPrice = 0 ;
>
> }
>
> else if (CurSymbolType == "AD")
>
> {
>
> AdvancingCount = C;
>
> DecliningCount = O;
>
> AdvancingVolume = H;
>
> DecliningVolume = L;
>
>
>
> if (ADVolumeBool) //PlotVolume
>
> {
>
> ADAdvancing = AdvancingVolume;
>
> ADDeclining = DecliningVolume;
>
> }
>
> else
>
> {
>
> ADAdvancing = AdvancingCount;
>
> ADDeclining = DecliningCount;
>
> }
>
>
>
>
>
> CurSymbolPrice = ADAdvancing - ADDeclining;
>
> }
>
> //Title = NumToStr(DecliningCount);
>
> LRSlopeAngle = PlotLinearRegression(CurSymbolPrice,
PlotLRBool,
> PlotLRSD1Bool, PlotLRSD2Bool,
>
>
> DaysBack, Shift, LRSTitleUpColor, LRSTitleDownColor, LRColor,
LRStyle,
>
>
> LRSDPeriods, LRSDColor, LRSDStyle,
>
> LRSDPeriods2, LRSDColor2, LRSDStyle2,
>
>
> SmoothPds);
>
>
>
> }
>
>
>
>
>
>
>
> _SECTION_END();
>
>
>
> _____
>
> From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx]
On Behalf
> Of Steve Dugas
> Sent: Saturday, February 04, 2006 12:11 PM
> To: amibroker@xxxxxxxxxxxxxxx
> Subject: Re: [amibroker] Re: Another question about how to use
LinearReg()
>
>
>
> OK...Could you show me how you would do this? Draw the line I
mean...
>
> Steve
>
> ----- Original Message -----
> From: "Fred" <ftonetti@xxx>
> To: <amibroker@xxxxxxxxxxxxxxx>
> Sent: Saturday, February 04, 2006 2:49 PM
> Subject: [amibroker] Re: Another question about how to use LinearReg
()
>
>
> > It is ALSO for drawing straight lines around which one can plot
among
> > other things such as parallel lines at +/- n Standard
Deviations ...
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "Steve Dugas" <sjdugas@> wrote:
> >>
> >> Hi,
> >>
> >> LinearReg is not for drawing straight lines - it is built by
> > plotting the
> >> endpoints of a LinReg line as it shifts forward through time.
Use
> > it like a
> >> moving average - it hugs the price ( or whatever ) very tightly.
> >>
> >> Steve
> >>
> >> ----- Original Message -----
> >> From: "jnz88" <jnz88@>
> >> To: <amibroker@xxxxxxxxxxxxxxx>
> >> Sent: Saturday, February 04, 2006 11:55 AM
> >> Subject: [amibroker] Another question about how to use LinearReg
()
> >>
> >>
> >> > There is a library item in AFL libreary showing how to draw
> > linear reg
> >> > line without using LinearReg() function.
> >> >
> >> > Could anybody show me how to use LinearReg() to do the same
> > thing. This
> >> > could help me to understand further about this function
> >> >
> >> > thanks,
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > 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
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >>
> >
> >
> >
> >
> >
> >
> >
> > 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
> >
> >
> >
> >
> >
> >
> >
>
>
>
> 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
>
>
>
>
>
>
> SPONSORED LINKS
>
>
> Investment
> <http://groups.yahoo.com/gads?
t=ms&k=Investment+management+software&w1=Inves
>
tment+management+software&w2=Real+estate+investment+software&w3=Invest
ment+p
>
roperty+software&w4=Software+support&w5=Real+estate+investment+analysi
s+soft
> ware&w6=Investment+software&c=6&s=200&.sig=_XXUzbE9l5lGlZNcMu4KNQ>
> management software
>
> Real
> <http://groups.yahoo.com/gads?
t=ms&k=Real+estate+investment+software&w1=Inve
>
stment+management+software&w2=Real+estate+investment+software&w3=Inves
tment+
>
property+software&w4=Software+support&w5=Real+estate+investment+analys
is+sof
>
tware&w6=Investment+software&c=6&s=200&.sig=5_sgDczz3ArKGMtJ9tFSJA>
estate
> investment software
>
> Investment
> <http://groups.yahoo.com/gads?
t=ms&k=Investment+property+software&w1=Investm
>
ent+management+software&w2=Real+estate+investment+software&w3=Investme
nt+pro
>
perty+software&w4=Software+support&w5=Real+estate+investment+analysis+
softwa
> re&w6=Investment+software&c=6&s=200&.sig=_N6zcwefgp4eg5n6oX5WZw>
property
> software
>
>
> Software
> <http://groups.yahoo.com/gads?
t=ms&k=Software+support&w1=Investment+manageme
>
nt+software&w2=Real+estate+investment+software&w3=Investment+property+
softwa
>
re&w4=Software+support&w5=Real+estate+investment+analysis+software&w6=
Invest
> ment+software&c=6&s=200&.sig=MJ2jP31F3n64RDZkDadU8w> support
>
> Real
> <http://groups.yahoo.com/gads?
t=ms&k=Real+estate+investment+analysis+softwar
>
e&w1=Investment+management+software&w2=Real+estate+investment+software
&w3=In
>
vestment+property+software&w4=Software+support&w5=Real+estate+investme
nt+ana
>
lysis+software&w6=Investment+software&c=6&s=200&.sig=GmF8PlAJASx0wrSaX
5-Zlw>
> estate investment analysis software
>
> Investment
> <http://groups.yahoo.com/gads?
t=ms&k=Investment+software&w1=Investment+manag
>
ement+software&w2=Real+estate+investment+software&w3=Investment+proper
ty+sof
>
tware&w4=Software+support&w5=Real+estate+investment+analysis+software&
w6=Inv
> estment+software&c=6&s=200&.sig=aMgGsKT4w29dMAYUzQUKzg> software
>
>
>
> _____
>
> YAHOO! GROUPS LINKS
>
>
>
> * Visit your group "amibroker
> <http://groups.yahoo.com/group/amibroker> " on the web.
>
> * To unsubscribe from this group, send an email to:
> amibroker-unsubscribe@xxxxxxxxxxxxxxx
> <mailto:amibroker-unsubscribe@xxxxxxxxxxxxxxx?subject=Unsubscribe>
>
> * Your use of Yahoo! Groups is subject to the Yahoo!
> <http://docs.yahoo.com/info/terms/> Terms of Service.
>
>
>
> _____
>
------------------------ Yahoo! Groups Sponsor --------------------~-->
Try Online Currency Trading with GFT. Free 50K Demo. Trade
24 Hours. Commission-Free.
http://us.click.yahoo.com/RvFikB/9M2KAA/U1CZAA/GHeqlB/TM
--------------------------------------------------------------------~->
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
<*> 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/
|