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

Re: [EquisMetaStock Group] Entry testing code issues



PureBytes Links

Trading Reference Links

Hi Andrew

> For a long and short system, I am ending up with code with 4 PREV latches. I
> can't get the indicator exit and the time stop in the same latch since the
> time stop needs to refer to the prior latch to set the clock running. This
> seems to work, but it feels clumsy - is there a better way?

The timestop can be built into one PREV latch quite easily

Trigger2:= If(PREV=0,If(Set,1,0),If(Reset  OR BarsSince(PREV=0)>=B2,0,PREV));

The PREV count can be cut back to two by substituting 1 for the last PREV. This latch is only
remembering a binary state (zero or one) and since the first If() has already tested for the
previous state there is no need for PREV at the end. Once the latch is set (to one) it will reatain
a value of 1 until there is a Reset.

Trigger2:= If(PREV=0,Set,If(Reset OR BarsSince(PREV=0)>=B2,0,1));

Here's the abreviated version. I prefer to use ">=" when testing for a bar count, as opposed to "=",
because with more complex logic it there may be something else happening on the same bar that causes
the "=" to be missed. Using ">=" prevents any possibility (with flakey code admittedly) of the count
dissappearing into the stratosphere.

There's no need for an If() where you have Set.

Now another point about your determination of the direction of the the EMA. There's a simpler way to
decide if the EMA is going up or down. By it's nature an EMA must go up if the price is above it,
and conversly, the EMA must go down if the price is below it. Therefore any time the price crosses
the EMA we know that the EMA has reversed direction.

MA:=  Mov(C,B1,E);         {today's MA}
MA1:= Ref(Mov(C,B1,E),-1); {yesterday's MA}
MA2:= Ref(Mov(C,B1,E),-2); {day before yesterday's MA}
Set:=   MA2>=MA1 AND MA1<MA;   {MA turns up}
Reset:= MA2<=MA1 AND MA1>MA;   {MA turns down}

This code above can be reduced to this.

MA:= Mov(C,B1,E);   {today's MA}

Set:= Cross(C,MA);   {MA turns up}
Reset:= Cross(MA,C);   {MA turns down}

This "law" determining the direction of an EMA also applies to Wilders Smoothing, but not to
non-exponential noving averages.

Hope this helps

Roy


> Here's an example, written as an indicator which will show long positions as
> +1, short as -1 and time out of the market as 0. The entry is on the slope
> of a moving average. I've annotated the long side for clarity. Short is just
> the opposite of long. I have included entry and exit signals for use in
> TE/TradeSim/System Tester although they're not actually used in the
> Indicator. Ideally I'm trying to get to a baseline code that I can use to
> quickly compare different entries. [NB this is not a tradable system -it
> cuts off trends way too early- just an exercise to compare different
> entries]
>
> Thanks for your thoughts
> Andrew
>
> ----------------------------------------------------------------------------
> ---------------------------
>
> {Single MA System - gives entry signals when slope of MA changes to up or
> down in one day. Exit is a reverse signal or a time stop. Indicator.}
>
>
> B1:= Input("Enter bars for MA1",1,300,50);
> B2:= Input("Enter bars for TStop",1,100,10);
>
> MA:=  Mov(C,B1,E);         {today's MA}
> MA1:= Ref(Mov(C,B1,E),-1); {yesterday's MA}
> MA2:= Ref(Mov(C,B1,E),-2); {day before yesterday's MA}
>
> Set:=   MA2>=MA1 AND MA1<MA;   {MA turns up}
> Reset:= MA2<=MA1 AND MA1>MA;   {MA turns down}
>
> Trigger1:= If(PREV=0,If(Set,1,0),If(Reset,0,PREV));
>      {first binary trigger for set and reset signals}
> TStopL:=if(Trigger1=1,if(barssince(roc(Trigger1,1,$)>0)=B2,1,0),0);
>      {time stop keying off Trigger1}
> Trigger2:= If(PREV=0,If(Set,1,0),If(Reset OR TStopL,0,PREV));
>      {second binary trigger to include time stop}
> Long:=Trigger2;
>
> EL:=if(ref(long,-1)=0,if(set,1,0),0);
>     {Enter Long if you're out of the market and get an indicator buy}
> CL:=if(ref(long,-1)=1,if(Reset OR TStopL,-1,1),0);
>     {Close Long on an indicator sell or time stop}
>
>
> Trigger3:= If(PREV=0,If(Reset,1,0),If(Set,0,PREV));
> TStopS:=if(Trigger3=1,if(barssince(roc(Trigger3,1,$)>0)=B2,1,0),0);
> Trigger4:= If(PREV=0,If(Reset,1,0),If(Set OR TStopS,0,PREV));
> Short:=Trigger4;
>
> ES:=if(ref(short,-1)=0,if(Reset,1,0),0);
> CS:=if(ref(short,-1)=1,if(Set OR TStopS,-1,1),0);
>
> Long - Short; {i.e., will show +1 for long market position, -1 for short and
> 0 for out}
>
>
>
>
>
>
> -----Original Message-----
> From: praktikus_ms [mailto:praktikus@xxxxxxxxxx]
> Sent: Monday, June 28, 2004 8:36 AM
> To: equismetastock@xxxxxxxxxxxxxxx
> Subject: [EquisMetaStock Group] Re: unnecessary repetitive signals
>
>
> Hormuz,
>
> Go to the files section of this group and search for a word document
> called 'Using Latches in MS.doc' by Roy Larsen. This should give you
> an idea about how solve this problem.
>
> A quick shot would be:
>
> {Trade Latch; Idea by                   }
> {2004 Roy Larsen, rlarsen@xxxxxxxxxxxxxx}
> Set:=Fml(your long therm buy signal);
> Reset:=Fml(your long term sell signal); Init:=Cum(Set+Reset>-1)=1;
> Trade:=If(BarsSince(Init+Set)<BarsSince(Init+Reset),1,-1);
> Trade; {swings between +1 and -1}
>
> This gives you an output of +1 for the buy signal and -1 for the sell
> signal. Just assign those to your expert signals and you should doing
> fine.
>
> Martin
>
>
> --- In equismetastock@xxxxxxxxxxxxxxx, hormuz maloo
> <hormuzmaloo@xxxx> wrote:
> > Hi everybody,
> > I am trying to program my own expert advisor, which
> > gives long-term buy and sell signals.
> > Have just got started, but I find that the buy or sell
> > signal is repeated everytime the pattern is found on
> > the chart.
> > What I would like to do is see that a buy signal does
> > not follow a buy signal, ie a buy signal should occur
> > only if the previous signal was a sell signal and vice
> > versa.
> > Can somebody please show me a simple way to do this.
> > Thanks in advance,
> > Hormuz Maloo
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>




------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/BefplB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/equismetastock/

<*> To unsubscribe from this group, send an email to:
     equismetastock-unsubscribe@xxxxxxxxxxxxxxx

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