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

Trend/Oscillator State Identification



PureBytes Links

Trading Reference Links

I've been trying to figure out what "states" a trend for a particular period
goes through.  I'm not clear but that what I'm looking for are merely the
"states" of MACD lines.

(But if MACD is what "trend states" are about, I'm not clear but that ALL
"trends" for a particular period bar and length are "oscillators" for a
larger period of the same length.  This is consistent with what Alexander
Elder says in his discussion of "Triple Screen" in "Trading for a Living."
Right?)

I have found it useful to distinguish the "states" of my favorite oscillator
in some initial testing and optimization runs.  My belief is that the basic
state definitions found in the function code below can be abstracted to any
oscillator.  My plan is to make the code below more abstract over time so
that it is oscillator/indicator independent.

I just looked again at the code below and am a bit embarrassed about some of
the stuff that hasn't been refined/parameterzed yet.  My focus has been on
correctly identifying meaningful states to determine with real data through
optimization which turn out to be significant.  The code below has some hard
coded values in it because I haven't got down the difference between series
and simple numerics, but the parms are mostly parameterized in the "state
definition" areas where it counts.

The "TempOscState" somehow helps with the 64k issue, don't ask me why.

A close read would show that there are actually four redundant states below.
I know it.  I haven't fixed it yet.

I'd appreciate feedback.

Steven Buss
Walnut Creek, CA
sbuss@xxxxxxxxxxx



{*******************************************************}
{OscillatorState}
Input:
 KPeriods(NumericSimple), DPeriods(NumericSimple), KSlow(NumericSimple),
 SellZone(NumericSimple), BuyZone(NumericSimple), BarPer(NumericSimple);
Variable:
 State01(FALSE), State02(FALSE), State03(FALSE), State04(FALSE),
State05(FALSE),
 State06(FALSE), State07(FALSE), State08(FALSE), State09(FALSE),
State10(FALSE),

StateNeg01(FALSE),StateNeg02(FALSE),StateNeg03(FALSE),StateNeg04(FALSE),Stat
eNeg05(FALSE),

StateNeg06(FALSE),StateNeg07(FALSE),StateNeg08(FALSE),StateNeg09(FALSE),Stat
eNeg10(FALSE),
 Stoch(0),   StochSyn(0),  StochMA(0),
 BZ(0),    SZ(0),     TempOscState(0);
{*******************************************************}
{VARIABLE ASSIGNMENT}
Stoch  = StochMain(KPeriods,Kslow,BarPer);
StochMA = Average(StochMain(KPeriods,Kslow,BarPer),DPeriods);
State01 = Stoch < BuyZone and Stoch <  StochMA; {May be expanded to get at
duration of OBought}
State02 = Stoch < BuyZone and Stoch >= StochMA;
State03 = Stoch Crosses Above 20;
State04 = Stoch >= BuyZone and
    Stoch <= BuyZone + 30 and
    Stoch >= StochMA ;
State05 = Stoch >= BuyZone and
    Stoch <= BuyZone + 30 and
    Stoch Crosses Above StochMA;
State06 = Stoch <=  SellZone and
    Stoch >= SellZone - 30 and
    Stoch >= StochMA ;
State07 = Stoch <=  SellZone and
    Stoch >= SellZone - 30 and
    Stoch Crosses Above StochMA;
State08 = Stoch Crosses Above 80;
State09 = Stoch >= SellZone and Stoch >= StochMA;
State10 = Stoch >= SellZone and Stoch < StochMA;
StateNeg01 = Stoch > SellZone and Stoch >  StochMA;
StateNeg02 = Stoch > SellZone and Stoch <= StochMA;
StateNeg03 = Stoch Crosses Below 80;
StateNeg04 = Stoch <= SellZone and
     Stoch >= SellZone - 30 and
     Stoch <= StochMA ;
StateNeg05 = Stoch <= SellZone and
     Stoch >= SellZone - 30 and
     Stoch Crosses Below StochMA;
StateNeg06 = Stoch >= BuyZone and
     Stoch <= BuyZone + 30 and
     Stoch <= StochMA ;
StateNeg07 = Stoch >= BuyZone and
     Stoch <= BuyZone + 30 and
     Stoch Crosses Below StochMA;
StateNeg08 = Stoch Crosses Below 20;
StateNeg09 = Stoch <= BuyZone and Stoch <= StochMA;
StateNeg10 = Stoch <= BuyZone and Stoch > StochMA;
  if State01 = TRUE Then TempOscState = 1
else if State02 = TRUE Then TempOscState = 2
else if State03 = TRUE Then TempOscState = 3
else if State04 = TRUE Then TempOscState = 4
else if State05 = TRUE Then TempOscState = 5
else if State06 = TRUE Then TempOscState = 6
else if State07 = TRUE Then TempOscState = 7
else if State08 = TRUE Then TempOscState = 8
else if State09 = TRUE Then TempOscState = 9
else if State10 = TRUE Then TempOscState = 10
else          TempOscState = 98;
if TempOscState = 98 then begin
  if StateNeg01 = TRUE Then TempOscState = -1
else if StateNeg02 = TRUE Then TempOscState = -2
else if StateNeg03 = TRUE Then TempOscState = -3
else if StateNeg04 = TRUE Then TempOscState = -4
else if StateNeg05 = TRUE Then TempOscState = -5
else if StateNeg06 = TRUE Then TempOscState = -6
else if StateNeg07 = TRUE Then TempOscState = -7
else if StateNeg08 = TRUE Then TempOscState = -8
else if StateNeg09 = TRUE Then TempOscState = -9
else if StateNeg10 = TRUE Then TempOscState = -10
else           TempOscState = TempOscState;
END;
OscillatorState = TempOscState;