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

Notification

Icon
Error

Options
Go to last post Go to first unread
v.trader  
#1 Posted : Sunday, May 9, 2010 1:44:05 PM(UTC)
v.trader

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/26/2009(UTC)
Posts: 76
Location: Toronto, Canada

Hi everyone. I'm experiencing some unusual activity by using the barssince function. The code is the following: a:=FmlVar("(C) StatsB&RSI Test","BUYRESULT"); b:= FmlVar("(C) StatsB&RSI Test","SHORTRESULT"); x:= BarsSince(a)=1 ; y:= BarsSince(b)=1 ; BuyPrice:= ValueWhen(1,x,O); ShortPrice:= ValueWhen(1,y,O); You can see that with x-variale (and y) I'm trying to refer to the next bar open price after a binary signal is given by a-variable and b-variable. In most cases barsSince does its job and does refer to the next bar's open price. HOWEVER, there are a few instances(10 out of 200) where it would not refer to the next bar but 2 bars after that. For instance, I receive the signal on Monday and I'm looking to get the open price for Tuesday. As I said, this is usually what I get but in a few cases I get the Open for Wednesday. Any ideas of why this bug might occur. Thanks in advance. VT
mstt  
#2 Posted : Monday, May 10, 2010 5:53:21 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)

Hi VT

Without your formulas it’s impossible to exactly replicate the problem you have without going to some trouble. Therefore what I suggest you do is copy the exploration code and create a new indicator, then use the indicator to successively plot and check all variable results on one or two of the securities returning incorrect values. The only reason for an exploration to return different values from an indicator with the same code would be if the exploration was not loading sufficient bars of data. Exponential moving averages are intolerant of too little data, but so are ValueWhen(), BarsSince(), HighestSince() and a number of other functions not requiring a Periods parameter. Any function using an Nth parameter needs the user to force-load sufficient bars. Using the Minimum Records option is asking for trouble.

It’s a good idea when using a ValueWhen() function, especially in an exploration, to create an “initialised” signal to be ORed with the Expression parameter. Ideally an “I” bar spikes TRUE for one bar once all user variables are valid. Without an “I” bar being included in the Expression parameter of ValueWhen() there’s a definite possibility that the primary condition will not eventuate and the function will instead return a rather useless N/A. Of course the “I” bar alone can generate an inappropriate result too, but there are ways to separate those from legitimate results.

Here are the steps that you need to cycle through with the indicator version of the exploration. If none of these show up anything odd then double check the bars you’re loading for the exploration. When the same number of bars is used for both exploration and indicator you WILL get the same result. The reason for testing by using an indicator is that you get to see what’s happening on EVERY bar, not just the last bar. A wrong result on the last bar (as reported by an exploration) is usually caused by something unexpected happening prior to the last bar. An indicator is much easier to troubleshoot if this is the situation you have.

Hope this helps.

Roy

a:=FmlVar("(C) StatsB&RSI Test","BUYRESULT");
b:= FmlVar("(C) StatsB&RSI Test","SHORTRESULT");
x:= BarsSince(a)=1 ; x;
y:= BarsSince(b)=1 ;
BuyPrice:= ValueWhen(1,x,O);
ShortPrice:= ValueWhen(1,y,O);

a:=FmlVar("(C) StatsB&RSI Test","BUYRESULT");
b:= FmlVar("(C) StatsB&RSI Test","SHORTRESULT");
x:= BarsSince(a)=1 ;
y:= BarsSince(b)=1 ; y;
BuyPrice:= ValueWhen(1,x,O);
ShortPrice:= ValueWhen(1,y,O);

a:=FmlVar("(C) StatsB&RSI Test","BUYRESULT");
b:= FmlVar("(C) StatsB&RSI Test","SHORTRESULT");
x:= BarsSince(a)=1 ;
y:= BarsSince(b)=1 ;
BuyPrice:= ValueWhen(1,x,O); BuyPrice;
ShortPrice:= ValueWhen(1,y,O);

a:=FmlVar("(C) StatsB&RSI Test","BUYRESULT");
b:= FmlVar("(C) StatsB&RSI Test","SHORTRESULT");
x:= BarsSince(a)=1 ;
y:= BarsSince(b)=1 ;
BuyPrice:= ValueWhen(1,x,O);
ShortPrice:= ValueWhen(1,y,O); ShortPrice;

v.trader  
#3 Posted : Monday, May 10, 2010 9:25:54 PM(UTC)
v.trader

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/26/2009(UTC)
Posts: 76
Location: Toronto, Canada

Roy, Thank you so much for the thorough insights,again. Out of curiosity I will test the code that you gave me but fortunately I have found an alternative solution. Apparently, using x:=Barssince(a)=1 and valuewhen(1,x,O) I was trying to figure out the price at which I enter the trade, that is the opening price of the next bar after the binary signal. However, I did remember that you mentioned in a different post that using Ref(signal,-1) would return the opening(e.i. entry) price so this is what I used and it worked perfectly. As for the "init" variable I will definitely incorporate that into my code. Thanks again for the help. VT
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.