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

Notification

Icon
Error

Options
Go to last post Go to first unread
eddie.m  
#1 Posted : Monday, February 27, 2012 9:28:52 AM(UTC)
eddie.m

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/20/2012(UTC)
Posts: 152

Was thanked: 1 time(s) in 1 post(s)
Hi, How to count the number of days that prices have been within a function? For instance, what is the number of days between the bar when the close crossed last time above 50-day simple moving average and the day when it crossed below? Ed.
wabbit  
#2 Posted : Monday, February 27, 2012 10:15:15 AM(UTC)
wabbit

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)
RTFM: BarsSince() wabbit [:D]
henry1224  
#3 Posted : Monday, February 27, 2012 10:20:57 AM(UTC)
henry1224

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/29/2004(UTC)
Posts: 1,394
Location: Glastonbury, CT

Was thanked: 2 time(s) in 2 post(s)
Event1:=Cross(C,Mov(C,50,S));
Event2:=Cross(Mov(C,50,s),C);
If(C<Mov(C,50,S),BarsSince(Event1)-BarsSince(Event2),BarsSince(Event1));

this will tell you how many bars C was greater than the 50 MA for each time event 1 is true
eddie.m  
#4 Posted : Monday, February 27, 2012 12:06:48 PM(UTC)
eddie.m

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/20/2012(UTC)
Posts: 152

Was thanked: 1 time(s) in 1 post(s)
Thank you Wabbitt. Thank you Henry, this is what I looked for.
eddie.m  
#5 Posted : Saturday, March 3, 2012 7:20:03 PM(UTC)
eddie.m

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/20/2012(UTC)
Posts: 152

Was thanked: 1 time(s) in 1 post(s)

Hello Henry,

I spent two hours trying to figure it out and I did a mess.

I need the Expert Advisor to say: there are X days since the Close crossed above the 50-day SMA: Y up days and Z down days.

There are X days since the Close crossed below the 50-day SMA: Y up days and Z down days.

You guys are better than me at programming. [:)]

wabbit  
#6 Posted : Sunday, March 4, 2012 6:22:07 AM(UTC)
wabbit

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)
Search the forum for count and reset codes. wabbit [:D]
henry1224  
#7 Posted : Sunday, March 4, 2012 7:53:39 AM(UTC)
henry1224

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/29/2004(UTC)
Posts: 1,394
Location: Glastonbury, CT

Was thanked: 2 time(s) in 2 post(s)
Eddie, when you say expert advisor to say

There are X days since the Close crossed above the 50-day SMA: Y up days and Z down days.
There are X days since the Close crossed below the 50-day SMA: Y up days and Z down days.

Are you looking for this value to show up on the chart or do you want the value in the expert commentary?

For ease of use , I would recommend that you create an indicator, then attach the expert to the chart,then save the chart as a template.

The way that I use experts is to show events on a chart.

I use highlights to define when I'm Long or Short
I use symbols to show entry and exit signals.
You can use the ribbon as another system
The commentary section is where you can show values

But for a quick scan of a chart to see the value of an indicator, I would use indicators as mentioned above.



eddie.m  
#8 Posted : Monday, March 5, 2012 7:15:44 PM(UTC)
eddie.m

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/20/2012(UTC)
Posts: 152

Was thanked: 1 time(s) in 1 post(s)
@wabbit Thanks, I shall search for the keywords you suggested.
Hi Henry, I need the value in the Expert Commentary, something like Total: 43 bars Up bars: 23 Down bars: 20 As for your other suggestions, I already do everything you suggested for several years now. But with programming, sometimes I just get stuck and waste too much time trying to find the answer by myself to no avail.
wabbit  
#9 Posted : Monday, March 5, 2012 9:09:36 PM(UTC)
wabbit

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)
Use the FmlVar() calls in your Expert Commentary to write the values from:

Code:
data:=close;
ma:=mov(data,50,S);

ch:=roc(data,1,$);
ch:=If(ch=0,valuewhen(1,ch<>0,ch),ch);

countUP:=cum(ch>0);
countDN:=cum(ch<0);

reset:=cross(data,ma) OR cross(ma,data);

counterUP:=countUP-valuewhen(1,reset,countUP);
counterDN:=countDN-valuewhen(1,reset,countDN);

{plot}
counterUP;
counterDN;



wabbit [:D]

eddie.m  
#10 Posted : Tuesday, March 6, 2012 8:24:28 AM(UTC)
eddie.m

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/20/2012(UTC)
Posts: 152

Was thanked: 1 time(s) in 1 post(s)
Thank you wabbit. Why must life be so complicated???? I assume data:=close; ma:=mov(data,50,S); to be under the formula name and the rest under the variable name. Right? I tried writeval(fmlvar("nameA","variableB"),0.0) and it didn't work.
wabbit  
#11 Posted : Tuesday, March 6, 2012 3:17:53 PM(UTC)
wabbit

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)
What I posted above is one indicator, complete; it can be attached to a chart, or it and its variables can be called from elsewhere in MS.

Expert Commentary:
Code:

Counter Up : writeval(FmlVar("myCountingIndicator","counterUP") ,0.0)

Counter Dn : writeval(FmlVar("myCountingIndicator","counterDN") ,0.0)





wabbit [:D]

eddie.m  
#12 Posted : Tuesday, March 6, 2012 7:07:02 PM(UTC)
eddie.m

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/20/2012(UTC)
Posts: 152

Was thanked: 1 time(s) in 1 post(s)
Hi Wabbit, I could have never done this by myself. I am not a programmer, and when I see what you can do, I totally capitulate ... Thank you, your code works like a charm ...
wabbit  
#13 Posted : Tuesday, March 6, 2012 9:09:30 PM(UTC)
wabbit

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)
The answers are all contained in the MS User Manual, the free Equis Formula Primer and the existing forum posts; all you have to do is look... wabbit [:D]
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.