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

Re: Why Won't This Work?



PureBytes Links

Trading Reference Links

At 3:28 AM -0400 4/29/99, Tom Cathey wrote:
>WE are getting Close!   This may turn into a great indicator.
>
>Mark and Bob, I took a composite of your suggestions and got it working
>reasonably well, but added a little more features and now get a flat line. I
>dicked around with it a coupla hours and can't quite pull it out.
>
<Snip>
>
>Anyway, guys,  please give me a hand getting the bugs out and I'll bet many
>on this list will find it useful too.  I will modify it further once
>working, add a few more bells and whistles and post the final version for
>all.

Your code required:

     if Value1 > 0 and Value3 > 0  then begin

so it required both a SwingHigh and SwingLow to occur on the same bar which
is impossible. You need to save the most recent SwingHighs and SwingLows
separately then compare them. The atttached code does this.

I made both "Strength" and the "Length" of the moving average inputs so
they could be changed. Keep in mind that the SwingHigh and SwingLow
functions do not recognize these conditions until after "Strength" bars
have passed so the indication lags by "Strength" bars. The moving average
also lags by an amount equal to

    (Length - 1) / 2

bars so you might like to make

    Length = 2 * Strength + 1

to make the lag of both equal.

I also added a "Mode" input. With Mode = 2 (default), it plots the "Trend"
as you did. But if you plot a second copy of the indicator and set Mode =
1, set it to plot in the Price scale, and to plot in subgraph 1, then it
will plot the values of the main variables on the price chart for debugging
purposes.

Bob Fulks

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

Input: Length(20), Strength(5), Mode(2);

Var: MA(Close), Trend(0), SLo1(0), SLo2(0), SHi1(0), SHi2(0);

MA = Average(Close, Length);

Value1 = SwingLow(1, MA, Strength, Strength+1);        {Find SwingLow}
Value2 = SwingHigh(1, MA, Strength, Strength+1);       {Find SwingHigh}

if Value1 > 0 then begin
   SLo2 = SLo1;    {Save previous SwingLow}
   SLo1 = Value1;  {Get new SwingLow}
   if Mode = 1 then Plot1[Strength](SLo1, "Low");
end;

if Value2 > 0 then begin
   SHi2 = SHi1;    {Save previous SwingHigh}
   SHi1 = Value2;  {Get new SwingHigh}
   if Mode = 1 then Plot2[Strength](SHi1, "High");
end;


if SLo1 > 0 and SLo2 > 0 and SHi1 > 0 and SHi2 > 0  then begin

   if SLo1 > SLo2 and SHi1 > SHi2 then Trend = 1;
         {Established Uptrend, higher lows and higher highs }

   if Trend = 1 and MA < SLo1 then Trend = -1;
         {If SwingLow gets broken, then immediate -1}

   if SLo1 > SLo2 and SHi1 < SHi2 then Trend  = 0; {Triangle - Trendless}

   if SLo1 < SLo2 and SHi1 < SHi2 then Trend = -1;
         {Established DownTrend, lower lows and lower highs}

   if Trend = -1 and MA > SHi1 then Trend = 1;
         {If SwingHigh Gets Broken then immediate +1}

end;

if Mode = 2 then Plot3(Trend, "Trend");
if Mode = 1 then begin
	Plot4(MA, "MA");
	Plot1(SLo1, "Low");
	Plot2(SHi1, "High");
end;