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

Re: [EquisMetaStock Group] Issues with Variables



PureBytes Links

Trading Reference Links

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/