Bar number must be 6 or greater
Author: rbryant
Creation Date: 6/23/2014 6:46 AM
profile picture

rbryant

#1
Sir

I am getting the error message "Bar number must be 6 or greater" and I dont know why, nor how to fix it (when I change the starting bar to a higher number, the number in the error message always exceeds it). For some reason, without changing code as far as I recall(!) I was getting a 'Basis price can not be 0' message a few minutes ago - even though none of my price bars are zero. What is wrong with this code please?

CODE:
Please log in to see this code.
profile picture

Eugene

#2
Is this closer to what you're looking for?

CODE:
Please log in to see this code.
profile picture

rbryant

#3
Eugene
It always amazes me how fast you respond to emails, year after year. A true example of professionalism.

That code works. Why didnt my code work please?

Second question: Is it possible to buy half a position, say for stock1. So if the sizing is set to 50%, then 50% of portfolio value will be used for stock2, and how can I make the purchase of stock1 only 25% of portfolio value? Maybe this is not possible.

Thank you very much
Rod
profile picture

Eugene

#4
1 - There was a logic error: despite the creation of multiple positions, the code was using single-position patterns like IsLastPositionActive or LastPosition.

2 - Wealth-Lab's architecture does not support accessing portfolio equity in strategies. To overcome this limitation, you can:
a) Rewrite your script to process DataSetSymbols and keep track of Portfolio Equity manually: Limit Monthly Drawdown / Portfolio Equity Tracker
b) Or leave it as is and use this technique: Interacting Dynamically with Portfolio Level Equity

To set the size as a function of equity, you may:
1) use SetShareSize() in conjunction with the "WealthScript Override (SetShareSize)" option in the Position Sizing control
2) or if you prefer that the position size adjusts to the changing equity, here are 3 PosSizers from the MS123 PosSizer library that can be used to specify a percentage of equity directly (more or less). Pick an approach that suits you:

2.1) Position Sizing with the Trend - through "Signal name options". In your Strategy code, assign an entry signal to your positions (i.e. instead of "Group1"/"Group2" choose something like "bullish"/"bearish" or "stock1"/"stock2") and then make necessary adjustments to the PosSizer dialog.
2.2) Priority Adjustment PosSizer is similar to a) but here you directly assign a position size as % of equity. Instead of entry signal name, here you assign a Position.Priority value exactly as illustrated in the QuickRef and configure the PosSizer accordingly.
2.3) Position Options > "Use .Tag". Yet another approach to the same problem. Usage is described in the Wiki manual.
profile picture

rbryant

#5
Thanks Eugene.
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).