PureBytes Links
Trading Reference Links
|
Greetings --
See if this is what you want:
////////////////////////////////////////////////
// from Ehlers, John F. Cybernetic Analysis for Stocks and Futures. Wiley. 2004. // Chapter 9, p. 107. Code on p. 111.
function varPeriodRSI( priceField, period ) { Chg = priceField - Ref( priceField, -1 ); pc = Max( Chg, 0 ); nc = Max( -Chg, 0 );
pa = AMA( pc, 1/period ); na = AMA( nc, 1/period );
return 100 * pa / ( pa + na ); }
SetBarsRequired(200, 0);
// Ehlers Dominant Cycle Period // from Ehlers, John F. Cybernetic Analysis for Stocks and Futures. Wiley. 2004. // Chapter 9, p. 107. Code on p. 111.
function CyclePeriod(array, alpha) // Figure 9.4 on p. 111 { smooth = (array + 2*Ref(array, -1) + 2*Ref(array, -2) + Ref(array, -3))/6;
// for(i = 0; i < 7; i++) cycle[i]=array[i]; // Initialize early values and as array
for(i = 0; i < 6; i++) { InstPeriod[i] = 0; // Initialize early values and as array DeltaPhase[i] = 0; cycle[i]=0; Period[i]=0; }
for(i = 6; i < BarCount; i++) { cycle[i] = (1 - .5*alpha)*(1 - .5*alpha)*(smooth[i] - 2*smooth[i-1] + smooth[i-2]) +
2*(1 - alpha)*cycle[i-1] - (1 - alpha)*(1 - alpha)*cycle[i-2]; Q1[i] = (.0962*cycle[i] + .5769*cycle[i-2] -.5769*cycle[i-4] - .0962*cycle[i-6])*(.5 + .08*InstPeriod[i-1]); I1[i] = cycle[i-3];
if(Q1[i] != 0 AND Q1[i-1] != 0)
DeltaPhase[i] = (I1[i]/Q1[i] - I1[i-1]/Q1[i-1])/(1 + I1[i]*I1[i-1]/(Q1[i]*Q1[i-1])); if(DeltaPhase[i] < 0.1) DeltaPhase[i] = 0.1; if(DeltaPhase[i] > 1.1) DeltaPhase[i] = 1.1;
//----- Speed up the median calculation by placing it inline
mlen = 5; for(k = mlen - 1; k >= 0; k--) {temparray[k] = DeltaPhase[i + k - (mlen - 1)];}
temp=0; for(k = mlen - 1; k > 0; k--) {for (j = mlen - 1; j > 0; j--) {if (temparray[j-1] > temparray[j])
{ temp = temparray[j-1]; temparray[j-1] = temparray[j]; temparray[j] = temp; } } } MedianDelta[i] = temparray[mlen - 1 - (mlen / 2)];
//----- End median calculation
if(MedianDelta[i] == 0) DC[i] = 15;
else DC[i] = 6.28318/MedianDelta[i] + .5;
InstPeriod[i] = .33*DC[i] + .67*InstPeriod[i-1]; Period[i] = .15*InstPeriod[i] + .85*Period[i-1]; } return Period; }
Med = (H+L)/2;
// CyclePeriod
CP = CyclePeriod(Med, .07); //Plot(CP, "CyclePeriod", colorRed, styleLine); // Graph0BarColor=IIf(CP>Ref(CP,-1),colorGreen,colorBlue);//----------------------------------------
Med = (H+L)/2;
// CyclePeriod CP = (CyclePeriod(Med, .07))/2;
//#include_once <varPeriodRSI.afl>
Vp = Varperiodrsi(C,LastValue(Cp)); VpSm = DEMA(Vp,3);
Buy = Cross(Vp,Vpsm); //Sell=Cross(vpsm,vp);
Sell = BarsSince(Buy) >=5;
Plot(C,"C",colorBlack,styleCandle); PlotShapes(Buy*shapeUpArrow+Sell*shapeDownArrow, IIf(Buy,colorGreen,colorRed));
Plot(Vp,"VPRSI", colorRed, styleLine|styleLeftAxisScale);
Plot(VpSm,"VPRSISM",colorGreen,styleLine|styleLeftAxisScale);
_SECTION_END();
/////////////////////////////////////////////
Thanks, Howard
www.quantitativetradingsystems.com
On Jan 17, 2008 4:30 PM, jeffro861 < jeffro861@xxxxxxxxx> wrote:
I'm still getting a blank in the chart.
thanks,
Jeff H.
// from Ehlers, John F. Cybernetic Analysis for Stocks and Futures.
Wiley. 2004.
// Chapter 9, p. 107. Code on p. 111.
function CyclePeriod(array, alpha)
// Figure 9.4 on p. 111
{
smooth = (array + 2*Ref(array, -1) + 2*Ref(array, -2) + Ref(array, -
3))/6;
// for(i = 0; i < 7; i++) cycle[i]=array[i]; // Initialize early
values and as array
for(i = 0; i < 6; i++)
{
InstPeriod[i] = 0; // Initialize early values and as array
DeltaPhase[i] = 0;
cycle[i]=0;
Period[i]=0;
}
for(i = 6; i < BarCount; i++)
{
cycle[i] = (1 - .5*alpha)*(1 - .5*alpha)*(smooth[i] - 2*smooth[i-
1] + smooth[i-2]) +
2*(1 - alpha)*cycle[i-1] - (1 - alpha)*(1 - alpha)
*cycle[i-2];
Q1[i] = (.0962*cycle[i] + .5769*cycle[i-2] -.5769*cycle[i-4] -
.0962*cycle[i-6])*(.5 + .08*InstPeriod[i-1]);
I1[i] = cycle[i-3];
if(Q1[i] != 0 AND Q1[i-1] != 0)
DeltaPhase[i] = (I1[i]/Q1[i] - I1[i-1]/Q1[i-1])/(1 + I1[i]*I1
[i-1]/(Q1[i]*Q1[i-1]));
if(DeltaPhase[i] < 0.1) DeltaPhase[i] = 0.1;
if(DeltaPhase[i] > 1.1) DeltaPhase[i] = 1.1;
//----- Speed up the median calculation by placing it inline
mlen = 5;
for(k = mlen - 1; k >= 0; k--) {temparray[k] = DeltaPhase[i + k -
(mlen - 1)];}
temp=0;
for(k = mlen - 1; k > 0; k--)
{for (j = mlen - 1; j > 0; j--)
{if (temparray[j-1] > temparray[j])
{
temp = temparray[j-1];
temparray[j-1] = temparray[j];
temparray[j] = temp;
}
}
}
MedianDelta[i] = temparray[mlen - 1 - (mlen / 2)];
//----- End median calculation
if(MedianDelta[i] == 0) DC[i] = 15;
else DC[i] = 6.28318/MedianDelta[i] + .5;
InstPeriod[i] = .33*DC[i] + .67*InstPeriod[i-1];
Period[i] = .15*InstPeriod[i] + .85*Period[i-1];
}
return Period;
}
Med = (H+L)/2;
// CyclePeriod
CP = (CyclePeriod(Med, .07))/2;
#include_once <varPeriodRSI.afl>
Plot(Varperiodrsi(C,Cp),"CyclePeriod", colorRed, styleLine);
_SECTION_END();
> --- In amibroker@xxxxxxxxxxxxxxx, "jeffro861" <jeffro861@> wrote:
> >
> > Thanks for the response! This seems like it would work but when
I
> > try and plot this function it doesn't show anything, but at least
I'm
> > not getting an error message. Does anybody have any idea why?
>
> #include_once <varPeriodRSI.afl>
>
> Plot(varPeriodRSI(C,14),"",colorRed);
>
> period=IIf(C>O,5,25);
>
> Plot(varPeriodRSI((H+L)/2,period),"",colorBlue);
>
> The above code works for me, show the code you are using.
>
> Bill
>
__._,_.___
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 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
__,_._,___
|