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

Re: [amibroker] Re: Slow Stochastic moving buy-sell levels



PureBytes Links

Trading Reference Links

Thank you, As You and Dimitri have given me valuable information on this
subject. I have discontinued my journey into this subject.....for the
moment.

after producing;
graph0=ema(c,10);
graph1=ema(ema(c,10),10);

and comparing the values returned by the code above ,with the values of
My Custom EMA with Decay , I found them to be the same, How can this be
if I coded incorrectly.

One of my original questions was how to initialize the EMA.PREV
statement, when the code starts with the close.

Anyway, Thank you Tomasz;

Anthony

Tomasz Janeczko wrote:

> Dear Anthony, The reason is that you are using Ref( array, -1 ) for
> PREV.This is not correct. Ref() works via shifting the array
> back/forwards.You can not use it for self-referencing formulas like
> EMA is. Therefore your formula does not calculate correct EMA and this
> is thereason for the difference. MS's PREV works in such a way that
> the formula is re-evaluatedas many times as the number of bars loaded.
> This leads to extremely longexecution times. Best regards,Tomasz
> Janeczkoamibroker.com
>
> ----- Original Message -----
> From: Anthony Faragasso
> To: amibroker@xxxxxxxxxxxxxxx
> Sent: Monday, November 12, 2001 1:15 PM
> Subject: Re: [amibroker] Re: Slow Stochastic moving buy-sell
> levels
> Tomasz;
>
> See the Attached Image, There seems to be some Difference,
> that is why I questioned. When I placed the formula under
> your explanation, they appear to be the same.
>
> This is an 8 period EMA of the Close.
> graph0=EMA(c,8);
> ema_today = factor * close + ( 1 - factor ) *
> ema_yesterday. value1 =(Smooth*Close)+(Decay*EMA.PREV)
>
> after you find value from above code, do you then continue
> with...
> graph0=EMA(value1,8);
> Possibly that is why there is a difference in custom EMA and
> Ami EMA. Because I continued with the above.
>
> Also, I know there was Discussion , but how do I satisfy
> the( EMA.Prev)
>
> Thanks
> Anthony
>
> Tomasz Janeczko wrote:
>
> > Anthony, This is NOTHING new. I mean EACH exponential
> > moving average is calculated this way. This Decay factor
> > is in fact the STANDARD way of calculating EMA:ema_today =
> > factor * close + ( 1 - factor ) *
> > ema_yesterday.
> > =(Smooth*Close)+(Decay*EMA.PREV)
> >
> > your decay factor is (1-factor), when factor =
> > 2/(Period+1). This is a STANDARD EMA. There is no magic
> > here. AFL built in EMA works exactly like this.And as I
> > wrote before AMA function that takes factor parameter
> > allowsyou to create variable-period exponential moving
> > averages that worksagain with the same scheme. Best
> > regards,Tomasz Janeczkoamibroker.com
> >
> > ----- Original Message -----
> > From: Anthony Faragasso
> > To: amibroker@xxxxxxxxxxxxxxx
> > Sent: Monday, November 12, 2001 12:32 PM
> > Subject: Re: [amibroker] Re: Slow Stochastic
> > moving buy-sell levels
> > Dimitri;
> >
> > Thank you for the reply and direction.
> >
> > Question: Have you heard of applying a Decay
> > Factor to Exponential Moving Averages.
> >
> > Period(N)
> > Smooth Decay
> > 8
> > Formulas: =2/(Period+1)
> > =1-Smooth
> >
> > =(Smooth*Close)+(Decay*EMA.PREV)
> >
> > Glossary:
> >
> > SMA:n - Simple Moving Average of the last n
> > values. The first n-1 value of the average are
> > invalid because there are not enough values to
> > produce an answer.
> > EMA:n - Exponential Moving Average
> > Period - (n) the number of days in the moving
> > averages. The period may be varied by changing
> > the value in cell R2C6 - the graph and the
> > results will change automatically.
> > Smooth - Smoothing factor for an exponential
> > moving average. Factor is dreived from the
> > period of an equivalent simple moving average
> > needed to achieve the same amount of lag. This
> > factor is multiplied by the current source value
> > (SPX in this case).
> > Decay - the decay factor is the one's complement
> > of the smoothing factor. This factor is used to
> > weight the previous exponential moving average
> > value before they are combined.
> >
> > I have completed some code, maybe you could
> > evaluate, to see if this warrants any
> > discussion. Your opinions are valued.
> >
> > Anthony
> >
> > DIMITRIS TSOKAKIS wrote:
> >
> > > Begin at 5119, 5120 and then at 5161 messages
> > > of this list.
> > > DT
> > > --- In amibroker@xxxx, Anthony Faragasso
> > > <ajf1111@xxxx> wrote:
> > > > Hi Dimitri;
> > > >
> > > > Could you explain how you arrived at the Dbuy
> > > and Dsell numbers in
> > > your
> > > > formula.Were they produced by doing some
> > > optimization, if so, could
> > > you
> > > > supply the optimization.
> > > >
> > > >
> > > > /*Slow Stochastic moving buy-sell levels*/
> > > >
> > > > Dbuy=14;
> > > > Dsell=8;
> > > > X1=13;
> > > > MaxGraph=12;
> > > > ST3=StochK(X1);
> > > > ST33=StochD(X1);
> > > > Graph0=ST3;
> > > > Graph1=ST33;
> > > > AVST=MA(StochD(X1),100);
> > > > Graph9=AVST-Dbuy;Graph10=AVST+Dsell;
> > > > Graph8=avst;Graph8Style=8;Graph8BarColor=2;
> > > > Graph9Style=Graph10Style=8;
> > > > Graph9BarColor=Graph10BarColor=1;
> > > >
> > > > Thank you.
> > > > Anthony
> > >
> > > ------------------------ Yahoo! Groups Sponsor
> > >
> > >
> > >
> > >
> > > Your use of Yahoo! Groups is subject to
> > > http://docs.yahoo.com/info/terms/
> >
> > Your use of Yahoo! Groups is subject to the
> > Yahoo! Terms of Service.
> >
> > -------------------------------------------------
> >
> > /* Custom Exponential Moving Average */
> > /* with Decay Factor, coded by Anthony
> > Faragasso*/
> >
> > MaxGraph=8;
> >
> > pds=10; /* Custom EMA periods,and EMA standard,
> > you can change period*/
> > pds2=10;/* Simple MA periods , you can change
> > period*/
> >
> > Smooth=(2/(pds+1));
> > Decay=(1-smooth);
> >
> > /* set the P variable: O,H,L,C , your average
> > can be on any price variable */
> > P=C;
> >
> > P1=p;
> > Avg2=(Smooth*p)+(Decay*p1);/* this line should
> > read (smooth*p)+(decay*ema.prev)*/
> >
> > Avg3=EMA(Avg2,pds);
> >
> > Avg4=(Smooth*p)+(Decay*Ref(Avg3,-1));/* have I
> > satisfied that line Here*/
> >
> > Graph0=EMA(Avg4,pds);
> > Graph0Color=6;
> > Graph0Style=1; /* blue line , Custom EMA with
> > Decay*/
> >
> > Graph2=C;
> > Graph2Style=128;
> >
> > Graph3=MA(p,pds2);
> > Graph3Color=4; /*red line , Simple MA */
> >
> > Graph4=EMA(p,pds);
> > Graph4Color=2; /* white line , EMA standard */
> >
> > Title=Name()+" Custom EMA with Decay :Blue
> > "+"("+WriteVal(Graph0,format=1.2)+")"+" EMA
> > :White"+"("+WriteVal(Graph4,format=1.2)+")"+"
> > Simple MA :Red
> > "+"("+WriteVal(Graph3,format=1.2)+")"+" Close
> > :"+"("+WriteVal(Graph2,format=1.2)+")";
> >
> > Your use of Yahoo! Groups is subject to the Yahoo! Terms
> > of Service.
>
> -------------------------------------------------------------
>
> [Image]
>
>
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

