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

Notification

Icon
Error

Options
Go to last post Go to first unread
Orfeo  
#1 Posted : Thursday, October 26, 2006 6:44:01 AM(UTC)
Orfeo

Rank: Member

Groups: Registered, Registered Users
Joined: 10/1/2006(UTC)
Posts: 10

Hello

I try to make an exploration that checks if SMA20 and SMA 40 are rising since their last crossing to the end of loaded periods in a chart.

I can detect the last crossing using the barssince function.

The next logical thing to do will be to use the sum function to calculate how many times the condition is true. However the periods parameter in the sum function can receive only a constant. how can i make the exploration without using the sum function?

Thanks

Rafael

wabbit  
#2 Posted : Thursday, October 26, 2006 7:42:17 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)
There are a few ways to tackle this one...

One way is to use a latch to count the conditions, then reset the counter back to zero when needed e.g.

Code:

SMA20:=Mov(C,20,S);
SMA40:=Mov(C,40,S);
x:=SMA20>SMA40;

cond:=ROC(SMA20,1,%)>0 AND ROC(SMA40,1,%)>0;

count=cum(cond);
reset:=x AND Alert(x=0,2);

counter:=count-valuewhen(1,reset,count);


Now this will reset to zero on the reset bar, you might want to consider adding 1?

Also, if I say to you the counter has a value of 100, what does this mean? Well if the reset happened 100 bars ago then this means that 100% of the bars have met the 'condition' criteria; if the reset happened 500 bars ago then only 20% of the bars have met the condition - - personally I owuld be working in percentages instead of absolute counter scores.... but this is up to you.

Try this code out... I haven't tested it....


wabbit [:D]
hayseed  
#3 Posted : Thursday, October 26, 2006 10:45:52 AM(UTC)
hayseed

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/7/2005(UTC)
Posts: 1,346

hey orfeo..... could you just use the ref function, such as mov(c,20,s)>ref(mov(c,20,s),-1) .... if both were rising it would plot a 1..... both could be rising from below so you could expand that to include plot a negative 1 in that condition....

its possible your searching for something else, but just in case...... code below.....h

1 for when the 20 is above the 40 and both are rising

-1 for when the 20 is below the 40 yet both are rising.. ..

------------------------

a:=Mov(C,20,S);
aa:=Mov(C,40,S);
0;
If(a>aa AND a>=Ref(a,-1) AND aa>=Ref(aa,-1),1,If(a<aa AND a>=Ref(a,-1) AND aa>=Ref(aa,-1),-1,0));

-----------------------

Orfeo  
#4 Posted : Friday, October 27, 2006 9:17:55 AM(UTC)
Orfeo

Rank: Member

Groups: Registered, Registered Users
Joined: 10/1/2006(UTC)
Posts: 10

Hello wabbit

Thank you very much it did the thing. I thought about it for a few hours and could still do so for a few days and not reach this solution.

Although i have a general impression of what the code does, i'll appreciate it if you could explain in more detail about the two last lines of the code.

Thanks

Rafael

Orfeo  
#5 Posted : Friday, October 27, 2006 9:21:54 AM(UTC)
Orfeo

Rank: Member

Groups: Registered, Registered Users
Joined: 10/1/2006(UTC)
Posts: 10

Hello Hayseed

Thank you for the code but my idea was to check how many times the condition was true since the last crossing of the moving averages.

I got a code from wabbit which does exactly that...

Thanks

Rafael

wabbit  
#6 Posted : Friday, October 27, 2006 7:25:12 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)
Orfeo wrote:
Although i have a general impression of what the code does, i'll appreciate it if you could explain in more detail about the two last lines of the code.


Code:

count=cum(cond);
reset:=x AND Alert(x=0,2);

counter:=count-valuewhen(1,reset,count);


The Cum() function is just counting every occasson when the 'condition' is true; the reset is just a more 'bulletproof' version of the Cross() function which is when we want to reset the counter to zero.

To actually perform the reset, on the bar when the reset is to happen, we subtract the value of the counter from the value of the counter, i.e. ValueOfCounterOnTheDayOfTheReset-ValueOfCounterOnTheDayOfTheReset = 0. On the next bar, assuming the 'condition' is true, we increment the counter by one, but we still subtract the value of the counter when the last reset happens i.e (ValueOfCounterOnTheDayOfTheReset + 1) - ValueOfCounterOnTheDayOfTheReset =1 and so on for each subsequent bar.

Hope this helps.

wabbit [:D]
jssuccess  
#7 Posted : Thursday, April 16, 2009 11:53:05 PM(UTC)
jssuccess

Rank: Member

Groups: Registered, Registered Users
Joined: 4/15/2009(UTC)
Posts: 14

Hi Wabbit,

I have faced a similar problem when try to identify whether ADX is rising since ADX(25)>ref(ADX(25),-1). I define ADX rises when ADX is higher than or equal to its previous value SINCE ADX(25)>ref(ADX(25),-1) on the first bar. The rise is said to be over when ADX falls in two CONSECUTIVE bars in any period during the rise. I have written something as follows:

Cond:=adx(25)>ref(adx(25),-1);

Count:=Barsince(cond);

Sum(adx(25)>=ref(adx(25),-1),count)=count.

However because SUM() only tackles constant, what I wrote above did not work out.

Does anyone can help me on this ?

Tks in advance





Advertisementvar inDapIF=true;document.domain="live.com"; var inDapMgrIf=true;window.setTimeout("document.close();",30000);\n\ndocument.write(\'\');\n\n'));" frameBorder=0 width=160 scrolling=no height=600>Advertisementvar inDapIF=true; var inDapMgrIf=true;document.domain="live.com";function startTimer(){if (event.srcElement.readyState == "complete") {parent.verifyDapResize(1);window.setTimeout("document.close();", 2000);}}'));" frameBorder=0 width=0 scrolling=no height=0 allowTransparency>
wabbit  
#8 Posted : Friday, April 17, 2009 12:03:34 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)
If I have understood the theory, this is one of those times when I would define either "end" of what I am looking for, then use a latch:

Code:

a0:=adx(25);
a1:=ref(a0,-1);

start:=a0>a1;
end:=sum(a0<a1,2)=2;
init:=cum(isdefined(start+end))=1;

rising:=barssince(start+init)<barssince(end+init);
{plot}
rising;



Hope this helps.

wabbit [:D]

jssuccess  
#9 Posted : Friday, April 17, 2009 12:42:54 AM(UTC)
jssuccess

Rank: Member

Groups: Registered, Registered Users
Joined: 4/15/2009(UTC)
Posts: 14

Wabbit,

your help is greatly appreciated.

jssuccess  
#10 Posted : Friday, April 17, 2009 1:55:35 AM(UTC)
jssuccess

Rank: Member

Groups: Registered, Registered Users
Joined: 4/15/2009(UTC)
Posts: 14

Wabbit,

Could u kindly explain to me the logic of the two variables --> init and rising ?

Tks and Cheers

wabbit  
#11 Posted : Friday, April 17, 2009 2:07:35 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)
Both can be explained by reading Roy Larsen's excellent guide to using latches in MS.... see the files section of the forum.


wabbit [:D]

jssuccess  
#12 Posted : Friday, April 17, 2009 2:41:46 AM(UTC)
jssuccess

Rank: Member

Groups: Registered, Registered Users
Joined: 4/15/2009(UTC)
Posts: 14

Wabbit,

TKS AGAIN AND ENJOY YOUR TRADING !!!

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.