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

Notification

Icon
Error

Options
Go to last post Go to first unread
ed  
#1 Posted : Friday, June 30, 2006 2:39:09 AM(UTC)
ed

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/20/2005(UTC)
Posts: 11
Location: Australia

Hi to all the crew, I am trying to flag when a bar crossed over moving average yesterday. I have set a binat indicator to visually inspect the integrity of this code (below). But I find that I get false triggers, namely the bat comes close to the Mov but never crosses yet the signal shows true (see green circle where it fails in attachment). I cannot see the error in my logic - perhaps one of the expert coders can set me straight. Indicator Code: Pds := 14; Offset := 1.7; {percent displacement} HiBand := ExtFml( "ASI.BBandTop", C, Pds, offset); LoBand := ExtFml( "ASI.BBandBot", C, Pds, offset); MidBand:= Mov(C, Pds, E ) ; HH5:= If(Cross(midband, Ref(L, -1)), 1,0 ); {Plot} HH5; Thanks in anticipation Ed UserPostedImage
wabbit  
#2 Posted : Friday, June 30, 2006 6:20:19 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)
ed wrote:
Indicator Code: Pds := 14; Offset := 1.7; {percent displacement} HiBand := ExtFml( "ASI.BBandTop", C, Pds, offset); LoBand := ExtFml( "ASI.BBandBot", C, Pds, offset); MidBand:= Mov(C, Pds, E ) ; HH5:= If(Cross(midband, Ref(L, -1)), 1,0 ); {Plot} HH5;
ed The code is correct, as far as I can see. What you have coded is for the variable to have a value of 1 when the midband (which is the Pds EMA) crosses up through the previous bar's low. In the green circle, this appears to be the case. On the 18th, the midband blue line is higher than the low of the blackbar on the 17th. BTW.. I assume you intend doing more with this code, hence the existence of the Hiband and Loband variables, so I won't comment more on them, but the HH5 variable is more simply written, without changing the values as: HH5:= Cross(midband, Ref(L, -1)); MS will return a Boolean TRUE (1) or FALSE (0) based on the algorithm, so it has the same value. -- As an alternative to Cross, particularly for more complicated scenarios you might like to use a code more like: x:= midband>Ref(L, -1); x AND Alert(x=0,2); which is a lot more flexible and extensible. Hope this helps. If you have any problems, just shout! wabbit :
Jose  
#3 Posted : Friday, June 30, 2006 6:41:35 AM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
There seems to be a disconnect between the chart and explanation. Perhaps it would be best to keep things simple and leave the Bollinger Bands out of it (and definitely no need for the ExtFml). Try this: [code:1:97d531afe9] { Variables } pds:=14; { Irrelevant code } offset:=1.7; {percent displacement} HiBand:=BBandTop(C,pds,E,offset); LoBand:=BBandBot(C,pds,E,offset); { EMA } MidBand:=Mov(C,pds,E); { Price bar crosses over EMA and clears it, yesterday } crossOver:=Ref(Cross(L,midband),-1); { Plot signal in own window } crossOver [/code:1:97d531afe9] jose '-)
ed  
#4 Posted : Friday, June 30, 2006 8:00:35 AM(UTC)
ed

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/20/2005(UTC)
Posts: 11
Location: Australia

Thanks for the reply Wabbit but unfortunately the Black bar of the 17th has a low of 9.01 and the Blue line Mov() on the 17th has a value of 8.968 and there is a clear gap between them, so in fact there should not be a boolean "true" on the bar of the 18th as it clearly failed the test. thers shouls be no "true"over the 18th at all. The signals on either side are correct, having said that the problem appears more than once further along. Has ther ever been mention of a "bug"in the cross function? BTW you are correct it is part of a more complex test - I just stripped out the noise to focus on this anomaly. Ed
wabbit  
#5 Posted : Friday, June 30, 2006 8:13:28 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)
But as Jose has correctly pointed out, there is a disconnect between what you think you wanted and what you have coded! You want : "I am trying to flag when a bar crossed over moving average yesterday" You coded: "What you have coded is for the variable to have a value of 1 when the midband (which is the Pds EMA) crosses up through the previous bar's low." Jose has corrected the code you seek to be : crossOver:=Ref(Cross(L,midband),-1); which says, return a value of TRUE (1) if yesterday, the LOW crossed up through the moving average. Compare this with your code: Cross(midband, Ref(L, -1)) and the difference is noticeable. Your code says, "today, the midband must have crossed above a level that is at the value of yesterday's Low" Hope this is making sense? If it doesn't, then let me know and I will try another angle... wabbit :D
ed  
#6 Posted : Friday, June 30, 2006 8:33:58 AM(UTC)
ed

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/20/2005(UTC)
Posts: 11
Location: Australia

Thanks Jose & Wabbit I cut & pasted Jose's code into the indicator - swapped { Price bar crosses over EMA and clears it, yesterday } crossOver:=Ref(Cross(midband,L),-1); Gave me what I wanted - thanks Wabbit & Jose. It was my logic at fault Ed
wabbit  
#7 Posted : Friday, June 30, 2006 8:47:25 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)
ed.. If you're happy, can you please remember to edit the subject of the first post in the thread and add "[RESOLVED]" thanks.
ed  
#8 Posted : Friday, June 30, 2006 8:47:59 AM(UTC)
ed

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/20/2005(UTC)
Posts: 11
Location: Australia

Thanks Wabbit Some times it's hard to stop and get out of thinking in Tradestation mode. Cheers Ed
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.