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

Notification

Icon
Error

Options
Go to last post Go to first unread
Flexi  
#1 Posted : Sunday, November 27, 2011 6:25:15 AM(UTC)
Flexi

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/27/2006(UTC)
Posts: 135

How to exit a specific 100 bars for a trade on tradesim? try the barssince()>60 but the trades didn't exit on the period
jjstein  
#2 Posted : Sunday, November 27, 2011 9:37:06 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)
Try something like:

ExitTrig1:=C<ref(c,-1);
ExitTrig2:=BarsSince(ExitTrig1);

ExitTrigger:=ExitTrig1 or ExitTrig2;

mstt  
#3 Posted : Sunday, November 27, 2011 8:23:16 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 Flexi

The question that has to be asked about a timed exit is - do you want to exit after 60 bars in the trade or do you want to exit 60 bars after the most recent entry signal? The latter option could keep you in a trade for ever if entry signals were given regularly. The former option will enter a trade and then ignore all subsequent entry signals until the current trade has terminated. For this you need to use PREV-based code.(you could try using one of the Simulation functions but good luck with that - you'll need it).

Something along these lines should work. (no responsibility taken for the site corrupting my code)

{Timed Exit Signal}
D:=60; {delay period}
N:=Fml("your entry signal or formula");
X:=0; {place an independant exit signal here if there is one}
R:=If(0>=PREV, N, X OR If(BarsSince(0>=PREV)>=D,-1,1));
Exit:=0>R;
Exit;

Roy
jjstein  
#4 Posted : Monday, November 28, 2011 12:58:30 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)
WHOOPS! That should be:

EntryTrig:=C>ref(C,-1);
ExitTrig1:=C<ref(C,-1);
ExitTrig2:=BarsSince(EntryTrig);

ExitTrigger:=ExitTrig1 or ExitTrig2;

jjstein  
#5 Posted : Monday, November 28, 2011 1:02:00 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)
Roy, I tried the following, but only got a "flatline".

{_Stochastic}
Period:=Input("Period:",1,250,14);
Length:=Input("Length:",1,250,3);
Smooth:=Input("Smooth:",1,250,3);

StochK:=(Sum(C-LLV(L,Period),Length)/Sum(HHV(H,Period)-LLV(L,Period),Length))*100;
FastD:=Mov(StochK,Smooth,S);
SlowD:=Mov(FastD,Smooth,S);

StochK;
FastD;




{_Test }
D:=60; {delay period}
N:=Cross(Fml("_Stochastic"),20);
X:=Cross(80,Fml("_Stochastic"));
R:=If(0>=PREV, N, X OR
If(BarsSince(0>=PREV)>=D,-1,1));
Exit:=0>R;
Exit;


mstt  
#6 Posted : Monday, November 28, 2011 2:40:37 AM(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 Johnathan

That's the problem with me messing with code in an effort to foil the forum foibles. I'll send you the code as a PM now that it's working again. Will do the same for Flexi but won't risk posting code to the thread in case it screws up what I just corrected. My mistake, the code posted exactly as I sent it but I'd modified some good working code before posting it. Duh.

Roy
jjstein  
#7 Posted : Monday, November 28, 2011 1:01:31 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)
Roy -- You whip out latches like a master chef in the pastry kitchen...

Users browsing this topic
Guest (Hidden)
Similar Topics
barssince() has problems when the condition never happened (MetaStock)
by yonyon191719 12/9/2018 10:33:25 PM(UTC)
BarsSince() help (Formula Assistance)
by v.trader 5/9/2010 1:44:05 PM(UTC)
BarsSince() Question (Basic Coding Techniques)
by bostonman28 2/13/2009 8:34:58 AM(UTC)
Problem with barssince() and valuewhen() (Advanced Coding Techniques)
by FoxerFX 2/13/2009 2:46:39 AM(UTC)
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.