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

RE: [amibroker] Re: Elder's AutoEnvelope



PureBytes Links

Trading Reference Links

Hi,

 

I made changes to Lesmond’s code.  First, I changed two of the Params to ParamList.   For discrete values, IMO it’s a better solution.  Second, using this technique, it’s easier and cleaner to directly set “x” to a specific price array (field) from the parameter list. Third, the “IIF(Plot1…)” statements used “=”.  Unless I’m misunderstanding, it should be “==”.  Fourth, I added styleOwnScale to the plot statements if the Plot Signal was Long signals or All signals.  

 

I remmed out the original code where I made changes, so that you’d have a reference point.  The code still needs some tweaks, but this should improve the parameters and output a bit.

 

Regards,

 

Dan.

 

// User inputs

// pds=Input("EMA periods",1,252,21); // MetaStock code ("name",min,max,default)

pds = Param("EMA periods",21,2,252,1);

 

// pdsBak=Input("lookback periods",1,252,42);

pdsBak=Param("lookback periods",42,2,252,1);

 

// Price field

WC = TimeFrameGetPrice( "C", inWeekly, -1 ); // gives you previous week Open price

// x=IIf(x=1,O,IIf(x=2,H,IIf(x=3,L,IIf(x=5,WC,C)))); // is this incorrect?

//x=IIf(x==1,O,IIf(x==2,H,IIf(x==3,L,IIf(x==5,WC,C))));

 

// x=Input("use: Open=1, High=2, Low=3, Close=4, WClose=5",1,5,4);

//x=Param("use: Open=1, High=2, Low=3, Close=4, WClose=5",4,1,5,1);

sX = ParamList("Use Price Field:", "Open|High|Low|Close|Weekly Close", 3);

if (sX == "Open")

      x = O;

else if (sX == "High")

      x = H;

else if (sX == "Low")

      x = L;

else if (sX == "Close")

   x = C;

else if (sX == "Weekly Close")

      x = WC;

 

// Plot1=Input("[1]AutoEnvelope, [2]Long signals, [3]All signals",1,3,1);

//Plot1=Param("[1]AutoEnvelope, [2]Long signals, [3]All signals",1,1,3,1);

sPlot1 = ParamList("Plot Signals:", "AutoEnvelope|Long signals|All signals", 0);

if (sPlot1 == "AutoEnvelope")

      Plot1 = 1;

else if (sPlot1 == "Long signals")

      Plot1 = 2;

else if (sPlot1 == "All signals")

      Plot1  = 3;

 

// delay=Input("Entry/Exit signals delay",0,5,0);

delay=Param("Entry/Exit signals delay",0,0,5,1);

 

// Envelope bands

AvgX=EMA(x,pds);

hiAvg=HHV(H,pdsBak);

loAvg=LLV(L,pdsBak);

shift= EMA(IIf(hiAvg > AvgX, hiAvg - AvgX, AvgX - loAvg),pds);

UpperBand=AvgX+shift;

LowerBand=AvgX-shift;

 

// Envelope signals

In=Cross(x,LowerBand);

Out=Cross(x,UpperBand);

Init=Cum(In + Out > - 1)==1;

InInit=Cum(In)==1;

flag=BarsSince(Init OR In) < BarsSince(Init OR Out)+InInit;

signals=Ref((InInit AND Hold(InInit=0,2) OR flag AND Hold (flag=0,2)) -(flag=0 AND Hold(flag,2)),-delay);

 

// Plot envelope on price chart

//UpBand = IIf(Plot=1,UpperBand,IIf(Plot1=2,signals,In- Out));

//MidBand = IIf(Plot=1,AvgX,IIf(Plot1=2,0,0));

//LowBand = IIf(Plot=1,LowerBand,IIf(Plot1=2,signals,In- Out));

UpBand = IIf(Plot1==1,UpperBand,IIf(Plot1==2,signals,In- Out));

MidBand = IIf(Plot1==1,AvgX,IIf(Plot1==2,0,0));

LowBand = IIf(Plot1==1,LowerBand,IIf(Plot1==2,signals,In- Out));

 

if (Plot1 == 1)

      iStyleScale = 0;

