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

Re: [Metastockusers] Fwd: Setting A Flag



PureBytes Links

Trading Reference Links

Hi Kevin

>>What is the most efficient way of setting a flag in Metastock? For
>>example, say I want to enter a trade on a signal but only, say, if there
>>has been an RSI overbought signal during the past four hours:
>>
>>flag:=If(Cross(RSI(14),70),1,0)
>>
>>initially sets the flag but it will get reset next bar. How can I keep the
>>flag set at 1 for the next four hours?

There are a number of ways you can do this. The subject will feature in my newsletter in a couple of 
months, but for now here's some latch (flag) code that should do the trick. You've already got the 
signal to set the latch and all you need is a signal to reset it. For my example I'll use the 
beginning bar of the next day.

FlagSet:=Cross(RSI(14),70);
FlagReset:=Hour()<Ref(Hour(),-1);
Flag:=BarsSince(FlagSet)<BarsSince(FlagReset);
Flag;

If you want to make sure the very first signal is picked up, perhaps for back-testing, then the code 
needs an initialisation (Init) variable added.

FlagSet:=Cross(RSI(14),70);
FlagReset:=Hour()<Ref(Hour(),-1);
Init:=Cum(FlagSet+FlagReset>-1)=1;
Flag:=BarsSince(Init+FlagSet)<BarsSince(Init+FlagReset);
Flag;

The same thing can be done with a little less code using PREV, but until you have a reset signal to 
complement the set signal no flag or latch code can work.



Kind regards

Roy Larsen
www.metastocktips.co.nz
Free formulas and MS links





------------------------ Yahoo! Groups Sponsor --------------------~--> 
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/zMEolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

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

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

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