BullCharts Forum Homepage
Forum Home Forum Home > BullCharts > BullScript
  New Posts New Posts RSS Feed: deviation to moving average
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

deviation to moving average

 Post Reply Post Reply Page  12>
Author
Message Reverse Sort Order / View First Unread Post
john View Drop Down
Newbie
Newbie


Joined: 18 Aug 2005
Posts: 7
Post Options Post Options   Quote john Quote  Post ReplyReply Direct Link To This Post Topic: deviation to moving average
    Posted: 30 Aug 2005 at 10:57pm

thanks pipsqueek

i will see what your coding gives me.

used with indices, chart two can give early warning signals.

regards, John

 

Back to Top
pipsqueek View Drop Down
Regular
Regular
Avatar

Joined: 03 Jan 2005
Location: Australia
Posts: 34
Post Options Post Options   Quote pipsqueek Quote  Post ReplyReply Direct Link To This Post Posted: 25 Aug 2005 at 10:45pm

HI John,

Try this for chart2

pd:=input("moving average period",20,1,250);

Devo:=(close-ma(c,pd,e))/ma(c,pd,e)*100;

{or Devo:=(close/ma(c,pd,e)-1)*100   is exactly the same thing}

NormDevo:=sum(Devo,pd)/pd;

(Devo - NormDevo)*100

Looks like I've just calculated the difference between (the %deviation of the close from its moving average) and (the average of this deviation). Multiplied by 100 to give a bigger number.

If you don't multply by 100, then you can plot your chart1 and chart2 in the same pane as their scales will be the same. They have the same basic shape.

Not quite sure what this is all about John, but hope it does what you wanted.

Pipsqueek

 

failing to plan is planning to fail.
Back to Top
john View Drop Down
Newbie
Newbie


Joined: 18 Aug 2005
Posts: 7
Post Options Post Options   Quote john Quote  Post ReplyReply Direct Link To This Post Posted: 24 Aug 2005 at 11:04pm

G'Day Pipsqueek,

Thanks for persisting...

--------------------

Is the "Devo" you refer to equal to the percentage deviation of the close from the moving average?? I'm guessing that it is. Correct?

->Yep

What do you mean by "NormDevo"?

-> Norm meaning normalisation. NormDevo is the average of Devo for the Period.

You are using 2 period references in "Chart two" ... one is the period for summing the "Devo data points" and the other is the period for "NormDevo". Do you want these periods to be the same as the period you used in Chart1 or are they different?

The period remains constant across all calculations. The Period is equal to the reference i.  So in the last part of chart two calcs we are subtracting the average Devo from Devo.

Hope this is clearer.

Thanks, John

Back to Top
pipsqueek View Drop Down
Regular
Regular
Avatar

Joined: 03 Jan 2005
Location: Australia
Posts: 34
Post Options Post Options   Quote pipsqueek Quote  Post ReplyReply Direct Link To This Post Posted: 24 Aug 2005 at 9:58pm

John

I'm a bit confused here ....

Is the "Devo" you refer to equal to the percentage deviation of the close from the moving average?? I'm guessing that it is. Correct?

What do you mean by "NormDevo"?

You are using 2 period references in "Chart two" ... one is the period for summing the "Devo data points" and the other is the period for "NormDevo". Do you want these periods to be the same as the period you used in Chart1 or are they different?

Regards, Pipsqueek

failing to plan is planning to fail.
Back to Top
john View Drop Down
Newbie
Newbie


Joined: 18 Aug 2005
Posts: 7
Post Options Post Options   Quote john Quote  Post ReplyReply Direct Link To This Post Posted: 21 Aug 2005 at 10:55pm

Thanks for your valuable posts pipsqueek and cobra.

I have been able to use a hybrid between both suggestions to get my first chart. There was one other chart. Great if you could help me get this one.

Thanks guys, John 

