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

Re: [EquisMetaStock Group] Issues with Variables



PureBytes Links

Trading Reference Links

Jose,

It's so obviously easy when one knows what one is doing. And you most
certainly do.

The deeper mystery for me to work on and from Roy's bits as well is,
how is it that MS works the way that it does? I would not have come to
this conclusion easily if at all on my own.

You and Roy should be running highly expensive vacation/course
offerings in your neck of the woods. I'd be there in a heartbeat.

And Equis should be showering you both with great gifts for being on
this board to support the product so well.

Thanks so much.



--- In equismetastock@xxxxxxxxxxxxxxx, "Jose" <josesilva22@xxxx> wrote:
> 
> Try this:
> 
> ---8<---------------------------------
> 
> value:=C;       { any value or formula }
> StDay:= 02;     { start Day,   1~31 }
> StMnth:=01;     {   "   Month, 1~12 }
> StYear:=2004;   {   "   Year, eg 2004 }
> 
> date:=Year()>StYear
>  OR (Year()=StYear AND (Month()>StMnth
>   OR Month()=StMnth AND DayOfMonth()>=StDay));
> date:=date AND Alert(date=0,2);
> ValueA:=LastValue(ValueWhen(1,date,value));
> ValueB:=LastValue(ValueWhen(1,date,Ref(value,-1)));
> 
> ValueA;ValueB
> 
> ---8<---------------------------------
> 
> jose '-)
> 
> 
> --- In equismetastock@xxxxxxxxxxxxxxx, "deepfoobar" <deepfoobar@xxxx> 
> wrote:
> > Roy,
> > 
> > As always you have given a heck of a lot here. BTW I'm signing up 
> for
> > your site/
> > newsletter. Least that can be done for all the help you have 
> offered.
> > (Hint Hint folks).
> > 
> > I'm going to give this a shot for sure. But I think the problem is
> > pretty fundamental 
> > and perhaps one that is very tough to deal with in MS as it is since
> > it has no loop 
> > control or assingment as in other languages.
> > 
> > What I really want to do in the example is pluck one value (in this
> > case the close) on a 
> > given date. The date here is the first trading day of 2004. Why? I'm
> > trying to evolve 
> > some Year-to-date indicators more for scanning purposes in the
> > Explorer than for 
> > charting.
> > 
> > So what I really am trying to do is pluck valueA from Jan 2, 2004 
> and
> > then compare it 
> > to the valueB (in this case the close of the prior day or today). 
> The
> > math bit in my 
> > example is just to display a percent change value between those 
> dates.
> > 
> > Here is the pseudo-code:
> > 
> > valueA:= the closing price  on Jan 2, 2004 
> > 
> > this is all I am interested in, and once assigned I don't want 
> valueA
> > to have any other 
> > value. see note below
> > 
> > valueB:= C, today's close
> > 
> > Now, here is the issue I have always had trouble with in MS. In 
> other
> > languages I can 
> > pluck a value from a matrix or list and that's the end of it. The
> > variable is assigned 
> > that value, end of story, no loop control necessary.
> > 
> > In MS however since the if/then structure always seems to require an
> > else valueA over 
> > the variable value's range goes something like this when I get it
> > back from the 
> > formula I sent.
> > 
> > <----- valueA
> > 
> > Jan 2, 2004: 39.00
> > Jan 5, 2004: 0
> > ...
> > Today's date:0
> > 
> > ------ >
> > What I want though is a variable that has only the first non-zero
> > value (Jan 2 in this 
> > case though it could be any date of choosing). Period. Yet MS seems
> > to offer no way 
> > to do that.
> > 
> > The problem is that if I want to use this value in an exploration, I
> > have to somehow 
> > parse it to get the non-zero, Jan 2nd value and then do the
> > manipulation. 
> > 
> > The only other MS approach I can think of is to somehow copy the one
> > value I want 
> > over the entire range of values.  In other words every value over 
> the
> > range of dates for 
> > valueA would be 39 to use the example above. Or somehow coerce the
> > non-zero 
> > value so that it would be the LastValue() of the variable.
> > 
> > Hope I have not utterly confused you. And maybe ValueWhen will do 
> it. 
> > 
> > 
> > --- In equismetastock@xxxxxxxxxxxxxxx, "Roy Larsen" <rlarsen@xxxx>
> > wrote:
> > > deepfoobar
> > > 
> > > I've looked at your code and I can't see what it is that you're
> > trying to achieve (my 
> > problem, not
> > > yours). However from your comments I think the function you need 
> is
> > ValueWhen(). 
> > The trick with
> > > ValueWhen() is to create an "EXPRESSION" that was last true on the
> > bar that has the 
> > value you want
> > > to record.
> > > 
> > > So if I wanted to extend the active value of your indicator from 2
> > January 2004 to 
> > the current bar I
> > > would change your last line by naming the variable, then add
> > ValueWhen() like so.
> > > 
> > > x:=If((Start<>End),varPercent+(100*(varC-(varB+C))/varC),0);
> > > ValueWhen(1,x>0,x);
> > > 
> > > To get this to plot on a chart properly when unscaled you might
> > need to add an 
> > "initialisation"
> > > signal. The purpose of this is to trigger the ValueWhen() at the
> > beginning of the 
> > chart. The value
> > > returned by that trigger is replaced by the genuine trigger from
> > the set data, but 
> > you need to
> > > remember that the pseudo (initialisation) trigger will create a
> > value even if the date 
> > signal does
> > > not occur for whatever reason.
> > > 
> > > ValueWhen(1,Cum(x>-1)=1 OR x>0,x);
> > > 
> > > Now, suppose your trigger signal was true for many bars, a date
> > range for example, 
> > and you only
> > > wanted the last true bar as the real signal. No change is 
> necessary
> > to the 
> > ValueWhen() because it
> > > will trigger on every bar up to the last true trigger bar. If you
> > wanted to return the 
> > value from
> > > the first bar of the date range then you need to convert the 
> signal
> > into a "leading 
> > edge" only
> > > signal.
> > > 
> > > ValueWhen(1,Cum(x>-1)=1 OR (x>0 AND Alert(x=0,2)) ,x);
> > > 
> > > Notice how I've used (x>0 AND Alert(x=0,2)) to create the leading
> > edge signal. you 
> > could use
> > > Ref(x,-1)=0 in place of Alert(), but in doing so you would
> > invalidate the 
> > initialisation expression
> > > because it is active while Ref(x,-1)=0 is still invalid. An 
> invalid
> > bar in an any 
> > expression in a
> > > variable makes the whole variable invalid.
> > > 
> > > Hope this helps.
> > > 
> > > Roy
> > > 
> > > > I have run into an annoying issue with MS I need help with.
> > Following
> > > > Roy Larsen's example I've been able to write some date code that
> > works
> > > > well in isolating the start and end of data to look at.
> > > >
> > > > The recent issue is that I want to be able to grab a value from 
> a
> > date
> > > > and return that value in a variable to use in explorations.
> > > >
> > > > Right now I have the code set up so that I get the expected 
> value
> > on
> > > > the specific date and zero otherwise. That works fine as far as
> > plots
> > > > go, but stops me dead in my tracks when it comes to using the
> > variable.
> > > >
> > > > Here is the code such as it is:
> > > > << ---------------
> > > >
> > > > Sd:=2;
> > > > Sm:=1;
> > > > Sy:=2004;
> > > >
> > > > Start:=(DayOfMonth()>=Sd AND Month()=Sm AND
> > > > Year()=Sy);
> > > >
> > > > End:=(DayOfMonth()>=Sd+1 AND Month()=Sm AND
> > > > Year()=Sy);
> > > >
> > > > varB:=0;
> > > > varPercent:=0;
> > > > varC:=LastValue(C);
> > > >
> > > > If((Start<>End),varPercent+(100*(varC-(varB+C))/varC),0)
> > > >
> > > > ------------------- >>
> > > >
> > > > Is there a way to isolate a variable only to the non-zero result
> > (this
> > > > would be varPercent)? The problem seems to be near as I can tell
> > that
> > > > I must be getting only the last value back from this instead of
> > the
> > > > variable, and thus always zero.
> > > >
> > > > In other languages this would be a snap. I'm at a loss in how to
> > tell
> > > > MS not to stomp all over this and return the non-zero result.
> > > >
> > > > Hope this was resonably clear. I want the variable back in
> > isolation
> > > > for that date by the way to use in other calculations. It is not
> > > > necessary for it to be plotted at all really.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > 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/