How is the value for GetTradingLoopStartBar determined?
Author: ciconia1
Creation Date: 12/16/2016 8:48 PM
profile picture

ciconia1

#1
I couldn't seem to locate a reference manual for the script commands, so I have a basic question:

How is the value determined for setting the 'GetTradingLoopStartBar' command? Should it be the number of bars of data loaded for the selected timeframe?
profile picture

Eugene

#2
Welcome to the forum.

QUOTE:
I couldn't seem to locate a reference manual for the script command


Strike F11 key and in the QuickRef window start typing in the first few characters of GetTradingLoopStartBar. There you'll find it explained.
profile picture

ciconia1

#3
F11 was just the resource I needed, but couldn't find. Thanks for pointing me in the right direction.
profile picture

Eugene

#4
Glad to help.
profile picture

innertrader

#5
One issue I have with B&H comparisons is that one of my daily strategies has a long "startup" period before it has enough historical data to generate signals. This is instantiated in code by the GetTradingLoopStartBar function at the start of the trading code. B&H buys immediately based on earliest date of the data range, while the strategy is still collecting data. This results in wildly different long-term performance of the strategy vs. B&H depending on what the market was doing while GetTradingLoopStartBar was delaying until it had enough days of data. This effect is easily seen on the Equity Curve tab.

I've never figured out a way to synchronize the strategy with B&H to get an apples-to-apples comparison. Ideally B&H would not kick in (and buy) until GetTradingLoopStartBar has the required number of days of data. Do you know if there is a way to do this?
profile picture

Eugene

#6
Answer can be found by searching the forum, in the User Guide and in the FAQ:

1. Forum:

Delay start of B&H (Look who started the thread!)
Buy and Hold starting at specific bar

2. Wealth-Lab User Guide:

Strategy Window > Backtesting Strategies > Inside a Portfolio Simulation > Note on Lead Bars and A Lead Bars Solution

2. Wiki FAQ:

FAQ | Strategies and WealthScript > How to start Buy&Hold from specific bar (not at bar #0)?
profile picture

innertrader

#7
At least I'm consistent ;)

I went through the background and think the GetAllDataForSymbol approach may be the best for me. I am trying to understand what is happening programmatically. In the following code sample:

CODE:
Please log in to see this code.


Is it creating a new object ("b") which contains all data rather than only data starting on selected data range? and does "b.Close" indicate to use this new dataset instead of the default which would be referenced by "Close"?

I have multiple references to "Close" in the beginning of my Execute code. so for example, would I change

CODE:
Please log in to see this code.


TO

CODE:
Please log in to see this code.



Also, would I change

CODE:
Please log in to see this code.


TO

CODE:
Please log in to see this code.


Please let me know if I understand this correctly.

profile picture

Eugene

#8
Happy New Year.

QUOTE:
Is it creating a new object ("b") which contains all data rather than only data starting on selected data range?

and does "b.Close" indicate to use this new dataset instead of the default which would be referenced by "Close"?

Your understanding is correct on both points.

QUOTE:
I have multiple references to "Close" in the beginning of my Execute code. so for example, would I change

Yes, that should work. With a little change to get rid of duplicate code:
CODE:
Please log in to see this code.

It's easy to get out of sync having duplicate definitions and tweaking the code later.
QUOTE:
Also, would I change

As long as the indicators your code does not rely on the "Bars" object (plus any other external Bars objects) vs. the new "b" object, the change should be fine.
profile picture

innertrader

#9
Hi Eugene,

I finally got back to this and implemented today. Look like it's working perfectly! Thank you!

Good catch on the redundant code....

Robert
profile picture

Eugene

#10
Hi Robert,

Good to hear that! You're most welcome.
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).