Kris![]() Legend ![]() ![]() ![]() ![]() Posts: 347 Joined: 4/20/2006 Location: JNB, ZA ![]() | 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) 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 ![]() |