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

Re: Can MS do loops?



PureBytes Links

Trading Reference Links

Hi ...

"previous" provides the pervious value of a formula or variable.

suppose you have a formula that gives you only a blip (to a true state ie value
one)

eg
buy:=cross(c,mov(c,21,e));
and
sell:=cross(mov(c,21,e),c);

these signals respectively will give a blip to a one when the close crosses to
above the 21 day exponential moving average and subseqently when it drops below.
ie they will switch to one for only one bar.

If you wanted to convert these two blips into a "am long" and "am out" signal to
use in the expert to colour being long as green, and being out as blue, you could
convert the two blips into a square wave by using the following formula

if(buy,1,
if(sell,0,previous));

ie if we have a buy blip switch to value one, if we have a sell blip switch to
value zero otherwise hold the previous value. This would switch to one on the buy
blip and then hold this value until we had a sell blip, at which time it would
switch to zero and stay there until we had another buy blip.

I have found the "previous" function invaluable when picking up and holding values
to use in indicators and experts. eg you can use the valuewhen function to pick up
the buy value on a buy blip and the sell value on a sell blip. But they appear
only for an instant (one bar). The "previous" function holds the values so that
you can subseqently deduct the buy value from the sell value to determine the
profit.

However, be warned that the "previous" function is very compute demanding and when
used over a long set of data, your machine may appear to "stall"

Regards ... Martin

Mullin285@xxxxxxx wrote:

> Thanks Ug
> I gotcha on the Ref, makes sense. Richard Estes gave me that one too. Thanks
> to both of ya.
> Prev is still foreign to me, but I'll play with it some more, as soon as I get
> a sec err... minute err... some time.
>
> Thanks for the reply
>
> Chris
>
> In a message dated 9/14/98 10:17:47 AM Eastern Daylight Time, ug@xxxxxxxxxxxx
> writes:
>
> > Mullin285@xxxxxxx writes:
> >
> >  > Thanks for popping in. Basically I am trying to learn how to use MS but
> > the
> >  > thing that triggered this particular question was ... I wanted to close
> my
> >  > long trades if there were 3 consecutive down days. I tried : C<prev and
> >  > C<prev-1 and C<prev-2 but that didn't work out right Seemed to be acting
> >  > more like I said or instead of and.
> >
> >  In this *particular* case, you probably want:
> >
> >  C < Ref(C, -1) and Ref(C, -1) < Ref(C, -2)
> >
> >  As I understand it, "PREV" refers to the value of the *entire* formula; not
> >  just the 'last thing it saw', so to speak.