Rank: Advanced Member
Groups: Registered, Registered Users Joined: 3/23/2010(UTC) Posts: 60
|
Is there a way to count back from the most current data entered? Something similar to the "Bars Since" function. For example if I move back three days from the latest most current data point, the function will count three time periods. I need to create an indicator that uses the number of counted time periods back from the most recent data and use that value to trigger a calculation.
Thanks,
dlipter
|
|
|
|
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
Would a reverse bar count help?
{Bar Count - Reverse} LastValue(Cum(1))-Cum(1);
This is useful for relating to the last bar of data but not so useful when needing to relate one hstorical bar to another historical bar. You say that you're only interested in counting back from the most recent bar so the above formula should work fine.
Roy
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 3/23/2010(UTC) Posts: 60
|
Roy,
Yes...your formula works like a charm!
I still have a vexing problem.
The formula: if(fml ("Bar Count- Reverse")>2, f1,f2) works fine where say f1 is a 5 period moving average and f2 is a 15 period moving average. It will plot f1 until 2 days before the last day, then for the final 2 days it plots f2.
Where the above "if" formula fails to work is where f1= Ref (Mov(MP( ),5,s),2) which is a 5 period MA displaced back 2 periods. In this case f2 doesn't plot for the final 2 days.
Ideas?
Thank's
dlipter
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers, Unverified Users Joined: 10/28/2004(UTC) Posts: 3,111 Location: Perth, Western Australia
Was thanked: 16 time(s) in 16 post(s)
|
Your Ref() is looking into the future; use a negative value.
See the MS Users Manual. Or, read the plethora of posts about the dangers of creating untradable-in-real-life indicators and systems.
wabbit [:D]
|
|
|
|
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 dlipter
The cause of the problem is obvious to me but I'm not sure whether it's intentional on your part or not. Your "displaced back 2 periods" is actually giving you a displacement forward 2 periods (the Periods parameter for the Ref() function is positive rather than negative). Fix that and the problem will disappear. If you really want the MA to be moved forwards (into the future) then a solution eliminating N/A is possible but not quite as simple as just changing a parameter or two.
Roy
|
|
|
|
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)
|
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 3/23/2010(UTC) Posts: 60
|
The formula Ref (Mov(MP( ),5,s),2) computes the average on lets say day 10 and plots that value on day 8, so the plotted average is moved back in time by 2 days. The value is always computed two days in advance. The plotted average will always trail the last data point by 2 days leaving the last two days blank. I want to substitute a proxy for the average on the two unplotted days using the If function to bring the plotted average forward to cover the last 2 data points using the third parameter in the If function.
The formula suggested Ref (Mov(MP( ),5,s),-2) using a -2 will plot an average displaced in the wrong direction resulting in an inaccurate representation of of the price data in the period. A simple average is only representative of the data in the period when it is plotted at the center of the period, hence my need to displace the average back 2 periods.
If you apply a trailing 5 day average and a centered 5 day average (displaced back in time by half the average length) over a price plot you will see that the centered average is superior in all aspects except that its plot lags the data by 1/2 the average length, in this case 2 days.
dlipter
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 3/23/2010(UTC) Posts: 60
|
mstt wrote:
Hi dlipter
If you really want the MA to be moved forwards (into the future) then a solution eliminating N/A is possible but not quite as simple as just changing a parameter or two.
Roy
What is N/A?
dlipter
|
|
|
|
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 dlipter
Open the Data Window and pass the cursor over the last two data bars. What value is shown for the last two bars (and first two as well)? N/A means that no result is generated.
Roy
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 3/23/2010(UTC) Posts: 60
|
Roy,
Ok...got the meaning of N/A.
"If you really want the MA to be moved forwards (into the future) then a solution eliminating N/A is possible but not quite as simple as just changing a parameter or two."
The solution you alluded to in the above quote would be?
One thing I noticed is, if I create two empty data days into the future with zero values in the data fields, the Ref (Mov(MP( ),5,s),2) function will work within the If function with the previously two empty data days filled in with the third paramater of the If function.
|
|
|
|
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)
|
Here's one thought I had in mind. The last two bars plot the same value as the last valid bar. Whether that's relevant to what you're trying to do I don't know. What the Forum DLL Sum function does is convert an N/A result to a zero result - what you convert those zeros into is up to you.
Signal:=Ref(Mov(MP( ),5,S),2); Defined:=IsDefined(Signal); Signal:=ExtFml("Forum.Sum",Signal,1); ValueWhen(1,Defined,Signal);
Roy
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 3/23/2010(UTC) Posts: 60
|
I am using MSv11 EOD.
When I enter your foumula I get an error: "This DLL does not exist in the MSX DLL folder" for the "Forum.Sum" function.
Is this DLL standard to MS? I might have deleted it when I exported and deleted a bunch of Custiom Indicators I didn't think I would need.
Or.....Is the "Forum.Sum DLL" in the File Download Section?
ForumDll 200 maybe?.....OK it's there!
Is it Listed as "Variable SUM Function?...I think so!
Holy Cow!!!!! It seems to be working!
Fantastic...I'll have to study your formula to understand it.
Thank You
|
|
|
|
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)
|
The Forum DLL is available as a free download from this site by going to http://forum.equis.com/files/default.aspx. It's labelled as "Forum Dll 200" but can be renamed anything you like. I prefer shorter names hence just "Forum" in my code - it's more economical with the limited space that MetaStock allows for each formula. If you have any version under a different name you can either change the name or change my code. The 188KB file is the latest and probably most useful/error-free version but as long as it's named differently it can coexist in MetaStock with earlier versions.
The User Manual was written by Wabbit for an earlier version and does not over all the functions offered by the "200" version. However you can identify the available functions and their syntax after installation by opening any indicator (or create a new one), and clicking in the Formula window then click on the functions button. Scroll down until you come to Forumand mark it. Yo'll see a lits offunctions in the Paste Function window and by marking any function you can read off the syntax from the Format window. DON'T click the OK button unless you want to paste the function into the indicator you have open.
Be aware that fuction names in Forum Dll 200 are not the same as those in Forum Dll 112 even when they do the same job.
Roy
|
|
|
|
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)
|
Should read "Scroll down until you come to Forum and mark it. You'll see a list of functions in the Paste Function window"
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 3/23/2010(UTC) Posts: 60
|
mstt wrote:
Here's one thought I had in mind. The last two bars plot the same value as the last valid bar. Whether that's relevant to what you're trying to do I don't know. What the Forum DLL Sum function does is convert an N/A result to a zero result - what you convert those zeros into is up to you.
Roy
Could the formula make the last two bars plot a function or custom indicator instead of the value of the last valid bar?
Lets say price midpoint as an example.
dlipter
|
|
|
|
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)
|
Yes
Signal:=Ref(Mov(MP( ),5,S),2); Defined:=IsDefined(Signal); Signal:=ExtFml("Forum.Sum",Signal,1); If(Defined,Signal,Mid(C,5));
Roy
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 3/23/2010(UTC) Posts: 60
|
mstt wrote:
Yes
Signal:=Ref(Mov(MP( ),5,S),2); Defined:=IsDefined(Signal); Signal:=ExtFml("Forum.Sum",Signal,1); If(Defined,Signal,Mid(C,5));
Roy
So whatever function or custom indicator I drop in place of "Mid(C,5)" in the last line of the above formula will be plotted in the last two Bars?
|
|
|
|
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)
|
Yes. Just be careful that you don't introduce new N/A bars into the If() function result with the formula you use. For example, a formula that only begins to plot on the 10th to last bar will force the If() function to do likewise.
Roy
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 3/23/2010(UTC) Posts: 60
|
mstt wrote:
Yes
Signal:=Ref(Mov(MP( ),5,S),2); Defined:=IsDefined(Signal); Signal:=ExtFml("Forum.Sum",Signal,1); If(Defined,Signal,Mid(C,5));
Roy
I don't understand the syntax, you have two variables with the same name "Signal". "Signal" is mentioned in the 2nd, 3rd, and 4th line equations.
In the last line, "Signal" refers to the 1st line variable or the 3rd line variable. Since the formula plots line 1 it must refer to line 1.
Is this covered in the Formula Primer?
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 3/23/2010(UTC) Posts: 60
|
blackcat54 wrote:mstt wrote:
Yes
Signal:=Ref(Mov(MP( ),5,S),2); Defined:=IsDefined(Signal); Signal:=ExtFml("Forum.Sum",Signal,1); If(Defined,Signal,Mid(C,5));
Roy
I don't understand the syntax, you have two variables with the same name "Signal". "Signal" is mentioned in the 2nd, 3rd, and 4th line equations.
In the last line, does "Signal" refer to the 1st line variable or the 3rd line variable?
Is this covered in the Formula Primer?
|
|
|
|
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.