logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Dendee  
#1 Posted : Sunday, August 30, 2009 6:39:07 AM(UTC)
Dendee

Rank:: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 8/13/2009(UTC)
Posts: 6

When plotting my Stop Loss Indicator I use ":= Input" to input the day, month, year. With daily bars this is fine, but if I am using Weekly bars, the Close Day of the weekly bar is the last day of the week, which may not be actual day I entered. When I enter a date that is mid week using weekly bars, the indicator won't find that date and therefore can't calculate. I need a formulae that, when I enter a mid week date, the formulae will look back (or forward) one day at a time up to 5 days until it finds the actual close date of that particular weekly bar, then calculate ithe indicator. Could someone please help me with such a formulae? Thanks
mstt  
#2 Posted : Sunday, August 30, 2009 3:04:23 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)

Dendee

Try one of these options. If you want the date signal to stay TRUE until the last bar of data then just remove Cum()=1 from the output line. A date filter that goes FALSE with a stop date is also a very useful addition to most MetaStock formula collections.

Roy

{Start Date}

{Roy Larsen, 2003-2009}

Dd:=Input("Start Day" ,1,31,1);

Mm:=Input("Start Month",1,12,6);

Yy:=Input("Start Year" ,1980,2010,2008);

D:=DayOfMonth(); M:=Month(); Y:=Year();

N:=(D>=Dd)*(M=Mm)*(Y=Yy)+(Y=Yy)*(M>Mm)+(Y>Yy);

Cum(N)=1;

{Start Date 2}

{Date concept by metastocktools.com}

Start:=Input("Start Date - YYMMDD ",101,991231,080601);

N:=IsDefined(Rnd(Life(Start)));

Cum(LastValue(Cum(N))=Cum(N))=1;

Dendee  
#3 Posted : Monday, August 31, 2009 6:03:04 AM(UTC)
Dendee

Rank:: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 8/13/2009(UTC)
Posts: 6

Thanks for your posting Roy. I tried both of your suggestions but neither worked for me; probably because I am a novice and don't know enough yet. To clarify I am using the following Trailing Stop Loss indicator that I read about somewhere!
Bd := Input("Day of Month" ,1,31,1); Bm := Input("Month" ,1,12,1); By := Input("Year",1985,2030,2009); BPr:=Input("Buy Price ($):",0,15000,1); TSE1 := BarsSince(DayOfMonth() = Bd AND Month() = Bm AND Year() = By); TSE2 := HighestSince(1,TSE1=0,C) ; TSE3 := TSE2 - TSE2*15/100; TSE4:=HighestSince(1 ,TSE1 = 0,TSE3 ); If(TSE1=0,BPr-(BPr*15/100),Max(BPr-(BPr*15/100),TSE4));
This works fine with Daily periods because every day is always present on the chart, however Weekly and Monthly periods are a problem because the end day for each bar rolls forward by one day for each new day. When using 'weekly' periodicity, if I enter the date/month/year inputs today, come tomorrow the date won't be in the chart as the bar end date will be tomorrows date, so my formulae won't work. I want my actual 'input' date to work but it can vary up to 5 days older (but no more). Say I input 23/06/2009 (dd/mm/yyyy), then I want the indicator to use the 23/06/2009 but it can't find it, then it may be any date up to 5 days older. On the 6th day of course the 23/06/2009 will appear once again on the prevoius bar and the indicator will work again. Any help would be much appreciated.
mstt  
#4 Posted : Monday, August 31, 2009 3:11:52 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)

Hi Dendee

A little bit of work was required to adapt the Start Date formulas I suggested. The output from each is a single bar spike TRUE, and for that reason I suggested removing the Cum()=1 function from the output (result) expression to allow the output to stay TRUE through to the last bar. Dropping in a new start formula with Cum()=1 removed from its output expression gives a plot even when there is not an exact match for the date.

The essential problem with the original start date marker is that it relies on an equality test for day, month and year. The solutions I offered pick up the next available bar when the given date does not match any existing bar and cannot meet all equality tests.

Start:=Input("Start Date - YYMMDD ",101,991231,090101);

{Date concept by metastocktools.com}

N:=IsDefined(Rnd(Life(Start)));

TSE1:=LastValue(Cum(N))=Cum(N);

BPr:=Input("Buy Price ($):",0,15000,1);

TSE2:=HighestSince(1,Cum(TSE1)=1,C);

TSE3:=TSE2 - TSE2*15/100;

TSE4:=HighestSince(1,TSE1=0,TSE3);

If(TSE1=0,BPr-(BPr*15/100),Max(BPr-(BPr*15/100),TSE4));

I make no guarantee that this formula will do everything you want either. What I will say, though, is that almost any problem you strike WILL have at least one solution. As you gain confidence and experience with the MFL you’ll discover that most problems have several solutions.

Roy

Dendee  
#5 Posted : Monday, August 31, 2009 11:32:25 PM(UTC)
Dendee

Rank:: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 8/13/2009(UTC)
Posts: 6

Thanks Roy. Your suggestions worked like a dream. I will fiddle on the edges to personalise the wording and hopefully learn why it works. I have written MS Access & Excel formulae OK, but as far as MFL goes, it is so different and I am getting mental blocks, confusion and high blood pressure. Must be my senior years of age. Denis
Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.