PureBytes Links
Trading Reference Links
|
Roy,
I've been using 4 different ways to debug the code:
1. Display within the indicator as you have. I hadn't thought of colour -
good idea, and also incrementing each so they stand out.
2. Using other indicators.
E.g. plotting an indicator that simply contains FmlVar("ST - System","POS").
This has the benefit of allowing me to change the main system indicator
output independently.
3. Using the Data Window. This displays values for all indicators and
values on display based upon where you move your mouse. Very useful but it
won't display any values for a specific indicator unless they have all been
initialised. Useful for confirming values when debuging calculations.
4. Using an Expert.
I have an Expert attached with Symbols defined for the Long Entry/Exit and
Short Entry/Exit conditions. This is probably the most useful. Give an at
a glance diagnosis of signals.
I've also defined a + Position (Long) to be highlighted green and a -
Position (Short) to be highlighted red.
Lastly, I display specific variables in the system indicator in a
commentary. Gives a tabular output showing #long wins/loses etc. with added
value calculations.
The commentary displays values that have been initialised and an error msg
for those that haven't.
I've been using 3com (not sure how I settled on that) with about 2yrs of
data.
I've also just stripped out the code to basics so I can see what's
happening - a monthly test entry to boot...
Using this I've figured out what was happening. I still had the Barsince()
in the Exit condition. This was causing the Pos variable to initialise
late.
Now I've replaced it with your Alert() it's highlighted to me why you needed
to create another set of entry/exit conditions off Pos. The Alert()
continues the Exit conditions.
Thanks for your help. I'm going to work the Equity etc in now.
Sean
P.S. test code below
LongEntryPoint:=O; ShortEntryPoint:=O; LongExitPoint:=O; ShortExitPoint:=O;
LongEntry:=Mod(Month(),2)=0 AND Ref(Month(),-1)<Month();{first TDM,
alternate Long/Short}
LongExit:=Alert(LongEntry,4) AND Alert(LongEntry,3)=0;{auto exit 3 days
later}
ShortEntry:=Mod(Month(),2)=1 AND (Ref(Month(),-1)<Month() OR
(Ref(Month(),-1)=12 AND Month()=1));
ShortExit:=Alert(LongEntry,4) AND Alert(LongEntry,3)=0;
Init:=Cum(LongEntry<>2 AND LongExit<>2 AND
ShortEntry<>2 AND ShortExit<>2)=1;
Pos:=Ref(If(BarsSince(LongEntry OR Init)>=
BarsSince(LongExit OR Init),0,2) +
If(BarsSince(ShortEntry OR Init)>=
BarsSince(ShortExit OR Init),0,-1),-0);
{
EnterLong:=Alert(Pos<1,2) AND Pos>=1;
CloseLong:=Alert(Pos>=1,2) AND Pos<1;
EnterShort:=Alert(Abs(Pos)<>1,2) AND Abs(Pos)=1;
CloseShort:=Alert(Abs(Pos)=1,2) AND Abs(Pos)<>1;
Equity:=Cum(If(CloseLong,ValueWhen(1,CloseLong OR Init, LongExitPoint)-
ValueWhen(1,EnterLong OR Init,LongEntryPoint),
If(CloseShort,ValueWhen(1,EnterShort
OR Init, ShortEntryPoint) - ValueWhen(1,CloseShort OR Init
,ShortExitPoint),0)));
}
-----Original Message-----
From: owner-metastock@xxxxxxxxxxxxx
[mailto:owner-metastock@xxxxxxxxxxxxx]On Behalf Of Roy Larsen
Sent: Monday, July 02, 2001 8:08 PM
To: metastock@xxxxxxxxxxxxx
Subject: Re: Indicator System problem
Sean
There appears to be a difference between what I worked on and your current
code. What I have
initialises immediately that all entry/close variables are valid, while the
code below misses the
first trade (on my test data) and doesn't initialise until the end of the
second trade. I will chase
this down as I am able.
What troubleshooting techniques are you using? I like to display each
variable within the indicator
other on its own or with relation to other internal variables. For example,
to display all
entry/exit signals I might adjust the last line to read
{Equity;} LongEntry+3; LongExit+2; ShortEntry+1: ShortExit;
Colouring each variable differently when more than one is displayed can also
useful.
What ticker codes are you testing on?
Roy
> I've been working through your code suggestions and the Pos variable
doesn't
> get initialised until after both a Long and a Short trade.
> I've stripped out everything else to resolve this first. I'm also not
> worried about triggers a day early or late than can be adjusted later.
> I'm assuming it's because there is now nothing to trigger the
LongEntry,...
> variables early now.
>
> This is the stripped out segment:
>
> LongEntryPoint:=Ref(H,-1);
> ShortEntryPoint:=Ref(L,-1);
> LongExitPoint:=O;
> ShortExitPoint:=O;
> LongEntry:=Ref(C,-1) < C AND
> C < L+((H-L)/4) AND
> C < O AND
> H < Ref(H,+1); {last part only for system test - following day entry
> condition}
> LongExit:=barsSince(LongEntry)=3;{auto exit 3 days later}
> ShortEntry:=Ref(C,-1) > C AND
> C > H-((H-L)/4) AND
> C > O AND
> L > Ref(L,+1); {last part only for system test - following day entry
> condition}
> ShortExit:=barsSince(ShortEntry)=3;{auto exit 3 days later}
> Init:=Cum(LongEntry<>2 AND LongExit<>2 AND
> ShortEntry<>2 AND ShortExit<>2)=1;
> Pos:=Ref(If(BarsSince(LongEntry OR Init)>=
> BarsSince(LongExit OR Init),0,2) +
> If(BarsSince(ShortEntry OR Init)>=
> BarsSince(ShortExit OR Init),0,-1),-0);
>
> Thanks again for your help,
> Sean
>
> -----Original Message-----
> From: owner-metastock@xxxxxxxxxxxxx
> [mailto:owner-metastock@xxxxxxxxxxxxx]On Behalf Of Roy Larsen
> Sent: Sunday, July 01, 2001 1:01 AM
> To: metastock@xxxxxxxxxxxxx
> Subject: Re: Indicator System problem
>
>
> Sean
>
> I believe the following code will track long and short positions more
> accurately than that swapped
> in previous posts. For the sake of brevity I have reduced Position to Pos.
A
> long trade is assigned
> a value of +2, and a short trade a value of -1. Therefore Pos will have a
> value >0 for any long
> position (with or without a short position) and = ABS(1) for any short
> position (with or without a
> long position). I guess you do not expect to be in both a long and short
> position at the same time,
> but with system testing if it can happen then it will. There are probably
a
> number of other values
> that could be used for Position but +2 and -1 seem to make it simple
enough
> to differentiate between
> current positions.
>
> Roy
>
> Pos{ition}:=Ref(If(BarsSince(LongEntry OR Init)>=
> BarsSince(LongExit OR Init),0,2) +
> If(BarsSince(ShortEntry OR Init)>=
> BarsSince(ShortExit OR Init),0,-1),-0);
> EnterLong:=Alert(Pos<1,2) AND Pos>=1;
> CloseLong:=Alert(Pos>=1,2) AND Pos<1;
> EnterShort:=Alert(Abs(Pos)<>1,2) AND Abs(Pos)=1;
> CloseShort:=Alert(Abs(Pos)=1,2) AND Abs(Pos)<>1;
>
>
>
|