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

RE: [amibroker] Re: simplest way to detect a reversal of direction in an indicator



PureBytes Links

Trading Reference Links

hi Dimitris, thanks for jumping in.

let me try to be clearer about the kind of simple reversal I'm looking for:
  for an up move, I'm looking for a single bar that's at least the threshold
amount greater than the minimum value seen since the last down move.
  for a down move, I'm looking for a single bar that's at least the
threshold amount lower than the maximum value seen since the last up move.

like this, with a threshold of 3 in both directions:

3 (min of first cycle)
5
4
6 <- up move, at least 3 above min of first cycle (3)
7
8 (max of this up cycle)
6
7
6
4 <- down move, at least 3 below max of this up cycle (8)
1
3
2
3
0 (min of this down cycle)
2
4 <- up move, at least 3 above min of this down cycle (0)

make sense?

below is the AFL I came up with. it does scan every bar, which I'm surprised
was necessary, but it works, I think, and it's not as horribly slow as I was
afraid it might be. given an array and separate thresholds for up and down
moves, it returns an array with +1 at every up move, -1 at every down move,
and 0 everywhere else.

---------------------
function ReverseDetect(ValueArray, ThreshUp, ThreshDown) {
	tracking = 0;	// last peak we're comparing to
	action = 0;		// last action taken; +1 = up, -1 = down
	result[0] = 0;
	for(i = 1; i < BarCount; i++)
	{
		result[i] = 0;	// default output for this bar if no move
		if(action != 1)	// looking for a rise
		{
			if(tracking > ValueArray[i])
				tracking = ValueArray[i];
			else
			{
				if(ValueArray[i] > tracking + ThreshUp)
				{
					action = 1;
					result[i] = action;
					tracking = ValueArray[i];
				}
			}
		}
		if(action != -1)	// looking for a drop
		{
			if(tracking < ValueArray[i])
				tracking = ValueArray[i];
			else
			{
				if(ValueArray[i] < tracking - ThreshDown)
				{
					action = -1;
					result[i] = action;
					tracking = ValueArray[i];
				}
			}

		}
	}
	return result;
}
---------------------

[if this gets mangled in the msg an anyone cares, I could post it as a
file.]

making any more sense? see any way to code this in fewer lines of
array-based AFL?

FWIW, none of the inputs I've tested so far have yielded great buy/sell
signals when processed this way. maybe none will, but at least I've been
able to test this idea.

dave


> your questions are somehow confusing: you wrote, for example,
> for "san diego wave" strategy :
> "...switches long when the MTI  rises by .12"
> If the MTI goes like
> MTI0
> MTI1=MTI0+0.13
> MTI2=MTI1+0.15
> MTI3=MTI2+0.12
> MTI4=MTI3+0.13
> ie it increases 4 consequtive bars by >0.12, they go long every day ?
> I dont think so and, anyway, it is not a reversal.
> You probably mean MTI go lower and lower and, on day0, change
> direction and go higher by >0.12.
> If this is requested, you should specify how many descending bars you
> need *before* the change.
> Do you need just one ?
> Then
> cond=roc(c,1)>0 AND Ref(roc(c,1),-1)<0;
> is enough to describe this "reversal".
> Equivalent condition would be the
> cond1=Ref(c,-1)==LLV(c,3);
> Do you need more than one consecutive descending bars before the
> reversal ?
> Then
> k=4;
> cond=ROC(C,1)>0 AND Ref(Sum(ROC(C,1)<0,k),-1)==k;
> would give you the reversal after four *consecutive* descending bars.
> Do you need just the previous bar to be the lower of the last k bars ?
> Then,
> k=10;
> Cond=Ref(C,-1)==LLV(C,k);
> would describe that yestedays close was the lowest of the last k
> bars, ie we do have a reversal without asking *all* previous bars to
> be descending.
> As you see, there are many alternatives and it would be better to be
> more specific.
> Decide first how would you like the reversal and then AFL will solve
> your request in 2 or 102 lines [they will be executed with the same
> speed, in one way or another]
> Dimitris Tsokakis
> PS1: All above described conditions are realistic, you should avoid
> *ANY* zig/peak/trough functions.
> The known trouble of zig use is simple : You are informed that Day X
> *was* a peak, but this information arrives 2 or 12 or 102 days later
> and it is totally useless for trading. Zig and its derivatives are
> *very* useful for the historical study of an indicator, but totally
> useless for decision making.
> PS2. Although it may be obvious, just know that all above conditions
> are equally applied to indicators, not only Close value. Just
> describe how do you like the reversal.
>
> --- In amibroker@xxxxxxxxxxxxxxx, "Dave Merrill" <dmerrill@xxxx>
> wrote:
> > I've been examining VectorVest's tools for a while now, and I'd say
> that
> > while that link tells you some of the party line, that's not the
> whole
> > enchilada. once you have a good long/short timing signal, there's a
> pretty
> > rich toolkit for stock selection, and a lot of canned and user group
> > strategies that I and others have tested and believe can do quite
> well.
> > timing's another story. as the tampa group's approach indicates,
> many people
> > think you can do better than VV's standard recommendations. some
> people
> > include the MTI and other proprietary VV indicators in their overall
> > formula, some not.
> >
> > anyway, I just used the MTI as an example of the kind of turn
> detection I
> > was looking for; I didn't mean to discuss any particular way of
> interpreting
> > it as a strategy. the MTI is range-bounded, so crossings of fixed
> levels can
> > have meaning. but how do you make use of other indicators that
> aren't
> > range-bounded? besides zero crossing or crossing some other
> indicator line,
> > another one that occurred to me was this idea of direction
> reversals of some
> > particular amount.
> >
> > I just need to figure out how to implement it...
> >
> > dave
> >
> >
> > > Some insight on Vectorvest MTI indicator:
> > >
> > > http://www.sctxcompclub.org/MtgFollowUp/Jul1_02Invest.html
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx, "Dave Merrill" <dmerrill@xxxx>
> wrote:
> > > > one example is the vectorvest-based "san diego wave" strategy,
> which
> > > > switches long when the MTI (vectorvest's proprietary Market
> Timing
> > > > Indicator) rises by .12, and goes short when it falls by .12.
> > > absolute level
> > > > doesn't matter, just having reversed direction by that amount.
> (not
> > > that I'm
> > > > saying that specifically is a great strategy or anything.)
> > > >
> > > > any indicator could be interpreted this way, and I thought it'd
> be
> > > > interesting to see which ones turned out to be useful.
> > > >
> > > > it's really easy to see these turns visually on a chart. I'm
> > > surprised that
> > > > it doesn't seem easy to determine them procedurally. I'd have
> > > thought tj or
> > > > one of the other AFL gurus would have put my feeble brain to
> shame
> > > with a 2
> > > > line solution by now (;-).
> > > >
> > > > dave


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/l.m7sD/LIdGAA/qnsNAA/GHeqlB/TM
---------------------------------------------------------------------~->

Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/