Rank: Newbie
Groups: Registered, Registered Users, Subscribers Joined: 2/25/2010(UTC) Posts: 6
|
Hi all,
I made search but could not find any answer... is it possible to transform any custom indicator to calculate its values from specific date or bar?
Thanks
Jamal
|
|
|
|
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 Jamal
Yes it is possible. There are a number of ways you could code MS for this to happen. Central to most methods is the need to identify the starting point required. If it's date-based then you might want to add inputs for DayofMonth(), Month() and Year() and code a variable that comes TRUE on or after the required date.
By using that "Start" point you could feed the original output through ValueWhen().
{Result;} {original result commented out}
Start:= {date met or exceeded code here};
ValueWhen(1, Cum(Start)>0, Result); {new Result output line}
As I said, there are a number of ways that each step could be coded and it's up to you to decide what is the most appropriate way to go. I'm not sure that you've conveyed the whole story and what you haven't told us might be the very thing that makes any specific suggestion unworkable. The thing with ValueWhen() is that it cannot produce an output until the Expression parameter comes TRUE at least for one bar. What happens after that depends on whether that paramater is held constantly TRUE or switched on and off
Roy
|
|
|
|
Rank: Newbie
Groups: Registered, Registered Users, Subscribers Joined: 2/25/2010(UTC) Posts: 6
|
Hi Roy,
{ Date inputs }
Copyright © 2003-2008 Jose Silva http://www.metastocktools.com }
StDay:=Input("start Day",1,31,1); StMnth:=Input("start Month",1,12,1); StYear:=Input("start Year",1800,2200,2005);
Result:=rsi(14); Start:=Year()>StYear OR (Year()=StYear AND (Month()>StMnth OR Month()=StMnth AND DayOfMonth()>=StDay)); aa:=ValueWhen(1, Cum(Start)>0, Result);
Thanks for replying, if I understand right way , it should be like this,
in this example rsi indicator begin whenever date you choose and does
not matter how many bar you loaded to your chart ...however is not be
true that when I expected the indicator should begin from 0 whenever
date I choose..
Jamal.
|
|
|
|
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 Jamal
Is there a question somewhere in "however is not be true that when I expected the indicator should begin from 0 whenever date I choose."?
The source of the code used doesn't quite fit, but you're using it exactly as I suggested. I'm not sure why you've named the ValueWhen variable unless you plan to take it on to another stage. When outputting "aa;" the result appears to do exactly what you asked for. Is there still a problem?
Roy
|
|
|
|
Rank: Newbie
Groups: Registered, Registered Users, Subscribers Joined: 2/25/2010(UTC) Posts: 6
|
Hi Roy,
Sorry my poor english, I just expected the indicator should begin from 0 value when I choose a specific date.... because it starts to calculate its value whenever date I choose.. So when I select date 01..01.2007 then indicator should begin from zero value on that time am I wrong with that? ..
Jamal
|
|
|
|
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 Jamal
Your assumption that this or any other indicator should start from zero is not correct. The selected indicator, RSI(14) in this case, begins generating a value right from the beginning of the chart. The only difference when ValueWhen() is introduced is that the earlier normal values do not plot on the chart until the selected date. Nevertheless the RSI(14) calculation does begin on bar one - you just can't see it from bar 14 until a plot from ValueWhen() is enabled.
If you want RSI() to start calculating on the given date, the way to do that is to inhibit the data used by RSI() until that point, and inhibit its result also. Changing your code to that below should do that for you. You need to be aware that RSI(14) (or RSI(C,14)) won't produce a truly accurate result until somewhere between 50 and 75 bars after the start date. This is a charactaristic of Wilders(), a function that is used internally to calcualte RSI() and a number of other common functions. This characteristic has been explained in this forum a number of times over the years.
StDay:=Input("start Day",1,31,1);
StMnth:=Input("start Month",1,12,1);
StYear:=Input("start Year",1800,2200,2005);
Start:=Year()>StYear
OR (Year()=StYear AND (Month()>StMnth
OR Month()=StMnth AND DayOfMonth()>=StDay));
Begin:=Cum(Start)>0;
Result:=RSI(ValueWhen(1,Begin,C),14);
ValueWhen(1,Begin,Result);
Roy
|
|
|
|
Rank: Newbie
Groups: Registered, Registered Users, Subscribers Joined: 2/25/2010(UTC) Posts: 6
|
Hi Roy,
Thank you for detail explanation :)
Jamal
|
|
|
|
Rank: Member
Groups: Registered, Registered Users Joined: 12/16/2005(UTC) Posts: 18 Location: Brisbane, Australia
|
Hi Roy,
Thanks for your info below, I've found it very helpful. One slight variation that I've been trying to do for a long time (without success!) is to plot an indicator over a number of periods only. So rather than date-based, using an input of number of periods. So either to plot the indicator a number of periods back from the current date or even plot the indicator back from a specified date would be very handy if at all possible? Thanks, much appreciated.
Kym
|
|
|
|
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 Kym
Limiting an indicator to plot just the last N periods (or frames) is not too difficult. First you need a down-counter for frames or bars. Let’s go with bars for the moment.
DC:=LastValue(Cum(1))-Cum(1);
This will have a value of zero on the last bar, so if you want a value of one for the last bar change DC to…
DC:=1+LastValue(Cum(1))-Cum(1);
To vary the display via the indicator's Parameters window then you need an Input() function to enter the required number of periods.
N:=Input("Periods to plot",5,9999,100);
DC:=1+LastValue(Cum(1))-Cum(1); DC;
The last line of code uses a ValueWhen() function to inhibit the target indicator’s output until the down-counter is equal to or less than your N-bars setting. For this exercise I’m just using the down-counter as the indicator display but this should work with virtually any indicator not already using 6 Input() functions.
{Limit Plot to N Bars}
N:=Input("Periods to plot",5,9999,100);
DC:=1+LastValue(Cum(1))-Cum(1);
{ }
{place your indicator in this space}
{ }
ValueWhen(1,N>=DC, DC {output signal name} );
If you want to count weeks or some other frame size you’d need to modify the DC down-counter variable to count weeks (or frames) instead of bars. Here’s hoping I’ve answered the right question.
If you want to “blank” the last N bars the trick is to calculate the number of bars you want to get rid of and then do a “Right / Left shuffle” with the signal to be partially blanked. This is just a matter of nesting one Ref() function inside another such that the inner Ref() function moves your expression to the right by N bars and then the outer Ref() function moves the truncated expression N periods to the Left. The shuffled expression ends up back where it started but missing the last N bars.
Roy
|
|
|
|
Rank: Member
Groups: Registered, Registered Users Joined: 12/16/2005(UTC) Posts: 18 Location: Brisbane, Australia
|
Thanks Roy, much appreciated. Am I right in saying the last line of code should read:
ValueWhen(1,N>=DC,{output signal name} );
Just one too many DCs in your last line?
Thankyou very much!
Kym
|
|
|
|
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 Kym
The extra DC was intentional so that the formula plotted 100 bars of the down-counter without any other code being added. This allows anyone to copy the code directly into the Indicator Builder and get a result even before adapting it to suit their own needs.
Roy
|
|
|
|
Rank: Member
Groups: Registered, Registered Users Joined: 12/16/2005(UTC) Posts: 18 Location: Brisbane, Australia
|
Ah......gotcha Roy. Thanks mate.
Kym
|
|
|
|
Rank: Member
Groups: Registered, Registered Users Joined: 12/16/2005(UTC) Posts: 18 Location: Brisbane, Australia
|
Hi Roy,
One last little issue I wanted to sort out. I’ve been trying to modify your code to produce a similar indicator that will only plot from a specific date and for N bars previous to that date. I’m obviously not a very good coder, but I think my code below does what I want except that it is also plotting something (it’s not the result?) from the specific date to the end of the chart. For some reason my code isn’t restricting the plot from the specific date to the right hand side of the chart. Much appreciated if you could eyeball the code see what I’m doing wrong. Thanks.
{Limit Plot from specific date to N Previous Bars}
EnDay:=Input("end Day",1,31,31);
EnMnth:=Input("end Month",1,12,3);
EnYear:=Input("end Year",1800,2200,2006);
N:=Input("Periods to plot",5,9999,100);
{Selected end date}
end:=Year()<enyear
OR (Year()=EnYear AND (Month()<EnMnth
OR Month()=EnMnth AND DayOfMonth()<=EnDay));
{Periods from end date to end of chart}
perenddate:=LastValue(Cum(end));
{Periods from end date - N periods to end of chart}
startrangedate:=LastValue(Cum(end))-N;
result:=C;
ValueWhen(1,Cum(1)<perenddate AND Cum(1)>=startrangedate,result);
|
|
|
|
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 Kym
It appears that your code got mangled when posted. Can you email me the code and possibly attach a chart setting out how the numbers and dates relate to each other. I'm not sure that I understand exactly what you're trying to do but I'm reasonably confident that it will be possible. I just need a clearer picture of where you're at and where you're trying to get to before I offer any further suggestions.
Roy
rlarsen@quik.co.nz
|
|
|
|
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.