--------------6866F381EC2F4E4C13D7A6B6
Content-Type: multipart/related;
boundary="------------D29543ECF2340A1EEC381854"

--------------D29543ECF2340A1EEC381854
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<body bgcolor="#FFFFFF">
Hi tomasz;
<p><b>Thank you</b>, As<b> You</b> and <b>Dimitri</b> have given me valuable
information on this subject. I have discontinued my journey into this subject.....for
the moment.
<p><b><u>after producing;</u></b>
<br>graph0=ema(c,10);
<br>graph1=ema(ema(c,10),10);
<p>and comparing the values returned by the code above ,with the values
of My Custom EMA with Decay , I found them to be the same, How can this
be if I coded incorrectly.
<p>One of my original questions was how to initialize the EMA.PREV statement,
when the code starts with the close.
<p>Anyway,&nbsp; Thank you Tomasz;
<p>Anthony
<p>Tomasz Janeczko wrote:
<blockquote TYPE=CITE>&nbsp;<font face="Arial"><font size=-1>Dear Anthony,</font></font>&nbsp;<font face="Arial"><font size=-1>The
reason is that you are using Ref( array, -1 ) for PREV.</font></font><font face="Arial"><font size=-1>This
is not correct.</font></font>&nbsp;<font face="Arial"><font size=-1>Ref()
works via shifting the array back/forwards.</font></font><font face="Arial"><font size=-1>You
can not use it for self-referencing formulas like EMA is.</font></font>&nbsp;<font face="Arial"><font size=-1>Therefore
your formula does not calculate correct EMA and this is the</font></font><font face="Arial"><font size=-1>reason
for the difference.</font></font>&nbsp;<font face="Arial"><font size=-1>MS's
PREV works in such a way that the formula is re-evaluated</font></font><font face="Arial"><font size=-1>as
many times as the number of bars loaded. This leads to extremely long</font></font><font face="Arial"><font size=-1>execution
times.</font></font>&nbsp;<font face="Arial"><font size=-1>Best regards,</font></font><font face="Arial"><font size=-1>Tomasz
Janeczko</font></font><font face="Arial"><font size=-1>amibroker.com</font></font>
<blockquote 
style="BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
<div style="FONT: 10pt arial">----- Original Message -----</div>

