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.
|
|
|
|
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]
|
|
|
|
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
|
|
|
|
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.
|
|
|
|
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. [:)]
|
|
|
|
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]
|
|
|
|
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.
|
|
|
|
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.
|
|
|
|
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]
|
|
|
|
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.
|
|
|
|
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]
|
|
|
|
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 ...
|
|
|
|
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.