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

Notification

Icon
Error

Options
Go to last post Go to first unread
jjstein  
#1 Posted : Friday, April 6, 2007 12:31:24 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

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

The following will tell me when a signal is in effect:

Code:

Buy:=Cross(RSI(14),30);
Sell:=Cross(70,RSI(14));
init:=Cum(IsDefined(Buy+Sell))=1;
flag:=ValueWhen(1,Buy-Sell<>0,Buy)*2-1;
flag;
But, when I try to filter for redundant signals, the following is missing the 1st signal:

Code:

Buy:=Cross(RSI(14),30);
Sell:=Cross(70,RSI(14));
init:=Cum(IsDefined(Buy+Sell))=1;
flag:=ValueWhen(1,Buy-Sell<>0,Buy)*2-1;
If(flag<>Ref(flag,-1),flag,0);
Can anyone suggest a fix? Thanks!

jjstein  
#2 Posted : Friday, April 6, 2007 1:11:17 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

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

May have answered my own question. Forgot the INIT for "signal":

Code:

Buy:=Cross(RSI(14),30);
Sell:=Cross(70,RSI(14));
init:=Cum(IsDefined(Buy+Sell))=1;
flag:=ValueWhen(1,Buy-Sell<>0 OR init,Buy)*2-1;
If(flag<>Ref(flag,-1),flag,0);
Seems to display correctly.

Jose  
#3 Posted : Friday, April 6, 2007 10:33:30 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)
jjstein wrote:
May have answered my own question.
...Or perhaps not. Your code bears an uncanny resemblance to the trade signals code found at MetaStockTools.com. ;) "Trade signals v4.0 - removes multiple redundant entry & exit system signals and plots clean buy/sell trade signals." jose '-)
jjstein  
#4 Posted : Friday, April 6, 2007 11:08:08 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

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

Jose -- Probably because you helped with the original -- but slightly different -- problem, last year... http://forum.equis.com/forums/thread/20340.aspx

Right now, it will miss the 1st signal if it is a SELL. I'd like it to work, no matter whether a SELL or BUY comes first.

Code:

Buy:=Cross(RSI(14),30);
Sell:=Cross(70,RSI(14));
init:=Cum(IsDefined(Buy+Sell))=1;
{init:=Cum(buy+sell>-1)=1;}
flag:=ValueWhen(1,Buy-Sell<>0 OR init,Buy)*2-1;
flag*(flag<>Ref(flag,-1));
Not sure I correctly know how a variable behaves when it is not defined...any help on understanding would be appreciated.

wabbit  
#5 Posted : Friday, April 6, 2007 8:43:03 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)
JJ,

try this?

Code:

Buy:=Cross(RSI(14),30);
Sell:=Cross(70,RSI(14));
init:=Cum(IsDefined(Buy+Sell))=1;
short:=BarsSince(init OR sell)<BarsSince(init OR buy);
long:=BarsSince(init OR buy)<BarsSince(init OR sell);

{plot}
long-short;



wabbit [:D]


Jose  
#6 Posted : Friday, April 6, 2007 11:45:18 PM(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)
Johnathan, any undefined element within your formula will also make other elements undefined thereafter. If either of your buy or sell plots are undefined (and they always are to some extent), you will need to convert the undefined signal to a defined one in order for the other signal to plot. You can either use the LastValue(signal+PREV-PREV) trick, or use any MS dll that removes the null bars from your plot. I use a purpose-built custom dll for this purpose - Xtend.dll. jose '-)
jjstein  
#7 Posted : Saturday, April 7, 2007 1:50:44 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

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

Wouldn't the "INIT OR [censored]" take care of that?

Code:

Buy:=Cross(RSI(14),30);
Sell:=Cross(70,RSI(14));
init:=Cum(IsDefined(Buy+Sell))=1;
short:=BarsSince(init OR sell)<BarsSince(init OR buy);
long:=BarsSince(init OR buy)<BarsSince(init OR sell);
flag:=long-short;
flag*(flag<>Ref(flag,-1));
As "-1" and "+1" are used for signals, the undefined state would be "0", if I understand things correctly. Is that what you mean by "null" bars?

Since you mentioned it -- just what does your "Xtend.dll" do?