<div 
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><b>From:</b>
Anthony Faragasso</div>

<div style="FONT: 10pt arial"><b>To:</b> amibroker@xxxxxxxxxxxxxxx</div>

<div style="FONT: 10pt arial"><b>Sent:</b> Monday, November 12, 2001 1:15
PM</div>

<div style="FONT: 10pt arial"><b>Subject:</b> Re: [amibroker] Re: Slow
Stochastic moving buy-sell levels</div>
&nbsp;Tomasz;
<p>See the Attached Image, There seems to be some Difference, that is why
I questioned. When I placed the formula under your explanation, they appear
to be the same.
<p>This is an 8 period EMA of the Close.
<br>graph0=EMA(c,8);
<br>&nbsp;<font face="Arial"><font size=-1>ema_today = factor * close +
( 1 - factor ) * ema_yesterday.</font></font><b>&nbsp;&nbsp; value1&nbsp;&nbsp;
=(Smooth*Close)+(Decay*EMA.PREV)</b>
<p><b>after you find value from above code, do you then continue with...</b>
<br>graph0=EMA(<b>value1</b>,8);
<br>Possibly that is why there is a difference in custom EMA and Ami EMA.
Because I continued with the above.
<p>Also, I know there was Discussion , but how do I satisfy the( EMA.Prev)
<p>Thanks
<br>Anthony
<p>&nbsp;Tomasz Janeczko wrote:
<blockquote TYPE="CITE"><style></style>
<font face="Arial"><font size=-1>Anthony,</font></font>
<font face="Arial"><font size=-1>This is NOTHING new. I mean EACH exponential
moving average is calculated this way.</font></font> <font face="Arial"><font size=-1>This
Decay factor is in fact the STANDARD way of calculating EMA:ema_today =
factor * close + ( 1 - factor ) * ema_yesterday.</font></font><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
=(Smooth*Close)+(Decay*EMA.PREV)</b>
<p>&nbsp;<font face="Arial"><font size=-1>your decay factor is (1-factor),
when factor = 2/(Period+1).</font></font> <font face="Arial"><font size=-1>This
is a STANDARD EMA. There is no magic here.</font></font> <font face="Arial"><font size=-1>AFL
built in EMA works exactly like this.And as I wrote before AMA function
that takes factor parameter allowsyou to create variable-period exponential
moving averages that worksagain with the same scheme.</font></font> <font face="Arial"><font size=-1>Best
regards,Tomasz Janeczkoamibroker.com</font></font>
<blockquote 
style="BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
<div style="FONT: 10pt arial">----- Original Message -----</div>

