OmniTrader Professional Forum OmniTrader Professional Forum
forums calendars search
today this week
 
register logon control panel Forum Rules
You are currently browsing as a guest.
You should logon to access more features
A Self-Moderated Community - ALL MEMBERS, PLEASE READ!
Vote for Members who contribute the most to your trading, and help us moderate content within the Forums.


  Current location        Thread information  
OmniTrader Professional Forum
OmniLanguage Discussion
Two Bar Trailing Stop
Last Activity 7/6/2025 3:47 AM
13 replies, 9584 viewings

Jump to page : 1
Now viewing page 1 [25 messages per page]
 
back reply
Printer friendly version

^ Top
Kris

Legend
10010010025
Posts: 347

Joined: 4/20/2006
Location: JNB, ZA

User Profile
 
Subject : Two Bar Trailing Stop
Posted : 6/3/2007 12:21 PM
Post #5126

Can someone help me spot the problem with my (dodgy) code for the two-bar trailing stop?

It is supposed to be at the LLV of two previous bars, but it can move only in the direction of the trade. For some reason my code occasionally allows it to retrace against the trade (see attached pic). The code is:

#Stop
#Param "Periods", 2
Dim myLevel As Single

If Signal = LongSignal and myLevel[1] = 0 Then
myLevel = LLV(Periods+1)
Else If Signal = LongSignal and LLV(Periods)>LLV(Periods)[1] Then
myLevel = LLV(Periods)
Else If Signal = ShortSignal and myLevel[1] = 0 Then
myLevel = HHV(Periods+1)
Else If Signal = ShortSignal and HHV(Periods)(Periods)[1] Then
myLevel = HHV(Periods)
Else
myLevel = myLevel[1]
End If

ExitLevel = myLevel

If Signal = LongSignal and C < myLevel Then
Signal = ExitSignal
Else If Signal = ShortSignal and C > myLevel Then
Signal = ExitSignal
End If

Thanks, Kris

Attached file : Stop.JPG (76KB - 652 downloads)

^ Top
RichardL

Veteran
100100
Posts: 211

Joined: 3/11/2006

User Profile
 
Subject : RE: Two Bar Trailing Stop
Posted : 6/3/2007 12:46 PM
Post #5127 - In reply to #5126

Hi Kris


Is the line

"Else If Signal = ShortSignal and HHV(Periods)(Periods)[1] Then"

correct? - probably a typo for the Forum post I guess. Should be

"Else If Signal = ShortSignal and HHV(Periods) < HHV(Periods)[1] Then"


Richard

[Edited by RichardL on 6/3/2007 12:48 PM]

^ Top
Kris

Legend
10010010025
Posts: 347

Joined: 4/20/2006
Location: JNB, ZA

User Profile
 
Subject : RE: Two Bar Trailing Stop
Posted : 6/3/2007 3:55 PM
Post #5130 - In reply to #5126

Yes Richard, you are right.

The code with your correction is giving me questionable stop levels.

I copy/pasted the entire Stop code, but for some reason, it got messed-up(?)

Cheers, Kris

^ Top
RichardL

Veteran
100100
Posts: 211

Joined: 3/11/2006

User Profile
 
Subject : RE: Two Bar Trailing Stop
Posted : 6/3/2007 4:19 PM
Post #5131 - In reply to #5130

Kris

silly question, but how do you get mylevel to persist between invocations without returning it.

Unless thats ExitLevel. But is the value maintained?

Richard

[Edited by RichardL on 6/3/2007 4:21 PM]

^ Top
rob-McKinneyTexas

Veteran
100
Posts: 111

Joined: 6/16/2006
Location: San Antonio

User Profile
 
Subject : RE: Two Bar Trailing Stop
Posted : 6/3/2007 8:54 PM
Post #5133 - In reply to #5126

Hi guys,

Kris... I see you check to see whether you need the last value of mylevel, or whether it's being replaced. So you save mylevel = mylevel[1] until the other if/then/else checks are done. By the way, guess you know you're not using exitlevel for anything.

I always clear out the stop level once the exit is issued in stops like this.... not sure it makes sense but that stop level may persist into the next trade. So the second time a stock trades, mylevel[1] will still be the last stop level instead of zero. I would change the end to look like this:

If Signal = LongSignal and C < myLevel Then
mylevel = 0
Signal = ExitSignal
ElseIf Signal = ShortSignal and C > myLevel Then
mylevel = 0
Signal = ExitSignal
end if

I didn't check it but it might help. Good luck!

Rob





[Edited by rob-McKinneyTexas on 6/3/2007 8:56 PM]

^ Top
Kris

Legend
10010010025
Posts: 347

Joined: 4/20/2006
Location: JNB, ZA

User Profile
 
Subject : RE: Two Bar Trailing Stop
Posted : 6/4/2007 2:28 AM
Post #5136 - In reply to #5126

Thanks Rob,

I have added "myLevel = 0", but I still have (incorrectly) retracing stops.

