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

Notification

Icon
Error

Options
Go to last post Go to first unread
nmouts  
#1 Posted : Sunday, October 23, 2011 5:35:14 PM(UTC)
nmouts

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 9/27/2010(UTC)
Posts: 7

Is there a way to perform two or more actions when an IF statement is true? For example: If(Condition A,{THEN} action1 {AND} action2,{ELSE} .....) Thx
jjstein  
#2 Posted : Monday, October 24, 2011 11:04: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)
I don't think so.

henry1224  
#3 Posted : Monday, October 24, 2011 4:49:08 PM(UTC)
henry1224

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/29/2004(UTC)
Posts: 1,394
Location: Glastonbury, CT

Was thanked: 2 time(s) in 2 post(s)
You could use 2 if statements separately
If(Condition A,{THEN} action1 ,{ELSE} .....)
If(Condition A,{THEN} action2,{ELSE} .....)

it would help if you posted your code or trading ideas
nmouts  
#4 Posted : Tuesday, October 25, 2011 5:17:38 AM(UTC)
nmouts

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 9/27/2010(UTC)
Posts: 7

Thank you very much for your replies. Dear Henry, I am trying to code the following: I want to get an entry long signal when there is a gapup with higher volume than the previous day (gapup() * (V>ref(v, -1)). Then I want to exit the long position as soon as there will be 3 down days (c>ref(c, -1)) with higher volume than the previous day (V>ref(v, -1)) from the entry day. The problem that I have is, to keep the status of the position in order to count the down days only when I am in a long position and to check for a gapup only when I am out of the market. I would appreciate of your help on this?
henry1224  
#5 Posted : Tuesday, October 25, 2011 6:21:53 AM(UTC)
henry1224

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/29/2004(UTC)
Posts: 1,394
Location: Glastonbury, CT

Was thanked: 2 time(s) in 2 post(s)
You have to define your entry and exit signals and then develop a latch.

3DD:=Sum(C < Ref(C,-1),3)>2; {3 down days}
EDVol:=ValueWhen(1,gapup()*(V>Ref(V,-1))=1,V); {entry day Volume}
LE:=Gapup()*(V>Ref(V,-1))=1; {long entry}
LX:=3DD*(V>EDVol)=1; {Long exit}
Sys:=If(BarsSince(LE)>BarsSince(LX),1,If(BarsSince(LE) < BarsSince(LX),-1,0));
Sys;


nmouts  
#6 Posted : Tuesday, October 25, 2011 8:09:33 AM(UTC)
nmouts

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 9/27/2010(UTC)
Posts: 7

Henry, sorry for not been clear and precise. after the long entry signal (LE) I am looking for three down days: a day in order to be considered as downday has to close lower (c>ref(c, -1)) AND has to have greater volume than the previous day (V>ref(v, -1)). The 3 downdays do not have to be one after the other. We might have three down days in a period of 10 total days or more. As soon as we sum three such days then we have the exit signal and we start looking for the next entry one. I hope now it is more clear to you.
nmouts  
#7 Posted : Tuesday, November 1, 2011 9:49:45 AM(UTC)
nmouts

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 9/27/2010(UTC)
Posts: 7

Hi Henry, I am trying to implement the above by using PREV based latches but with no success till now. I would appreciate for your guidelines? Regards
jjstein  
#8 Posted : Friday, November 4, 2011 11:36:52 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)
Is this what you're looking for:
UserPostedImage


DownDay:=C<Ref(C,-1) AND V>Ref(V,-1);
Sell:=Sum(DownDay,10)=3;

Buy:=GapUp()*(V>Ref(V,-1))=1;

init:=Cum(IsDefined(Buy+Sell))=1;
flag:=ValueWhen(1,Buy-Sell<>0 OR init,Buy)*2-1;
If(flag<>Ref(flag,-1),flag,0);


nmouts  
#9 Posted : Tuesday, November 8, 2011 1:57:55 PM(UTC)
nmouts

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 9/27/2010(UTC)
Posts: 7

Dear jjstein, thank you very much for your reply and the smart code that you proposed. Unfortunately this is not what I am looking for due to the following two reasons: The sell signal should be generated when we will sum 3 DownDays AFTER the entry signal. Therefore: A) we do not know in advance the duration required in order to sum the 3 DownDays. By using the function Sell:=Sum(DownDay,10)=3; we limit the duration to the 10 previous days. As I also said in the previous post the duration might be 10 days or more. B) we want to start the counting of the DownDays AFTER the entry signal. Thus, we have to reset the counter of the DownDays at the time of an entry signal and then start counting from 0 again. Otherwise, we might face the following problem: Suppose that at a time we have 2 DownDays and then we get an entry signal. The next day we have one more DownDay. The proposed code will give us an exit signal since it will sum 3 DownDays in the previous 10 days. But we do not want to get an exit signal. We want an exit signal as soon as we will sum 3 DownDays after the entry signal I hope that the differences are clear.
jjstein  
#10 Posted : Wednesday, November 9, 2011 10:32:23 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)
OK, this should do it. Had to use two indicators, one to count and the other for binary signal. Maybe someone else can do in a more elegant, single indicator...
UserPostedImage
{_Test Counter }
DownDay:=C<Ref(C,-1) AND V>Ref(V,-1);
Buy:=GapUp()*(V>Ref(V,-1))=1;
Set:=DownDay;
Reset:=Buy;
Signal:=If(Set,PREV+1,If(Reset,0,PREV));
Signal;


{_Test }
{ Get signals from latch indicator }
Buy:=FmlVar("_Test Counter","Buy");
Sell:=Fml("_Test Counter")=3;

{ GENERIC - Filter repeat signal, 1=Buy -1=Sell }
init:=Cum(IsDefined(Buy+Sell))=1;
Season:=ValueWhen(1,Buy-Sell<>0 OR init,Buy)*2-1;
Signal:=If(Season<>Ref(Season,-1),Season,0);

{ Display }
Signal;


nmouts  
#11 Posted : Thursday, November 10, 2011 10:49:28 AM(UTC)
nmouts

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 9/27/2010(UTC)
Posts: 7

Hi Jonathan, Once again I would like to thank you for your effort. Unfortunately the approach still has a problem: The problem is with the reset function. Think of the case that we are IN the market and we are counting the DownDays to see for an exit signal. Suddenly we have another Buy signal (Gapup day with high volume) that mistakenly resets the DownDays counter. In simple words: - As long as we are IN the market we are interested for counting only DownDays. - As long as we are OUT of the market we are interested only for the Gapup days, as we have defined them. We do not want the decision to be affected by other events. Can we achieve something like this?
jjstein  
#12 Posted : Thursday, November 10, 2011 11:34:42 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)
Change "_Test Counter" to this:

DownDay:=C<Ref(C,-1) AND V>Ref(V,-1);
Buy:=GapUp()*(V>Ref(V,-1))=1;
Set:=DownDay;
Reset:=Buy;
Signal:=If(Set,PREV+1,
If(Reset and PREV>=3,0,
PREV));
Signal;

UserPostedImage


nmouts  
#13 Posted : Tuesday, November 15, 2011 2:55:49 AM(UTC)
nmouts

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 9/27/2010(UTC)
Posts: 7

Hi Jonathan, It seems that we are in a better status. The next days I will finish the coding in order to check the correct behavior. I will let you know of the results soon. Thanks again for your help.
jjstein  
#14 Posted : Tuesday, November 15, 2011 1:01: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)
You're welcome. Was curious if we finally got to what you wanted...

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.