|
|
Logic problem -- missing initial signal after filter
Last post 04-10-2007, 13:46 by Jose. 13 replies.
-
04-06-2007, 0:31 |
-
jjstein
-
-
-
Joined on 05-13-2005
-
-
Posts 144
-
-
|
Logic problem -- missing initial signal after filter
The following will tell me when a signal is in effect:
|
|
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:
|
|
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!
--Johnathan
|
|
-
04-06-2007, 1:11 |
-
jjstein
-
-
-
Joined on 05-13-2005
-
-
Posts 144
-
-
|
Re: Logic problem -- missing initial signal after filter
May have answered my own question. Forgot the INIT for "signal":
|
|
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.
--Johnathan
|
|
-
04-06-2007, 10:33 |
-
Jose
-
-

-
Joined on 01-20-2005
-
Koh Pha-Ngan, Earth
-
Posts 1,087
-
-
|
Re: Logic problem -- missing initial signal after filter
jjstein: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 '-)
MetaStockTools.com
|
|
-
04-06-2007, 11:08 |
-
jjstein
-
-
-
Joined on 05-13-2005
-
-
Posts 144
-
-
|
Re: Logic problem -- missing initial signal after filter
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.
|
|
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.
--Johnathan
|
|
-
04-06-2007, 20:43 |
-
wabbit
-
-

-
Joined on 10-28-2004
-
Perth, Western Australia
-
Posts 2,042
-
-
|
Re: Logic problem -- missing initial signal after filter
JJ, try this? |
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
"The question of whether a computer can think is no more interesting than the question of whether a submarine can swim." Edsgar W. Dijkstra MS: 6.52 EOD, 7.x EOD, 8.0 PRO, 9.2 PRO w/QC, 10 PRO w/QC C, 11 PRO w/QC & MDK For custom MetaStock programming : http://www.wabbit.com.au My SkyPE status :  My SkyPE account : wabbit.com.au
|
|
-
04-06-2007, 23:45 |
-
Jose
-
-

-
Joined on 01-20-2005
-
Koh Pha-Ngan, Earth
-
Posts 1,087
-
-
|
Re: Logic problem -- missing initial signal after filter
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 '-)
MetaStockTools.com
|
|
-
04-07-2007, 1:50 |
-
jjstein
-
-
-
Joined on 05-13-2005
-
-
Posts 144
-
-
|
Re: Logic problem -- missing initial signal after filter
Wouldn't the "INIT OR xxx" take care of that?
|
|
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?
--Johnathan
|
|
-
04-07-2007, 1:59 |
-
Jose
-
-

-
Joined on 01-20-2005
-
Koh Pha-Ngan, Earth
-
Posts 1,087
-
-
|
Re: Logic problem -- missing initial signal after filter
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 '-)
MetaStockTools.com
|
|
-
04-07-2007, 11:58 |
-
jjstein
-
-
-
Joined on 05-13-2005
-
-
Posts 144
-
-
|
Re: Logic problem -- missing initial signal after filter
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.
--Johnathan
|
|
-
04-07-2007, 23:11 |
-
Jose
-
-

-
Joined on 01-20-2005
-
Koh Pha-Ngan, Earth
-
Posts 1,087
-
-
|
Re: Logic problem -- missing initial signal after filter
jjstein: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:On any date with valid data, a calculation returning N/A will evaluate as ZERO in a formula.
No - Null is not Zero.
jjstein: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: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 '-)
MetaStockTools.com
|
|
-
04-09-2007, 18:59 |
-
jjstein
-
-
-
Joined on 05-13-2005
-
-
Posts 144
-
-
|
Re: Logic problem -- missing initial signal after filter
>>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:
While THIS will plot a zero from bar 1 to 14, then a a "1" from bar 15 onwards:
|
|
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...
--Johnathan
|
|
-
04-10-2007, 12:04 |
-
Jose
-
-

-
Joined on 01-20-2005
-
Koh Pha-Ngan, Earth
-
Posts 1,087
-
-
|
Re: Logic problem -- missing initial signal after filter
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 '-)
MetaStockTools.com
|
|
-
04-10-2007, 12:40 |
-
jjstein
-
-
-
Joined on 05-13-2005
-
-
Posts 144
-
-
|
Re: Logic problem -- missing initial signal after filter
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...
--Johnathan
|
|
-
04-10-2007, 13:46 |
-
Jose
-
-

-
Joined on 01-20-2005
-
Koh Pha-Ngan, Earth
-
Posts 1,087
-
-
|
Re: Logic problem -- missing initial signal after filter
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 '-)
MetaStockTools.com
|
|
|
|