else

      iStyleScale = styleOwnScale;

 

Plot(UpBand ,"UpperBand",colorBlueGrey, styleLine | iStyleScale);

Plot(MidBand , "MidleBand", colorGreen, styleLine | iStyleScale);

Plot(LowBand, "LowerBand", colorViolet, styleLine | iStyleScale);

Plot(C, "Price", colorDarkYellow, styleCandle);

 


From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of Lesmond V
Sent: Friday, January 27, 2006 4:21 AM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Re: Elder's AutoEnvelope

 

One more correction to John's correction posted before:

// x=Input("use: Open=1, High=2, Low=3, Close=4, WClose=5",1,5,4);
x=Param("use: Open=1, High=2, Low=3, Close=4, WClose=5",4,1,5,1);

Now the resulting chart looks better. Here is the code with all corrections. I've changed the colours a bit so everything is clearly seen on a chart with both white or black background. Can someone compare it with MetaStock if nothing else is missing here:

/*******************************/
//Elder's AutoEnvelope

// Dr A. Elder's AutoEnvelope interpretation v1.0
// modified for AmiBroker by Guno van Engel
// MS ref: www.elder.com/MetaStock/AutoEnvelope.htm
// MS ref: http://www.metastocktools.com
// AB ref: http://finance.groups.yahoo.com/group/amibroker/message/92783 + corrections

// User inputs
// pds=Input("EMA periods",1,252,21); // MetaStock code ("name",min,max,default)
pds = Param("EMA periods",21,2,252,1);

// pdsBak=Input("lookback periods",1,252,42);
pdsBak=Param("lookback periods",42,2,252,1);

// x=Input("use: Open=1, High=2, Low=3, Close=4, WClose=5",1,5,4);
x=Param("use: Open=1, High=2, Low=3, Close=4, WClose=5",4,1,5,1);

// Plot1=Input("[1]AutoEnvelope, [2]Long signals, [3]All signals",1,3,1);
Plot1=Param("[1]AutoEnvelope, [2]Long signals, [3]All signals",1,1,3,1);

// delay=Input("Entry/Exit signals delay",0,5,0);
delay=Param("Entry/Exit signals delay",0,0,5,1);

// Price field
WC = TimeFrameGetPrice( "C", inWeekly, -1 ); // gives you previous week Open price
// x=IIf(x=1,O,IIf(x=2,H,IIf(x=3,L,IIf(x=5,WC,C)))); // is this incorrect?
x=IIf(x==1,O,IIf(x==2,H,IIf(x==3,L,IIf(x==5,WC,C))));

// Envelope bands
AvgX=EMA(x,pds);
hiAvg=HHV(H,pdsBak);
loAvg=LLV(L,pdsBak);
shift= EMA(IIf(hiAvg > AvgX, hiAvg - AvgX, AvgX - loAvg),pds);
UpperBand=AvgX+shift;
LowerBand=AvgX-shift;

// Envelope signals
In=Cross(x,LowerBand);
Out=Cross(x,UpperBand);
Init=Cum(In + Out > - 1)==1;
InInit=Cum(In)==1;
flag=BarsSince(Init OR In) < BarsSince(Init OR Out)+InInit;
signals=Ref((InInit AND Hold(InInit=0,2) OR flag AND Hold (flag=0,2)) -(flag=0 AND Hold(flag,2)),-delay);

// Plot envelope on price chart
UpBand = IIf(PPlot=1,UpperBand,IIf(Plot1=2,signals,In- Out));
MidBand = IIf(PPlot=1,AvgX,IIf(Plot1=2,0,0));
LowBand = IIf(PPlot=1,LowerBand,IIf(Plot1=2,signals,In- Out));

Plot(UpBand ,"UpperBand",colorBlueGrey, styleLine);
Plot(MidBand , "MidleBand", colorGreen, styleLine);
Plot(LowBand, "LowerBand", colorViolet, styleLine);
Plot(C, "Price", colorDarkYellow, styleCandle);
/*******************************/

