PureBytes Links
Trading Reference Links
|
Bill,
Thanks for the detailed look at your code. I always learn something by
doing this, and you have some great ideas in it!
I really like that you are initializing the variables in your code. I
hadn't thought of that or even messed around with what results that gives.
Perhaps this has been the source of several of my past unexplained
problems--I've typically tried using a form such as If(A,..then ...) relying
on the fact that it would be implicit that if A were true, then A=1 would be
redundant. Not so. I've fixed many a problem by specifically stating A=1.
Perhaps the root of my error lies in the initialization.
I can understand that you'd want the last three bars of the SMA and MMA to
be getting farther apart. I ususally bend over backwards and create
horrible, inelegant code to avoid the PREV function. It really is a four
letter word. Nothing I know of consumes resources faster. Sometimes it's
unavoidable, but I want to exhaust all possibilities. So this is my intent
when I make the following suggestions (your code will work fine as is).
If you were to take the difference of the SMA-MMA and use the Linear
Regression Slope function, you would not only have a test of a widening gap,
but also you would have a measure of the rate of that widening. This may be
good information for tweaking your system. i.e. a very fast widening might
suggest a rapid and large move which with testing you might find will
indicate either that the trend will be more likely to sustain or less likely
to sustain, depending on the markets you are testing.
As another way of measuring your three day widening, you could again take
the difference of SMA-MMA, require it to be positive, and then test that the
SUM((SMA-MMA)>Ref(SMA-MMA),-1),3) is equal to three.
Finally, what you are seeing as you have no results in your indicator is
"the big one." The big problem that is. You are correct about the
BarsSince() function being undefined until an event occurs such as FALSELONG
or LONG. Until one of each takes place, your function remains undefined.
(This has been useful in getting MetaStock to produce a null result on a
plot, but it's not helping us here.)
Here's my "Kludge": talk about an inelegant approach to get around a
problem!!! I will create a TRUE condition for each of my indicators very
early in the chart. Then I will have to add a conditional statement into
each part of my code, such as my equity line, to start calculating just
after those fabricated signals.
In your system, I would set these just after the LMA starts. I've found
that setting them before all functions are no longer null doesn't work. So,
use a test with Cum(1)= <yourLMAperiods>+1 and set the LONG variable to 1,
then two or three bars later, Cum(1)=<yourLMAperiods>+4 and set the
FALSELONG variable to 1, etc. Then all of your BarsSince() comparisons
should work sooner.
I think this approach is especially important in longer term systems where
you don't have as many, or even any, of the opposite signals on any given
loaded amount of data/chart.
One thing I thought about in your approach but I don't know the result is
this: what if instead of initializing your variables to zero you
initialized them to your TRUE condition of 1 or -1? I don't know if
MetaStock works top down through the code for each individual bar on a chart
or performs the calculation across the data array operating from the current
date. I'd like to experiment with this a bit.
Bill, I hope some of these ideas help. I think you have a promising looking
system, and I'd be curious to see how it does across a deep and broad data
set (lots of history and many stocks).
Dave Nadeau
Fort Collins, CO
-----Original Message-----
From: owner-metastock@xxxxxxxxxxxxx
[mailto:owner-metastock@xxxxxxxxxxxxx]On Behalf Of Bill Irwin
Sent: Saturday, January 27, 2001 9:48 PM
To: metastock@xxxxxxxxxxxxx
Subject: RE: Systems and Testing (WAS: RE: Setting colour on a
multi-plot indicator)
Dave:
I hope you got through your furniture move alright. I know I hate it when I
have to do it.
The problem I'm working on now is getting the Exits to be a little less
sensitive. In my Triple MA Crossovers indicator I've defined FalseLong and
FalseShort to be when the Sma slips back below the Mma. The value of this
valiable is used in the Positions indicator to determine if a Long position
still holds. If the FalseLong is true then the Position should not be Long.
This is working but the exit is being triggered even if true for one day.
Then, if it isn't true the next day, the Position goes long again. Here's
the code:
Triple MA Crossovers:
Sma := FmlVar("_Triple MA","ShortMA");
Mma := FmlVar("_Triple MA","MediumMA");
Lma := FmlVar("_Triple MA","LongMA");
LongSignal:= 0;
ShortSignal:= 0;
FalseLong:= 0;
FalseShort:= 0;
LongSignal:= Cross(Sma, Mma) AND
Lma > Mma;
ShortSignal:= -1 * (Cross(Mma, Sma) AND
Lma < Mma);
FalseLong := BarsSince(LongSignal = 1) <=
BarsSince(ShortSignal = -1) AND
Sma < Mma;
FalseShort := BarsSince(ShortSignal = -1) <=
BarsSince(LongSignal = 1) AND
Sma > Mma;
What I've tried to introduce is the idea that, not only should the Sma be
below the Mma, but the difference between the two should be getting greater
over the last 3 days. When I implement the following change, I get nothing
plotted by the Positions indicator.
Triple MA Crossovers:
Sma := FmlVar("_Triple MA","ShortMA");
Mma := FmlVar("_Triple MA","MediumMA");
Lma := FmlVar("_Triple MA","LongMA");
LongSignal := Cross(Sma, Mma) AND
Lma > Mma;
ShortSignal := Cross(Mma, Sma) AND
Lma < Mma;
FalseLong := BarsSince(LongSignal = 1) <=
BarsSince(ShortSignal = -1) AND
Sma < Mma AND
Cross(Ref(Mma, -3), Ref(Sma, -3)) AND
Mma - Sma > PREV AND
Ref(Mma, -1) - Ref(Sma, -1) > PREV AND
Ref(Mma, -2) - Ref(Sma, -2) > PREV;
FalseShort := BarsSince(ShortSignal = -1) <=
BarsSince(LongSignal = 1) AND
Sma > Mma AND
Cross(Ref(Sma, -3), Ref(Mma, -3)) AND
Sma - Mma > PREV AND
Ref(Sma, -1) - Ref(Mma, -1) > PREV AND
Ref(Sma, -2) - Ref(Mma, -2) > PREV;
There may be a better way to detect a widening gap between two MAs, I don't
know. One thing I am learning is how frustrating it is to have to work in
tiny little windows where you can't see much of the formula; can't flip back
& forth between two Indicator formulas; can't resize many of the windows.
With a 17" monitor I have lots of space I could be using to make the
programming task much easier.
Here's the current state of the Positions indicator. I've been trying to
get positions to be taken earlier in the history but it seems that any
formula that's referred to must evaluate to something other than N/A before
anything happens. It seems I have to have a FalseLong and FalseShort
condition before any Long or Short position is taken. This misses many good
opportunities. You can see my attempts to have variables initialized to
zero if they aren't true.
Triple MA Positions:
BuyLong:= If(FmlVar("_Triple MA Crossovers",
"LongSignal") =1, 1, 0);
SellShort:= If(FmlVar("_Triple MA Crossovers",
"ShortSignal") = -1, -1, 0);
ExitLong:= If(FmlVar("_Triple MA Crossovers",
"FalseLong") = 1, 1, 0);
ExitShort:= If(FmlVar("_Triple MA Crossovers",
"FalseShort") = 1, 1, 0);
If(BarsSince(Ref(BuyLong,-1) = 1) <=
BarsSince(Ref(SellShort,-1) = -1) AND
(ExitLong = 0 OR
BarsSince(BuyLong) <= BarsSince(ExitLong)),
+1,
If(BarsSince(Ref(SellShort,-1) = -1) <=
BarsSince(Ref(BuyLong,-1) = 1) AND
(ExitShort = 0 OR
BarsSince(SellShort = -1) <=
BarsSince(ExitShort)), -1,0
)
);
> -----Original Message-----
> From: owner-metastock@xxxxxxxxxxxxx
> [mailto:owner-metastock@xxxxxxxxxxxxx]On Behalf Of Dave Nadeau
> Sent: Saturday, January 20, 2001 11:31 AM
> To: metastock@xxxxxxxxxxxxx
> Subject: Systems and Testing (WAS: RE: Setting colour on a multi-plot
> indicator)
>
>
> Bill,
>
> Sorry for the delayed response. I've been away on travel,
> and came home mid
> week to a pile of stuff to catch up on...
>
> Regarding the $25 question, yes, that's exactly right. You have a $25
> profit per share over the period tested.
>
> Regarding what I mean by a "high number." For my results, I
> like something
> like 40 or so trades. That's fairly arbitrary, but well into
> the total
> amount for my results to be "statistically significant". And
> this is closed
> trades per market or security. So, across a portfolio, I'm
> looking at a
> "bunch" of trades.
>
> To refine any of my systems, what I'm going to do with the
> results of any
> single System Test is to export the trade by trade results
> into Excel and
> look at MAE or Maximum Adverse Excursion while the system runs without
> stops. Group the MAE's by winners and losers, with my
> thought being that
> I'd set a stop at some level (preferring to use percentages
> rather than
> whole dollar amounts here) of MAE where the probability of
> recovering to a
> profitable trade becomes too low--again a subjective call based on my
> trading preferences. This is another reason why I like a
> higher number of
> closed trades in my System Test.
>
> I have to be somewhere (to help move furniture...ugh!) so
> I'll finish the
> Exits portion later. I'd like to work with your code some
> more when I have
> a bit more time later today. Thanks for all of your detail
> and sharing your
> code with us!
>
> Dave Nadeau
> Fort Collins, CO
>
> -----Original Message-----
> From: owner-metastock@xxxxxxxxxxxxx
> [mailto:owner-metastock@xxxxxxxxxxxxx]On Behalf Of Bill Irwin
> Sent: Friday, January 12, 2001 1:05 PM
> To: metastock@xxxxxxxxxxxxxxxxxx
> Subject: RE: Setting colour on a multi-plot indicator
>
>
> Dave:
> I've been wrestling with this System trying to improve it,
> amid all the
> other demands on my time during the holidays. See below:
>
> > -----Original Message-----
> > From: owner-metastock@xxxxxxxxxxxxx
> > [mailto:owner-metastock@xxxxxxxxxxxxx]On Behalf Of Dave Nadeau
> > Sent: Monday, December 25, 2000 9:57 PM
> > To: metastock@xxxxxxxxxxxxx
> > Subject: RE: Setting colour on a multi-plot indicator
> >
> > At this point you run an exploration across the TSE and get
> > the results as
> > you suggested. Certainly, your average return tells you how
> > this system
> > performs over the broad market. It's nice if it does better on more
> > securities, but I'm of the opinion that it's very unlikely
> > that a single
> > system will work well on every market.
>
> When an Exploration's Equity column shows +25 I think that
> means that the
> trades gained $25/share over the run. Is this correct?
>
> > From here, I would sort those results and look at the best
> > performers. On a
> > chart of those, I'd plot the equity line that you have
> programmed. A
> > smoothly rising equity line suggests consistent, repeatable
> > performance in
> > the past which should have predictive value for the future,
> > assuming that
> > you have a fairly high number of trades that this is based on.
>
> How many is a "high number"?
>
> What this system needs now is an exit signal for both long and short
> positions that should be terminated. The Positions indicator
> is always in
> either a long or short position once the crossover occurs that is the
> opposite of the first crossover (it misses the first
> opportunity). We need
> to recognize that a signal may be false because the trend
> doesn't continue
> long enough for all the MAs to cross over so that the
> opposite signal can be
> generated. In other words, some times after a long signal,
> the price trends
> down before the Medium MA has crossed above the Long MA.
> Hence a short
> signal isn't generated and the position stays long all the
> way through the
> slide and up through (what should be) the next long position.
> The closest
> I've been able to come follows:
>
> _Triple MA Crossovers:
> Sma := FmlVar("_Triple MA","ShortMA");
> Mma := FmlVar("_Triple MA","MediumMA");
> Lma := FmlVar("_Triple MA","LongMA");
> LongSignal := Cross(Sma, Mma) AND
> Lma > Mma;
> ShortSignal := Cross(Mma, Sma) AND
> Lma < Mma;
> FalseLong := BarsSince(LongSignal) <=
> BarsSince(ShortSignal) AND
> Sma < Mma;
> FalseShort := BarsSince(ShortSignal) <=
> BarsSince(LongSignal) AND
> Sma > Mma;
>
> _Triple MA Positions
> BuyLong := FmlVar("_Triple MA Crossovers", "LongSignal");
> SellShort := FmlVar("_Triple MA Crossovers", "ShortSignal");
> ExitLong := FmlVar("_Triple MA Crossovers", "FalseLong");
> ExitShort := FmlVar("_Triple MA Crossovers", "FalseShort");
>
> If(BarsSince(Ref(BuyLong,-1)) <= BarsSince(Ref(SellShort,-1)) AND
> (ExitLong = 0 OR
> BarsSince(BuyLong) <= BarsSince(ExitLong)), +1,
> If(BarsSince(Ref(SellShort,-1)) <= BarsSince(Ref(BuyLong,-1)) AND
> (ExitShort = 0 OR
> BarsSince(SellShort) <= BarsSince(ExitShort)), -1,0
> )
> );
>
> The Positions indicator misses several Long and Short
> triggers early in the
> graph. I haven't figgered out why yet but I suspect my
> efforts at defining
> an early exit are preventing positions to be taken. I need a
> way to set a
> variable when a position has been entered that can be referenced when
> deciding if an exit should be done. The exit indicator
> shouldn't turn on
> unless the condition exists AND we're currently in the
> position that the
> exit is trying to get us out of. More study needed here...
>
> I'm having difficulty identifying a position that's been
> exited while the
> condition to enter the position is still true. In other
> words, After a Long
> position is entered and the ShortMA drops back below the MediumMA, the
> FalseLong indicator fires to exit the position. Then, if the
> Short pops
> back above the Medium, a Long position is taken again. I
> need to smooth out
> the short, temporary conditions that trigger an entry.
>
> Any ideas would be greatly appreciated.
>
> Bill
>
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
|