REFERENCES:
i. Moving average (MA) period = no. bars in MA calculation (Period)
ii. MA value = current MA value (MA)
iii. Stock closing price (Stock)

CHART ONE*:
Deviation of MA from Stock price, expressed as a %
A. Formula: ((Stock/MA)-1)*100 (Devo)

* the above chart has been completed.

CHART TWO:
Second deviation of MA, expressed as a %

This has two parts. Firstly to calculate average of
Devo

B.  sum(Devo data points for Period)/Period (NormDevo)

Then the finale...

C. (Devo - NormDevo)*100 (or (A-B)*100)

Back to Top
pipsqueek View Drop Down
Regular
Regular
Avatar

Joined: 03 Jan 2005
Location: Australia
Posts: 34
Post Options Post Options   Quote pipsqueek Quote  Post ReplyReply Direct Link To This Post Posted: 20 Aug 2005 at 10:41pm

Hi John

Yep, you are right. What I suggested should plot the difference between the close and the moving average. If the close is above the moving average then this difference is positive, if the close is below the moving average then the differnce is negative.

I see your point about wanting to display this difference as a percentage. Makes comparisons easier.

Try this

[target=default]

pd:=input("moving average period",20,1,250);

(close-ma(c,pd,e))/ma(c,pd,e)*100;

The difference between the close and the moving average has been expressed as a percentage of the moving average. Plonk the indicator into a new pane (it will go there anyway by default) and add a horizontal line at x = 0 if you wish. When the indicator is zero, then the close and the moving average are equal.

Regards, pipsqueek

failing to plan is planning to fail.
Back to Top
Cobra View Drop Down
Regular
Regular
Avatar

Joined: 08 Nov 2004
Location: Australia
Posts: 76
Post Options Post Options   Quote Cobra Quote  Post ReplyReply Direct Link To This Post Posted: 19 Aug 2005 at 12:37pm
John,
I use this basic script for deviation from 200 day moving average -

[target=price]
[horzlines=1]

C/(sum(C,200)/200)

Save as a indicator then add it to a new pane.

Any use?. Let me know if you find a way of displaying the scale in percent, I'm sure there would be a way, I just haven't had time to look into it.
One problem I find with this indicator is that each stock is different, as to what constitutes a large deviation away from the average and hence a buy or sell signal, from a scan viewpoint. If the divergence from 1 could be converted into a percentage it may be more meaningful??.


BullCharts version:3.4.1.28129
Windows XP SP2
Back to Top
john View Drop Down
Newbie
Newbie


Joined: 18 Aug 2005
Posts: 7
Post Options Post Options   Quote john Quote  Post ReplyReply Direct Link To This Post Posted: 18 Aug 2005 at 11:58pm

Pipsqueek,

This shoul be plotting the difference (above or below) between the price and the ma value. is that what its doing?

John 

Back to Top
john View Drop Down
Newbie
Newbie


Joined: 18 Aug 2005
Posts: 7
Post Options Post Options   Quote john Quote  Post ReplyReply Direct Link To This Post Posted: 18 Aug 2005 at 11:54pm

Thanks Pip,

Got close there.

An input function would work well. I don't know how to display the scale as a %.

Regards, John 

Back to Top
pipsqueek View Drop Down
Regular
Regular
Avatar

Joined: 03 Jan 2005
Location: Australia
Posts: 34
Post Options Post Options   Quote pipsqueek Quote  Post ReplyReply Direct Link To This Post Posted: 18 Aug 2005 at 10:38pm

Hi John

What kind of deviations from the moving average?

Are you just talking about the actual distance of the close from a moving average? Or something a bit more exotic?

If its the former, then wouldn't you just do something like...

close-ma(c,20,e); 0;

You could use an input function to allow you to change the moving average period as you apply the indicator.

Don't know if this what you were after ....

Pipsqueek

 

 

 

failing to plan is planning to fail.
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.69
Copyright ©2001-2010 Web Wiz