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.


This message cannot be deleted. It is the first message of the thread.
Administrators or moderators may choose to delete the entire thread


 
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 - 667 downloads)

Deleting message 5126 : Two Bar Trailing Stop


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