What you meand by "By the way, guess you know you're not using exitlevel for anything."?

Cheers, Kris

^ Top
Matthew Greenslet

Idol
2000252525
Posts: 2077

Joined: 2/27/2006

User Profile
 
Subject : RE: Two Bar Trailing Stop
Posted : 6/4/2007 9:53 AM
Post #5139 - In reply to #5126

#Stop
#Param "Periods", 2
Dim myLevel As Single

myLevel = myLevel[1]

If Signal = LongSignal Then
If myLevel = 0 Or LLV(Periods) > myLevel Then
myLevel = LLV(Periods)
End If
ElseIf Signal = ShortSignal Then
If myLevel = 0 Or HHV(Periods) < myLevel Then
myLevel = HHV(Periods)
End If
End If

ExitLevel = myLevel

If Signal = LongSignal and C < myLevel Then
Signal = ExitSignal
Else If Signal = ShortSignal and C > myLevel Then
Signal = ExitSignal
End If


[Edited by Matthew Greenslet on 6/4/2007 10:08 AM]

^ Top
Kris

Legend
10010010025
Posts: 347

Joined: 4/20/2006
Location: JNB, ZA

User Profile
 
Subject : RE: Two Bar Trailing Stop
Posted : 6/4/2007 11:41 AM
Post #5147 - In reply to #5126

Thanks Matthew,

That is exactly what I was after (!)

Cheers, Kris

^ Top
Tony

Legend
100100100100
Posts: 411

Joined: 3/21/2006

User Profile
 
Subject : RE: Two Bar Trailing Stop
Posted : 6/26/2007 10:02 PM
Post #5481 - In reply to #5126

HI Guys,

just looking at stop. It looks like this is one of those through close type of stops. So a user needs to exit at the begining of next bar. For eod equivalent of moo order. Is this correct?

Thanks for the input.

Tony
^ Top
Kris

Legend
10010010025
Posts: 347

Joined: 4/20/2006
Location: JNB, ZA

User Profile
 
Subject : RE: Two Bar Trailing Stop
Posted : 6/27/2007 2:48 PM
Post #5503 - In reply to #5126

Yes, it is a through-stop, i.e. one doesn't get stopped prematurely by the high/low (candle) wigs. The market has to close below/above the stop level for it to actually close the position.

To see an exaple check the picture attached to the HOLP system post: http://www.omnitrader.com/omnitrader/proforum/thread-view.asp?threadid=1044&posts=2

Cheers, Kris

^ Top
Tony

Legend
100100100100
Posts: 411

Joined: 3/21/2006

User Profile
 
Subject : RE: Two Bar Trailing Stop
Posted : 6/28/2007 6:28 AM
Post #5522 - In reply to #5503

HI,


thanks Chris. I am looking at using this stop together with a filter. The idea is to put just a little bit more odds in your favor. For what its worth here is an example, for enter on close with a 50% off at two atr, then, I do not want the stop to be to deep. Perhaps 1.5 level below the entry.

That way my loss is smaller than win. Something like:
L[2]>C-(atr*1.5)
and repeat for one day ago.

Anyway, just an idea and thought others may find useful.

Tony


^ Top
Bill Graves

Veteran
100252525
Posts: 184

Joined: 3/22/2006
Location: Phoenix, Arizona

User Profile
 
Subject : RE: Two Bar Trailing Stop
Posted : 6/28/2007 1:44 PM
Post #5530 - In reply to #5522

Tony,

Keep in mind that Kris designed this stop for short term Forex trading.

So, I think altering his risk/reward ratio depends on the system/markets one is trading. With a sufficiently high system expectancy, it is possible to trade very profitably with even a negagive risk/reward ratio.

Cheers,

^ Top
RichardL

Veteran
100100
Posts: 211

Joined: 3/11/2006

User Profile
 
Subject : RE: Two Bar Trailing Stop
Posted : 6/28/2007 2:04 PM
Post #5531 - In reply to #5530

Its also giving very good results on eminis in a paper IB brokerage account on 1 min ABU7

all the best

Richard
^ Top
rob-McKinneyTexas

Veteran
100
Posts: 111

Joined: 6/16/2006
Location: San Antonio

User Profile
 
Subject : RE: Two Bar Trailing Stop
Posted : 7/15/2007 6:59 PM
Post #5755 - In reply to #5126

Kris,

oops... sorry about the 6 week delay in answering!

That comment I made aout exitlevel was just me not realizing exitlevel was a keyword. I should've noticed it wasn't listed as a variable.

Anyway, looks like Matthew solved your problem. Hope you're well.

Rob
Jump to page : 1
Now viewing page 1 [25 messages per page]
back reply

Legend    Action      Notification  
Administrator
Forum Moderator
Registered User
Unregistered User
E-Mail this thread to a friend
Toggle e-mail notification


Nirvana Systems
For any problems or issues please contact our Webmaster at webmaster@nirvsys.com.