Jose  
#8 Posted : Saturday, April 7, 2007 1:59:59 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)
J, you are confusing "Null" (N/A) with "zero" - they are very different from each other. Plot your buy & sell conditions separately, and you'll see the missing plot on the first few bars of data - this is what "Null" looks like. Xtend.dll extends the last defined value into any Null zone. jose '-)
jjstein  
#9 Posted : Saturday, April 7, 2007 11:58:15 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

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

Jose,

Nothing seems to plot on a chart until there is enough data to calculate a formula.

So, if I understand correctly, then:

The "Null Zone" will ALWAYS precede, and NEVER follow the first valid calculation.

On any date with valid data, a calculation returning N/A will evaluate as ZERO in a formula.

It could be said that "Xtend.dll extends the first defined value backwards, from "ref(IsDefined(ConditionX)),-1)" BACKWARD to "Cum(1)=1".

So, I plotted "ValueWhen(1,Cum(1)=1,Cross(RSI(14),30));", thinking that I'd see a zero line from the first bar of the data, but got a zero line that started at bar 14.

However, "IsDefined(ValueWhen(1,Cum(1)=1,Cross(RSI(14),30)))" DID start at bar 1.

This begs the question: WHY do you need/use "Xtend.dll"? An "init" with "IsDefined" should give a value starting with bar 1.

Jose  
#10 Posted : Saturday, April 7, 2007 11:11:10 PM(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)
jjstein wrote:
The "Null Zone" will ALWAYS precede, and NEVER follow the first valid calculation.
No - it can also be found at the end of a chart, such as when forward-referencing is used.
jjstein wrote:
On any date with valid data, a calculation returning N/A will evaluate as ZERO in a formula.
No - Null is not Zero.
jjstein wrote:
It could be said that "Xtend.dll extends the first defined value backwards, from "ref(IsDefined(ConditionX)),-1)" BACKWARD to "Cum(1)=1".
Correct, as well as filling any forward Null bars.
jjstein wrote:
This begs the question:  WHY do you need/use "Xtend.dll"?  An "init" with "IsDefined" should give a value starting with bar 1.
Plot your buy/sell signals, and see for yourself why you cannot remove Null bars using the IsDefined() function. J, we could go on with this subject forever. To find a solution, you'll first need to understand the problem. Use your eyes to find both, not your keyboard. ;) jose '-)
jjstein  
#11 Posted : Monday, April 9, 2007 6:59:49 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

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

>>Plot your buy/sell signals, and see for yourself why you cannot remove Null bars using the >>IsDefined() function.

The following does not plot until bar 14:

Code:

RSI(14)
While THIS will plot a zero from bar 1 to 14, then a a "1" from bar 15 onwards:

Code:

IsDefined(ValueWhen(1,Cum(1)=1,Cross(RSI(14),30)))
Uh, am I misunderstanding something? I'd attach a JPG of the screen/indicator, but don't see how to put it in a posting...

Jose  
#12 Posted : Tuesday, April 10, 2007 12:04:50 PM(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)
The IsDefined() function can only plot zero or one. It cannot help with plotting any other values/signals within the first 13 Null bars in your example. If you have a buy or sell signal in those first 13 Null bars, you'll need to use either of the tricks outlined earlier, or the purpose-built Xtend.dll - available for US$60 through MetaStockTools.com. jose '-)
jjstein  
#13 Posted : Tuesday, April 10, 2007 12:40:59 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

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

Don't see how Xtend.dll would help in my example -- if the RSI(14) is length 14, then how could you get a signal before bar 14?

Perhaps you could give an example of Xtend doing something that an IsDefined/Init variable cannot help with?

--Johnathan

P.S. I'm glad to know it's available, but FWIW a "xtend.dll" search on your site doesn't turn up anything...

Jose  
#14 Posted : Tuesday, April 10, 2007 1:46:42 PM(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)
J, what about your original problem, where no Buy signals can plot until the Sell signals are defined (and viceversa) - can you see the Null problem yet? Null bars turn everything they touch into nothingness. No Init signal will help if the Null zone touches it, that's how nasty this mathematical black hole is. For example, an exit based on an RSI(14) will prevent any entry signals based on an RSI(5) (in the 5~13 bar zone) from plotting as a single entry/exit plot. More on the Null issue (and Xtend.dll) here: Null bar removal - removes leading/trailing null (N/A) bars from any plot. jose '-)
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.