"Buy at limit channel low" doesn't buy when expected
Author: macklevit
Creation Date: 5/1/2020 7:51 PM
profile picture

macklevit

#1
Hi there,

I want to create a strategy to buy the lowest value of the 2 prior periods. I tried to use the Entry "Buy at limit channel low". However it didn't work properly. The entry ocurred in next bar when it should happen in the current bar.

I also tried to change the code as the following example, but it didn't work as well.

Old:
CODE:
Please log in to see this code.

New: I changed to
CODE:
Please log in to see this code.


Anyone has a cue?

Thanks and best regards.

André Ferraz
profile picture

Eugene

#2
Hi Andre,

QUOTE:
However it didn't work properly. The entry ocurred in next bar when it should happen in the current bar.

It does work properly. The entry can only happen on the next bar - not on the current bar. Keep in mind that the lowest price of today is unknown until today's close.

QUOTE:
I also tried to change the code as the following example, but it didn't work as well.

Your change has made it badly peek into the future. Please refer to the WealthScript Programming Guide > Programming Trading Strategies > Peeking. Also: The Dangers of Looking Ahead (Peeking) in Trading System Development.
profile picture

macklevit

#3
Hi Eugene,

Thanks for answering, but let's consider the example below:

On 06/01, I know the lowest value of the 2 prior periods was 35,92 on 02/01, right? Knowing that, the program should set a limit order on 06/01 at 35,92. This should be the correct entry according to this strategy, because low of this date was 35,85 which is lower than 35,92.

Sec.Nm Date Open High Low Close
ITUB4 08/01/2020 35,4 35,75 34,59 34,59
ITUB4 07/01/2020 36 36,17 35,17 35,17
ITUB4 06/01/2020 36,47 36,5 35,85 36
ITUB4 03/01/2020 36,42 37,14 36,37 36,55
ITUB4 02/01/2020 36,21 36,93 35,92 36,93

I'm using this example on Wealth Lab, but the entry is happening just on 08/01 as showed in attached document.

Thanks again,

Andre Ferraz
profile picture

Eugene

#4
Andre, it depends on the starting bar of your backtest. Let's assume that a) you don't have any other conditions (as per Rule.png) and b) the data range starts from 1/1/2020. In this case, the buy should have indeed occurred on 01/06 at 35,92 or below.

Problem: for this particular set of rules, Wealth-Lab's Rule Wizard sets the starting bar as #3 so the backtest starts on 01/06 only. It's not wrong - just your case is borderline.

What you can do to get the entry on 01/06 and do it correctly, without peeking:

1. If there's data before 1/1/2020 for ITUB4, simply set an earlier date as the starting date (or it won't work). You can keep on using the Rules Wizard.

2. If there's not, click"Open code in new window", adjust the code, save as a new code-based Strategy:

CODE:
Please log in to see this code.


#2 shuts the door on using Rules.
profile picture

macklevit

#5
Hi Eugene,

Thanks again for your answer, but it still doens't work.

No matter how I change, initial date or the code, the first "buy" occurs only in 08/01.

As I have more data of ITUB4, then before changing the code I've tried to set an earlier date as the starting date (26/12/2019). As it didn't work I've changed the code as you have suggested. In both cases the results were the same.

I uploaded the data file if you want to check the data.

Thanks again and best regards,

André Ferraz


profile picture

macklevit

#6
The data file
profile picture

Eugene

#7
Set "Pricing decimal places" to 2 in Preferences > Advanced Options.

Voila.
profile picture

macklevit

#8
Perfect!

Thanks a lot!
profile picture

Eugene

#9
You're welcome.

Case closed.
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).