--- In amibroker@xxxxxxxxxxxxxxx, "ricko8294_98" <ricko@xxxx> wrote:
>
> also I think the line
> x=IIf(x=1,O,IIf(x=2,H,IIf(x=3,L,IIf(x=5,WC,C))));
>  should read
> x=IIf(x==1,O,IIf(x==2,H,IIf(x==3,L,IIf(x==5,WC,C))));
> Rick
>
> --- In amibroker@xxxxxxxxxxxxxxx, "John" <jar5499297@xxxx> wrote:
> >
> > Guno,
> >
> > Your Param's are incorrect.
> > In MS, Input("Prompt Text",Min,Max,default)
> > In Ami, Param(( ''name'', default, min, max, step, sincr = 0 )
> >
> > So your formula will change from:
> >
> > //{ User inputs }
> > //pds=Input("EMA periods",1,252,21);
> > pds = Param("EMA periods", 1, 252, 21);
> >
> > //pdsBak=Input("lookback periods",1,252,42);
> > pdsBak=Param("lookback periods",1,252,42);
> >
> > //x=Input("use: Open=1, High=2, Low=3, Close=4, WClose=5",1,5,4);
> > x=Param("use: Open=1, High=2, Low=3, Close=4, WClose=5",1,5,4);
> >
> > //Plot1=Input("[1]AutoEnvelope, [2]Long signals, [3]All
> > signals",1,3,1);
> > Plot1=Param("[1]AutoEnvelope, [2]Long signals, [3]All
> > signals",1,3,1);
> >
> > //delay=Input("Entry/Exit signals delay",0,5,0);
> > delay=Param("Entry/Exit signals delay",0,5,0);
> >
> > To:
> >
> > pds = Param("EMA periods",21,2,252,2);
> > pdsBak = Param("lookback periods",42,2,252,2);
> > x = Param("use: Open=1, High=2, Low=3, Close=4, WClose=5",1,1,5,4);
> > Plot1 = Param("[1]AutoEnvelope, [2]Long signals, [3]All
> > signals",1,1,3,1);
> > delay = Param("Entry/Exit signals delay",0,0,5,1);
> >
> >
> > Hope this helps,
> >
> > John
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "gunovanengel"
> <gunovanengel@xxxx>
> > wrote:
> > >
> > > Hi Swingtrader
> > >
> > > Here my Amibroker interpretation of the Code
> > >
> > > Kindest Regards
> > > Guno
> > >
> > > //====================
> > > //Elder's AutoEnvelope
> > > //====================
> > > //---8<---------------------------
> > >
> > > //{Dr A. Elder's AutoEnvelope interpretation v1.0}
> > > //{ www.elder.com/MetaStock/AutoEnvelope.htm }
> > > //{ http://www.metastocktools.com }
> > > //Modified for AmiBroker by Guno van Engel
> > >
> > > //{ User inputs }
> > > //pds=Input("EMA periods",1,252,21);
> > > pds = Param("EMA periods", 1, 252, 21);
> > >
> > > //pdsBak=Input("lookback periods",1,252,42);
> > > pdsBak=Param("lookback periods",1,252,42);
> > >
> > > //x=Input("use: Open=1, High=2, Low=3, Close=4, WClose=5",1,5,4);
> > > x=Param("use: Open=1, High=2, Low=3, Close=4, WClose=5",1,5,4);
> > >
> > > //Plot1=Input("[1]AutoEnvelope, [2]Long signals, [3]All
> > > signals",1,3,1);
> > > Plot1=Param("[1]AutoEnvelope, [2]Long signals, [3]All
> > > signals",1,3,1);
> > >
> > > //delay=Input("Entry/Exit signals delay",0,5,0);
> > > delay=Param("Entry/Exit signals delay",0,5,0);
> > >
> > > //{ Price field }
> > > WC = TimeFrameGetPrice( "C", inWeekly, -1 ); // gives you
> previous
> > > week Open price
> > > x=IIf(x=1,O,IIf(x=2,H,IIf(x=3,L,IIf(x=5,WC,C))));
> > >
> > > //{ Envelope bands }
> > > AvgX=EMA(x,pds);
> > > hiAvg=HHV(H,pdsBak);
> > > loAvg=LLV(L,pdsBak);
> > > shift= EMA(IIf(hiAvg > AvgX, hiAvg - AvgX, AvgX - loAvg),pds);
> > > UpperBand=AvgX+shift;
> > > LowerBand=AvgX-shift;
> > >
> > > //{ Envelope signals }
> > > In=Cross(x,LowerBand);
> > > Out=Cross(x,UpperBand);
> > > Init=Cum(In + Out > - 1)==1;
> > > InInit=Cum(In)==1;
> > > flag=BarsSince(Init OR In) < BarsSince(Init OR Out)+InInit;
> > > signals=Ref((InInit AND Hold(InInit=0,2) OR flag AND Hold
> > > (flag=0,2)) -(flag=0 AND Hold(flag,2)),-delay);
> > >
> > > //{ Plot envelope on price chart }
> > > UpBand  = IIf(PPlot=1,UpperBand,IIf(Plot1=2,signals,In-Out));
> > > MidBand = IIf(PPlot=1,AvgX,IIf(Plot1=2,0,0));
> > > LowBand = IIf(PPlot=1,LowerBand,IIf(Plot1=2,signals,In-Out));
> > >
> > > Plot(UpBand  ,"UpperBand",colorBlack,styleLine | styleThick);
> > > Plot(MidBand , "MidleBand", colorBlack, styleLine | styleThick  );
> > > Plot(LowBand, "LowerBand", colorBlack, styleLine | styleThick  );
> > > Plot(C , "Price", colorBlack, styleCandle | styleThick  );
> > >
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx, "swingtrader_se"
> > > <swingtrader_se@xxxx> wrote:
> > > >
> > > > Can anyone please translate this formula to Amibroker?
> > > > I would be very grateful...
> > > > ====================
> > > > Elder's AutoEnvelope
> > > > ====================
> > > > ---8<---------------------------
> > > >
> > > > {Dr A. Elder's AutoEnvelope interpretation v1.0}
> > > > { www.elder.com/MetaStock/AutoEnvelope.htm }
> > > > { http://www.metastocktools.com }
> > > >
> > > > { User inputs }
> > > > pds:=Input("EMA periods",1,252,21);
> > > > pdsBak:=Input("lookback periods",1,252,42);
> > > > x:=Input("use: Open=1, High=2, Low=3, Close=4, WClose=5",1,5,4);
> > > > plot:=Input("[1]AutoEnvelope, [2]Long signals, [3]All
> > > > signals",1,3,1);
> > > > delay:=Input("Entry/Exit signals delay",0,5,0);
> > > >
> > > > { Price field }
> > > > x:=If(x=1,O,If(x=2,H,If(x=3,L,If(x=5,WC(),C))));
> > > >
> > > > { Envelope bands }
> > > > Avg:=Mov(x,pds,E);
> > > > hiAvg:=HHV(H,pdsBak);
> > > > loAvg:=LLV(L,pdsBak);
> > > > shift:=
> > > >  Mov(If(hiAvg>Avg,hiAvg-Avg,Avg-loAvg),pds,E);
> > > > UpperBand:=Avg+shift;
> > > > LowerBand:=Avg-shift;
> > > >
> > > > { Envelope signals }
> > > > In:=Cross(x,LowerBand);
> > > > Out:=Cross(x,UpperBand);
> > > > Init:=Cum(In+Out>-1)=1;
> > > > InInit:=Cum(In)=1;
> > > > flag:=BarsSince(Init OR In)
> > > >  <BarsSince(Init OR Out)+InInit;
> > > > signals:=Ref((InInit AND Alert(InInit=0,2)
> > > >   OR flag AND Alert(flag=0,2))
> > > >    -(flag=0 AND Alert(flag,2)),-delay);
> > > >
> > > > { Plot envelope on price chart }
> > > > If(plot=1,UpperBand,If(plot=2,signals,In-Out));
> > > > If(plot=1,Avg,If(plot=2,0,0));
> > > > If(plot=1,LowerBand,If(plot=2,signals,In-Out))
> > > >
> > > > ---8<---------------------------
> > > >
> > > >
> > > > http://www.metastocktools.com
> > > >
> > >
> >
>







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