Current location | Thread information | |
![]() ![]() ![]() ![]() ![]() ![]() |
Last Activity 7/6/2025 3:47 AM 13 replies, 9584 viewings |
|
|
Printer friendly version |
^ Top | |||
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 ![]() | ||
^ Top | |||
RichardL![]() Veteran ![]() ![]() Posts: 211 Joined: 3/11/2006 ![]() |
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 ![]() ![]() ![]() ![]() Posts: 347 Joined: 4/20/2006 Location: JNB, ZA ![]() |
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 ![]() ![]() Posts: 211 Joined: 3/11/2006 ![]() |
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 ![]() Posts: 111 Joined: 6/16/2006 Location: San Antonio ![]() |
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 ![]() ![]() ![]() ![]() Posts: 347 Joined: 4/20/2006 Location: JNB, ZA ![]() |
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 ![]() ![]() ![]() ![]() Posts: 2077 Joined: 2/27/2006 ![]() |
#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 ![]() ![]() ![]() ![]() Posts: 347 Joined: 4/20/2006 Location: JNB, ZA ![]() |
Thanks Matthew, That is exactly what I was after (!) Cheers, Kris | ||
^ Top | |||
Tony![]() Legend ![]() ![]() ![]() ![]() Posts: 411 Joined: 3/21/2006 ![]() |
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 ![]() ![]() ![]() ![]() Posts: 347 Joined: 4/20/2006 Location: JNB, ZA ![]() |
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 ![]() ![]() ![]() ![]() Posts: 411 Joined: 3/21/2006 ![]() |
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 ![]() ![]() ![]() ![]() Posts: 184 Joined: 3/22/2006 Location: Phoenix, Arizona ![]() |
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 ![]() ![]() Posts: 211 Joined: 3/11/2006 ![]() |
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 ![]() Posts: 111 Joined: 6/16/2006 Location: San Antonio ![]() |
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 |
|
|
Legend | Action | Notification | |||
Administrator
Forum Moderator |
Registered User
Unregistered User |
![]() |
Toggle e-mail notification |