<div 
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><b>From:</b>
Anthony Faragasso</div>

<div style="FONT: 10pt arial"><b>To:</b> amibroker@xxxxxxxxxxxxxxx</div>

<div style="FONT: 10pt arial"><b>Sent:</b> Monday, November 12, 2001 12:32
PM</div>

<div style="FONT: 10pt arial"><b>Subject:</b> Re: [amibroker] Re: Slow
Stochastic moving buy-sell levels</div>
&nbsp;Dimitri;
<p>Thank you for the reply and direction.
<p><b>Question:&nbsp;</b> Have you heard of applying a Decay Factor to
Exponential Moving Averages.
<p><b>Period(N)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Smooth&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Decay</b>
<br>&nbsp;&nbsp;&nbsp;&nbsp; <b>8</b>
<br><b>Formulas:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>
=2/(Period+1)</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>
=1-Smooth</b>
<p><b>&nbsp;=(Smooth*Close)+(Decay*EMA.PREV)</b>
<p><b>Glossary:</b>
<p><b>SMA:n </b>- Simple Moving Average of the last n values. The first
n-1 value of the average are invalid because there are not enough values
to produce an answer.
<br><b>EMA:n </b>- Exponential Moving Average
<br>Period - (n) the number of days in the moving averages.&nbsp; The period
may be varied by changing the value in cell R2C6 - the graph and the results
will change automatically.
<br><b>Smooth</b> - Smoothing factor for an exponential moving average.
Factor is dreived from the period of an equivalent simple moving average
needed to achieve the same amount of lag. This factor is multiplied by
the current source value (SPX in this case).
<br><u><b>Decay</b> </u>- the decay factor is the one's complement of the
smoothing factor.&nbsp; This factor is used to weight the previous exponential
moving average value before they are combined.
<p>I have completed some code, maybe you could evaluate, to see if this
warrants any discussion. Your opinions are valued.
<p>Anthony
<p>DIMITRIS TSOKAKIS wrote:
<blockquote TYPE="CITE">Begin at 5119, 5120 and then at 5161 messages of
this list.
<br>DT
<br>--- In amibroker@xxxx, Anthony Faragasso &lt;ajf1111@xxxx> wrote:
<br>> Hi Dimitri;
<br>>
<br>> Could you explain how you arrived at the Dbuy and Dsell numbers in
<br>your
<br>> formula.Were they produced by doing some optimization, if so, could
<br>you
<br>> supply the optimization.
<br>>
<br>>
<br>> /*Slow Stochastic moving buy-sell levels*/
<br>>
<br>> Dbuy=14;
<br>> Dsell=8;
<br>> X1=13;
<br>> MaxGraph=12;
<br>> ST3=StochK(X1);
<br>> ST33=StochD(X1);
<br>> Graph0=ST3;
<br>> Graph1=ST33;
<br>> AVST=MA(StochD(X1),100);
<br>> Graph9=AVST-Dbuy;Graph10=AVST+Dsell;
<br>> Graph8=avst;Graph8Style=8;Graph8BarColor=2;
<br>> Graph9Style=Graph10Style=8;
<br>> Graph9BarColor=Graph10BarColor=1;
<br>>
<br>> Thank you.
<br>> Anthony
<p>------------------------ Yahoo! Groups Sponsor ---------------------~-->
<br>Universal Inkjet Refill Kit $29.95
<br>Refill any ink cartridge for less!
<br>Includes black and color ink.
<br>http://us.click.yahoo.com/bAmslD/MkNDAA/ySSFAA/dkFolB/TM
<br>---------------------------------------------------------------------~->
<br>&nbsp;
<br>&nbsp;
<p>Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/</blockquote>
<tt>Your use of Yahoo! Groups is subject to the <a href="http://docs.yahoo.com/info/terms/";>Yahoo!
Terms of Service</a>.</tt>
<p>
<hr>
<br>/* Custom Exponential Moving Average */
<br>/* with Decay Factor, coded by Anthony Faragasso*/
<p>MaxGraph=8;
<p>pds=10; /* Custom EMA periods,and EMA standard, you can change period*/
<br>pds2=10;/* Simple MA periods , you can change period*/
<p>Smooth=(2/(pds+1));
<br>Decay=(1-smooth);
<p>/* set the P variable: O,H,L,C , your average can be on any price variable
*/
<br>P=C;
<p>P1=p;
<br>Avg2=(Smooth*p)+(Decay*p1);/* this line should read (smooth*p)+(decay*ema.prev)*/
<p>Avg3=EMA(Avg2,pds);
<p>Avg4=(Smooth*p)+(Decay*Ref(Avg3,-1));/* have I satisfied that line Here*/
<p>Graph0=EMA(Avg4,pds);
<br>Graph0Color=6;
<br>Graph0Style=1; /* blue line , Custom EMA with Decay*/
<p>Graph2=C;
<br>Graph2Style=128;
<p>Graph3=MA(p,pds2);
<br>Graph3Color=4; /*red line , Simple MA */
<p>Graph4=EMA(p,pds);
<br>Graph4Color=2; /* white line , EMA standard */
<p>Title=Name()+"&nbsp;&nbsp; Custom EMA with Decay :Blue "+"("+WriteVal(Graph0,format=1.2)+")"+"&nbsp;
EMA :White"+"("+WriteVal(Graph4,format=1.2)+")"+"&nbsp; Simple MA :Red
"+"("+WriteVal(Graph3,format=1.2)+")"+"&nbsp; Close :"+"("+WriteVal(Graph2,format=1.2)+")";</blockquote>

