logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Derek Worswick  
#1 Posted : Wednesday, September 21, 2016 2:50:12 PM(UTC)
Derek Worswick

Rank:: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 8/11/2005(UTC)
Posts: 104

Hi Equis Formula assistance I would like to be able to Plot the Standard Error Channel Formula below with Shift To the left of a number of selected Days i.e. {shift:=Input("Shift back Period Days",0,512,52) } Hoping you can oblige, thanking you in advance Best regards, Derek *code* { ========== 8< ========================= } Periods:=Input("Periods Length Channel ",20,1000,102); nd:= Input("number of deviations",0,10,2); {shift:=Input("Shift back Period Days",0,512,52) } end:=LastValue(Cum(1)); pt:=LastValue(LinearReg(C,Periods)); slope:=LastValue(LinRegSlope(C,Periods)); start:=BarsSince(Cum(1)>=end-(Periods-1)); center:=If(start=0,pt - (slope*(end-Cum(1))),0); dis:=nd*LastValue(STE( C, Periods)); { center+dis;} { center; } {center-dis; } If(Cum(1)=(end-(Periods-1)),(center+dis),center-dis); If(Cum(1)=(end-(Periods-1)),center-dis,center+dis); { ========================================== } {The second part of the formula below is just a repeat of the Formula above but the Periods divided by 2 for the half cycle} Periods:=LastValue(Round(Periods/2)); {shift:=Input("Lookback Period Days",0,512,52) } end:=LastValue(Cum(1)); pt:=LastValue(LinearReg(C,Periods)); slope:=LastValue(LinRegSlope(C,Periods)); start:=BarsSince(Cum(1)>=end-(Periods-1)); center:=If(start=0,pt - (slope*(end-Cum(1))),0); dis:=nd*LastValue(STE( C, Periods)); { center+dis;} { center; } {center-dis; } If(Cum(1)=(end-(Periods-1)),(center+dis),center-dis); If(Cum(1)=(end-(Periods-1)),center-dis,center+dis); Standard Error Channel with shift.docx */code*
MS Support  
#2 Posted : Thursday, September 22, 2016 7:49:37 PM(UTC)
MS Support

Rank: Advanced Member

Groups: Moderators, Registered, Registered Users, Subscribers
Joined: 10/8/2010(UTC)
Posts: 1,960

Thanks: 92 times
Was thanked: 155 time(s) in 150 post(s)
Hi,

Official formula assistance is only provided via https://www.metastock.co...s/customformulaform.aspx

The forum is set up to support assistance among users. I am not a formula guru myself, but generally speaking when you want to shift something backward, you will add a positive REF function periods. You would wrap the REF function among the various outputs, i.e.:

ref(center+dis,shift);
ref(center,shift);
ref(center-dis,shift);

 

You would want to remove the curly brackets from around the shift input portion of the code as well.

Edited by user Thursday, September 22, 2016 7:51:29 PM(UTC)  | Reason: Not specified

Derek Worswick  
#3 Posted : Thursday, September 22, 2016 9:25:45 PM(UTC)
Derek Worswick

Rank:: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 8/11/2005(UTC)
Posts: 104

Hi, Thank you for your reply Below is the Amibroker code for the "Shift" I wish I want to achive to the Standard Channel The code Plots the "Shifted" Channels OK I hope you get the oode OK I had to alter the "Param" numbers of the Shift Link below:in case the code is corrupted on the internet http://www.traderji.co...on-trend-channels.htm l Best regards, Derek ================================ // 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. // BarIndex() is the same as Cum(1)-1 but is much faster than Cum(1) *code* Plot( C, "Close", colorBlue, styleBar | styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() ); P = ParamField("Price field",-1); Daysback = Param("Period for Liner Regression Line",21,1,240,1); shift = Param("Look back period",0.30,0,0,240,1); // =============================== Math Formula ================================ x = Cum(1); lastx = LastValue( x ) - shift; aa = LastValue( Ref(LinRegIntercept( p, Daysback), -shift) ); bb = LastValue( Ref(LinRegSlope( p, Daysback ), -shift) ); y = Aa + bb * ( x - (Lastx - DaysBack +1 ) ); // ==================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 ); // styleDots ); // ========================== Plot 1st SD Channel ============================== //SDP = Param("Standard Deviation", 1.5, 0, 6, 0.1);//1.5 default //SDP = Param("Standard Deviation" ,0.30, 0, 6, 0.1);//1.5 default SDP = Param("Standard Deviation" ,0.30, 0, 6, 0.1);//1.5 default SD = SDP/2; width = LastValue( Ref(SD*StDev(p, 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 ) ; SDColor = ParamColor("SD Color", colorCycle ); SDStyle = ParamStyle("SD Style"); Plot( SDU , "Upper Lin Reg", SDColor,SDStyle ); Plot( SDL , "Lower Lin Reg", SDColor,SDStyle ); // ============================ End Indicator Code ======== */code*

Edited by user Friday, September 23, 2016 3:10:37 PM(UTC)  | Reason: Info Note: BarIndex() is the same as Cum(1)-1 but is much faster than Cum(1)

Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.