Peeking?
Author: wmac2009
Creation Date: 4/11/2009 9:24 AM
profile picture

wmac2009

#1
I noticed that several of the example strategies that come with WL use the return value of the order commands in conditional statements. For example, the Bandwagon Trade script includes the following:

CODE:
Please log in to see this code.

Since a command that will execute now (SellAtLimt) depends on the outcome of something that will take place in the future (SellAtStop), isn't this peeking?
profile picture

Eugene

#2
Both these commands will execute on the same bar -- bar+1 -- so SellAtLimit will not trigger now. Instead, it will only execute if SellAtStop won't.
profile picture

wmac2009

#3
But doesn't the if statement execute on the current bar? Likewise, if the condition being tested is true, then the conditional code would be executed during the current bar. Right? It seems like you'll never get to the SellAtLimit line unless you know the result of something that won't happen until the next bar.

I know that placing both the SellAtStop and SellAtLimit without using one as the condition for the other would be OK, but my question is related to using the result from one of the statements as a condition for the other.

One last way to ask the question - if the code is not a form of peeking, then is it true that the two sell commands AND the if statement surrounding them are all executed on the next bar? I would be surprised if that were true, but, what the heck, I've been surprised before.
profile picture

Eugene

#4
Yes, the if statement executes on the current bar.

What this code pattern does and what is it used for is that it sets the right order of precedence for more than one exit at the same bar: the so-called "pessimistic assumption", or "less favorable exits are executed first".

More than one exit at the same Bar

So, with this code you won't get to the SellAtLimit unless your stop loss is not hit. Both orders are to be executed on the same bar+1, but only one is selected when there's more than one to pick from.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).