<p><tt>Your use of Yahoo! Groups is subject to the <a href="http://docs.yahoo.com/info/terms/";>Yahoo!
Terms of Service</a>.</tt></blockquote>

<hr>
<center>
<p><img SRC="cid:part1.3BEFCCD8.277B0804@xxxx"; ></center>
</blockquote>

<p><br><tt>Your use of Yahoo! Groups is subject to the <a href="http://docs.yahoo.com/info/terms/";>Yahoo!
Terms of Service</a>.</tt></blockquote>

</body>
</html>

--------------D29543ECF2340A1EEC381854
Content-Type: image/jpeg
Content-ID: <part1.3BEFCCD8.277B0804@xxxx>
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename=""


--------------D29543ECF2340A1EEC381854--

--------------6866F381EC2F4E4C13D7A6B6--

/* Custom Exponential Moving Average */
/* with Decay Factor, coded by Anthony Faragasso*/

MaxGraph=8;

pds=10; /* Custom EMA periods,and EMA standard, you can change*/ /*period*/
pds2=10; /* Simple MA periods , you can change period*/

Smooth=(2/(pds+1));
Decay=(1-smooth);


P=C; /* set the P variable: O,H,L,C , your average can be on any*/ /*price variable */

P1=p; /* return variable in P= statement */

Avg2=(Smooth*p)+(Decay*p1); /* this line should read */ /*(smooth*p)+(decay*EMA.prev)*/ 

Avg3=EMA(Avg2,pds);

Avg4=(Smooth*p)+(Decay*Ref(Avg3,-1)); /* have I satisfied that line Here*/

Graph0=EMA(Avg4,pds);
Graph0Color=6;
Graph0Style=1; /* blue line , Custom EMA with Decay*/

Graph2=C;
Graph2Style=128;

Graph3=MA(p,pds2);
Graph3Color=4; /*red line , Simple MA */

Graph4=EMA(p,pds);
Graph4Color=2; /* white line , EMA standard */

Title=Name()+" Custom EMA with Decay :Blue "+"("+WriteVal(Graph0,format=1.2)+")"+" EMA :White"+"("+WriteVal(Graph4,format=1.2)+")"+" Simple MA :Red "+"("+WriteVal(Graph3,format=1.2)+")"+" Close :"+"("+WriteVal(Graph2,format=1.2)+")";

Attachment: Description: ""