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

Re: Indicator System problem



PureBytes Links

Trading Reference Links

Sean

I'll take a closer look at your code over the weekend when I have a bit more time on my hands.

Roy 


> 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?
> 
> Thanks,
> Sean
> 
> -----Original Message-----
> From: owner-metastock@xxxxxxxxxxxxx
> [mailto:owner-metastock@xxxxxxxxxxxxx]On Behalf Of Roy Larsen
> Sent: Thursday, June 28, 2001 6:02 PM
> To: metastock@xxxxxxxxxxxxx
> Subject: Re: Indicator System problem
> 
> 
> Sean
> 
> One of the annoying problems with the ValueWhen() function is that it is
> invalid until the When
> condition is true. A method I have adopted at times to get around this is to
> include an
> initialisation signal. For example in my "Trade Flag" (shown below) code I
> use a variable I call
> "Init" to signal the first bar when both the Buy and Sell variables are
> valid.  Init can then
> sometimes be legitimately used to fake a signal that is valid but not true
> until some bars later.
> 
> In the example below I want to use Enter (the first bar in a trade) in a
> ValueWhen() function, but
> to ensure that ValueWhen() is valid from the earliest possible bar I include
> "OR Init" in the code
> for Enter.
> 
> Buy:=Fml("Your Long Entry");
> Sell:=Fml("Your Long Close");
> Init:=Cum(Buy<>2 AND Sell<>2)=1;
> Trade:=If(BarsSince(Init OR Buy) >= BarsSince(Init OR Sell),0,1);
> Enter:=(Trade AND Alert(Trade=0,2)) OR Init;
> 
> While this won't solve all your problems it may give you one workaround for
> use with ValueWhen().
> 
> Roy
> 
> 
> > Below I've tried to code the framework for a system as an indicator.  It's
> > being debugged at present and doesn't include proper exit signals or use
> of
> > the P variable to introduce Interest rate change.  All things for the
> > future.  Enough excuses...
> >
> > I've run into the problem of variables being initialised late and despite
> > the use of early false entry/exit signals, the Equity variable (for
> example)
> > doesn't get initialised until both a real Long and Short signal get
> > generated.
> >
> > Grateful for any help.
> >
> > Thanks,
> > Sean
> >
> >
> > {Larry Williams - Long-Term secrets to Short-Term trading p.102}
> > {Smash Day BUY has up close but in lower 25% of days range,
> > Close less than Open.  Enter tomorrow at today's High.
> > Sell Short is opposite.
> > Should combine with strong trend and interest rates}
> > {System uses following day entry}
> > Periods:=5; {Used to delay false early triggers if necessary}
> > 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:=If(Cum(1)=Periods+1,1,
> >     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:=If(Cum(1)=Periods+4,1,
> >     barsSince(LongEntry)=3);{auto exit 3 days later}
> > ShortEntry:=If(cum(1)=Periods+6,1,
> >     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:=If(Cum(1)=Periods+9,1,
> >     barsSince(ShortEntry)=3);{auto exit 3 days later}
> > Position:=If(Ref(BarsSince(LongEntry)<=BarsSince(LongExit),-1),1,
> >     If(Ref(BarsSince(ShortEntry)<=BarsSince(ShortExit),-1),-1,0));
> > 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),Lon
> > gEntryPoint)<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;
> >
> >
> >
> 
> 
>