Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 5/27/2006(UTC) Posts: 135
|
Have a indicator that plot 1 when signal and 0 when no signal. Wanted to plot the value of close when the indicator is 1 on the entire previous no signal period (ard 1 month) and update the close on next signal when the indicator is 1. Is this possible? Just like plotting the close on 30th jan for the entire jan month.
|
|
|
|
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)
|
I dont quite understand the problem, but have a look at the ValueWhen() function? Code:signal:={your signal};
valuewhen(1,signal,close);
Plotting the end of the month value before the end of the month is using foresight, and although it can be done programatically, it often gives the trader a false sense of security that cannot be traded in real life. Hope this helps. wabbit [:D]
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 5/27/2006(UTC) Posts: 135
|
Hi Wabbit,
The valuwhen plots the value forward rather than backward. Says for 31th Jan close, the close value is plotted in feb month. But wanted to plotted in Jan month instead. This is just for chart purpose and not for backtesting.
Tried using the Ref(X,31) to reference the forward value but this seems to have problem because some months has 31 days some month has 30 days or 29 days. So tried to devise a fomula to track the number of days in a month and use that value in ref(X,num of days in month) but MS says REF( ) only allow numeric value and formula derived number is not allowed. Any idea?
|
|
|
|
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)
|
One of the limitations of the MS formula language is it doesn't allow you to work through the data from right to left, only from left to right. There might be some MS formula tricks using the ValueWhen(), LastValue() and/or PREV (and maybe some of the forum.dll functions) that might allow you to make this function, but it doesn't immediately spring to mind.
When dealing with time/date issues, you also have to be cognisant that charts deal in "bars" not calendar days, so attempting to shift indicators x-bars where x is based on the number of calendar days in the month is going to run into trouble from the start. You cannot even be assured there will exist a bar for every trading day in the month as some equities are not traded on every trading day. The only thing you know is, if a bar exists the equity traded on that day.
Generally speaking, if I have to spend more than a short period of time thinking about how to work around the limitations of the MS formula language, I will generally stop wasting any further time and simply program an external indicator in a much more powerful programming language that has access to the entire data range and can access it in any order desired. Of course, you have to have the MDK to be able to do this.
Maybe someone else might like the challenge, but I'd either get the MDK or get someone to build this one for you as a library function.
wabbit [:D]
|
|
|
|
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)
|
I did a quick play with some code over a glass (or two) of wine and came up with something which might be suitable; be warned it wont be entirely correct, but I thought the code was kinda cute [:)] Code:start:=Month()<>Ref(Month(),-1);
data:=ValueWhen(1,start,Ref(C,-1));
If(Cum(start)<LastValue(Cum(start)),
ExtFml("forum.ref",data,-(32-DayOfMonth())),
LastValue(C));
Maybe it will give you some inspiration on how to tackle this further? I still think the library function is the better solution though... wabbit [:D] P.S. You'll need the forum.dll if you don't already have it.
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 5/27/2006(UTC) Posts: 135
|
Where to download Forum.dll?
Have two indicators that each plot 1 once a month. When the two are add together, there are some month which both indicator plotted 1 (total 2 in a month). Indicator B is after Indicator A. Is possible to code in a way that ignore indicator A (return 0 rather than 1) and plot just indicator B in month which both indicator return 1?
|
|
|
|
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)
|
Flexi wrote:Where to download Forum.dll?
Files section. Flexi wrote:Have two indicators that each plot 1 once a month. When the two are add together, there are some month which both indicator plotted 1 (total 2 in a month). Indicator B is after Indicator A. Is possible to code in a way that ignore indicator A (return 0 rather than 1) and plot just indicator B in month which both indicator return 1?
A OR B ? wabbit [:D]
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 5/27/2006(UTC) Posts: 135
|
Indicator A and B are both for optionexp on wednesday (index option).
if(optionexp()=3 and dayofweek()=3,indicatorA,0); if(optionexp()>32 and dayofweek()=3,indicatorB,0);
The problem is on month which has more than 32 bars, indicator A and B would both plot 1 for the same month even indicator B is after indicator A.
Wanted to code in a way that return indicator B (plot 1) and ignore indicator A (plot 0) on month which has bars more than 32. There is only one option exp per month
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 5/27/2006(UTC) Posts: 135
|
Wabbit do you think the code you posted below possible to adapt to plot the close on option exp on the option exp month?
start:=Month()<>Ref(Month(),-1); data:=ValueWhen(1,start,Ref(C,-1));
If(Cum(start)<LastValue(Cum(start)), ExtFml("forum.ref",data,-(32-DayOfMonth())), LastValue(C));
|
|
|
|
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)
|
Flexi wrote:Indicator A and B are both for optionexp on wednesday (index option).
if(optionexp()=3 and dayofweek()=3,indicatorA,0); if(optionexp()>32 and dayofweek()=3,indicatorB,0);
The problem is on month which has more than 32 bars, indicator A and
B would both plot 1 for the same month even indicator B is after
indicator A.
Wanted to code in a way that return indicator B (plot 1) and ignore
indicator A (plot 0) on month which has bars more than 32. There is
only one option exp per month huh? Code:(dayofweek()=3) * if(optionexp()>32,indicatorB,indicatorA);
??? wabbit [:D]
|
|
|
|
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)
|
Flexi wrote:Wabbit do you think the code you posted below possible to adapt to plot the close on option exp on the option exp month?
start:=Month()<>Ref(Month(),-1); data:=ValueWhen(1,start,Ref(C,-1));
If(Cum(start)<LastValue(Cum(start)), ExtFml("forum.ref",data,-(32-DayOfMonth())), LastValue(C)); Yes I do think it's possible: Change the "start" variable and the look ahead referencing: Code:oe:=optionexp();
start:=oe>Ref(oe,-1);
data:=ValueWhen(1,start,Ref(C,-1));
If(Cum(start)<LastValue(Cum(start)),
ExtFml("forum.ref",data,-oe),
LastValue(C));
Using the MS Users Manual and the knowledge gained through completing the home study exercises in the free Equis Formula Primer will help you to write these codes for yourself. The forum is not a free "do-my-work-for-me" community; we're here to ASSIST you to do the work yourself and improve your learning. wabbit [:D]
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 5/27/2006(UTC) Posts: 135
|
Wabbit does the code below works only for optionexp() when plotting backward? When tried using other indicator instead of of optionexp() the close plots forward rather than backward.
oe:=optionexp(); start:=oe>Ref(oe,-1); data:=ValueWhen(1,start,Ref(C,-1));
If(Cum(start)<LastValue(Cum(start)), ExtFml("forum.ref",data,-oe), LastValue(C));
------------------
oe:=Indicator1 { Plot 1 or 0 }; start:=oe<Ref(oe,-1); data:=ValueWhen(1,start,Ref(C,-1));
If(Cum(start)<LastValue(Cum(start)), ExtFml("forum.ref",data,-oe), LastValue(C));
------------------
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 11/25/2006(UTC) Posts: 79
|
|
|
|
|
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.