PureBytes Links
Trading Reference Links
|
Sean
I'm not done yet but you may want to look at where I am at so far and take it from there. I have
made a few changes, some from necessity and some for personal choice. My approach is not the most
elegant, and definitely not the only "right" way, but hopefully it will give you an idea or two.
I have changed the method of timing the exits relative to the entries as these were causing a
problem on my test data. Using the Alert() function as I have is preferable to a Ref() function as a
Ref() will also delay the leading edge of the variable it is applied. This compounds the sort of
problems you already have. Hope this makes sense.
I have also added the Init variable as shown in my earlier note. I find that this gives a consistent
starting point to hang everything else on. In this case it just makes sure that all entry/exit
signals are valid. As it is also used in the Position variable you can see that Position will be
invalid as long as any one of the entry/exit signals are invalid.
I have taken the liberty of changing Position by separating it into two individual If() functions
rather than nesting one If() within the other. This may not have been necessary. I can see a
potential problem with either construction method if there is an overlap of trade types - unlikely
with 3 day trades, but possible. You will see that I have also reversed <= and made it >= . Previous
testing I have done shows that the latter configuration handles the first trade better for some
reason. Of course the If() test results also had to be reversed.
I question whether it is desirable to use a Ref() function with the Position variable, but where
else to put it I am not sure. For my own equity curve indicator I apply the delay directly to the
entry and exit signals. This has the effect of also delaying the Init, but other variable are kept
to zero delay wherever possible. The reason for avoiding a Ref() function is the same as that given
above for the new exits.
I still have to work my way through the Equity variable.
Hope this helps in the meantime.
Roy
rlarsen@xxxxxxxxxxxxx
> Thanks very much for this. I've looked at your suggestion and it seems to
> be a very similar trick to the one I'm using already (perhaps slightly
> better). Your Enter initialises at the same time as my Position variable.
> I'm not sure how this is going to help with my equity line and trade count
> variables which initilise very late.
>
> The variables :
> Position,
> LongEntry
> LongExit
> ShortEntry and
> ShortExit all get initialised early with the false triggers...
> I need the Equity and Win/Loss counts to initialise early too.
>
> Is it the way I've coded those specific variables?
{Periods:=5;} {Redundant when an Init signal is used as shown}
LongEntryPoint:=Ref(H,-1); {calc. on day of entry, limit order entry}
ShortEntryPoint:=Ref(L,-1); {calc. on day of entry, limit order entry}
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:=Alert(LongEntry,4) AND Alert(LongEntry,3)=0;
{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:=Alert(ShortEntry,4) AND Alert(ShortEntry,3)=0;
{auto exit 3 days later}
Init:=Cum(LongEntry<>2 AND LongExit<>2 AND
ShortEntry<>2 AND ShortExit<>2)=1;
Position:=Ref(If(BarsSince(LongEntry OR Init)>=
BarsSince(LongExit OR Init),0,1) +
If(BarsSince(ShortEntry OR Init)>=
BarsSince(ShortExit OR Init),0,-1),-1);
TotalLong:=Cum(Cross(Position,0.5));
TotalShort:=Cum(Cross(-0.5,Position));
Equity:=Cum(If(Cross(0.5,Position),ValueWhen(1,Cross(0.5,Position),
LongExitPoint)-ValueWhen(1,Cross(Position,0.5),LongEntryPoint),
If(Cross(Position,-0.5),ValueWhen(1,Cross(-0.5,Position),ShortEntryPoint)-
ValueWhen(1,Cross(Position,-0.5),ShortExitPoint),0)));
TotalLongWin:=Cum(If(Cross(0.5,Position),ValueWhen(1,Cross(Position,0.5),LongEntryPoint)<
ValueWhen(1,Cross(0.5,Position),LongExitPoint),0));
TotalLongLoss:=TotalLong-TotalLongWin;
TotalShortWin:=Cum(If(Cross(Position,-0.5),ValueWhen(1,Cross(-0.5,Position),
ShortEntryPoint)>ValueWhen(1,Cross(Position,-0.5),ShortExitPoint),0));
TotalShortLoss:=TotalShort-TotalShortWin;
Equity;
|