speedynyc / trader-dss

Automatically exported from code.google.com/p/trader-dss
0 stars 0 forks source link

Williams %R needs more data to make good decisions #9

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
The wikipedia page for W%R says 

***********
Williams used a 10 trading day period and considered values below -80 as
oversold and above -20 as overbought. But they were not to be traded
directly, instead his rule to buy an oversold was

    *  %R reaches -100%.
    * Five trading days pass since -100% was last reached
    *  %R rises above -95% or -85%.
***********

To be able to select stocks that match this, we need to be able to use a
query something like

# oversold (os) stocks
select symb, exch, wpr_10 from indicators where wpr_10_os_80 = 5 and wpr_10
< -85 and date = 'xxxx-xx-xx';

Original issue reported on code.google.com by peter.st...@1ab.ltd.uk on 19 Jan 2010 at 2:27

GoogleCodeExporter commented 8 years ago

Original comment by peter.st...@1ab.ltd.uk on 20 Jan 2010 at 1:08

GoogleCodeExporter commented 8 years ago
What I remember from our discussion

o. Keep a running count of the number of days since the %R went below -80 or 
above
-20. These will require separate columns in the indicators table.
o. When %R is greater than -80, that is from -79 to 0, the count will be +ve
o. When %R is <= -80 the count will be -ve
Should it work the same way for -20? Or should the sense be reversed? Which 
makes
writing queries more straight forward? I suspect keeping it consistent makes 
most sense.
o. Variable names? Here I've used wpr_10_os_80 as the number of days since 
wpr_10 was
over sold at -80 (os = over sold)

The method might be something like this (for -80)

-- get yesterday's count
SELECT wpr_10_os_80 last_wpr_10_os FROM indicators WHERE DATE < new_date AND 
symb =
new_symb AND exch = new_exch ORDER BY DATE DESC limit 1;
if not found -- first record?
 if wpr10v > -80 then
     wpr_10_os_80 := 1
 else
     wpr_10_os_80 := -1
 end if
-- work out today's count. If it's in the same direction as yesterday's then
increment, if not reset it to +1 or -1
elsif last_wpr_10_os > 0 then -- which means wpr10v > -80 yesterday
  if wpr10v > -80 then
     -- another day in the same direction
     wpr_10_os_80 := wpr_10_os_80 + 1;
  else
     -- swapped direction
     wpr_10_os_80 := -1
  end if
else
  if wpr10v < -80 then
     -- another day in the same direction
     wpr_10_os_80 := wpr_10_os_80 1 1;
  else
     -- swapped direction
     wpr_10_os_80 := 1
  end if
end if

Original comment by peter.st...@1ab.ltd.uk on 23 Feb 2010 at 1:05

GoogleCodeExporter commented 8 years ago
wpr_10_os_80 := wpr_10_os_80 1 1; 
should say
wpr_10_os_80 := wpr_10_os_80 - 1;

Original comment by peter.st...@1ab.ltd.uk on 23 Feb 2010 at 1:07

GoogleCodeExporter commented 8 years ago
I wish you could edit these!

-- get yesterday's count
SELECT wpr_10_os_80 as last_wpr_10_os into yesterday FROM indicators WHERE DATE 
<
new_date AND symb = new_symb AND exch = new_exch ORDER BY DATE DESC limit 1;
if not found -- first record?
 if wpr10v > -80 then
     wpr_10_os_80 := 1
 else
     wpr_10_os_80 := -1
 end if
-- work out today's count. If it's in the same direction as yesterday's then
increment, if not reset it to +1 or -1
elsif yesterday.last_wpr_10_os > 0 then -- which means wpr10v > -80 yesterday
  if wpr10v > -80 then
     -- another day in the same direction
     wpr_10_os_80 := wpr_10_os_80 + 1;
  else
     -- swapped direction
     wpr_10_os_80 := -1
  end if
else
  if wpr10v < -80 then
     -- another day in the same direction
     wpr_10_os_80 := wpr_10_os_80 - 1;
  else
     -- swapped direction
     wpr_10_os_80 := 1
  end if
end if

Original comment by peter.st...@1ab.ltd.uk on 23 Feb 2010 at 1:26

GoogleCodeExporter commented 8 years ago
will have a shot at this soon.

Original comment by peter.st...@1ab.ltd.uk on 9 Jan 2011 at 2:01