Runtime error: Basis price for position entry cannot be zero
Author: sourkraut
Creation Date: 4/19/2011 10:00 AM
profile picture

sourkraut

#1
I uderstand what the error says, and there are bars with zero values, BUT I'm excluding these bars from trading, so why am I still getting the error?

Here is the relevant code (there are no other buy/sell orders):
CODE:
Please log in to see this code.


The error:
(copy to clipboard would be nice for the error window):

QUOTE:
Runtime error: Basis price for Position entry cannot be zero
at WealthLab.Strategies.MyStrategy.Execute()
at WealthLab.WealthScript.ShortAtClose(Int32 bar)
at WealthLab.WealthScript.ShortAtClose(Int32 bar, String signalName)
at WealthLab.WealthScript.a(Double A_0)


Thnx
profile picture

Eugene

#2
Somehow I fail to see where is the code excluding the zero value bars for bmSymb?
profile picture

sourkraut

#3
My appologies, I did not show the connection between bmSeries and bmSymb.

The top part of the code actually is:

CODE:
Please log in to see this code.


CODE:
Please log in to see this code.


Does that not exclude any bar containing zero, in either the active or the bmSymb?

profile picture

Eugene

#4
No. Sorry if my commentary wasn't clear but what I meant to say is that you're setting context to a symbol whose bars have zero values w/o making any check:
CODE:
Please log in to see this code.

However, Wealth-Lab must use the close price to determine the basis price for the Position:
QUOTE:
Runtime error: Basis price for Position entry cannot be zero
profile picture

sourkraut

#5
QUOTE:
Wealth-Lab must use the close price to determine the basis price for the Position
Sorry Eugene, I still don't understand. If the close is zero, the program flow never reaches the trade code.
Are you saying, that WL need all close prices for a trade, even if not accessed by the trade?
profile picture

Eugene

#6
QUOTE:
If the close is zero, the program flow never reaches the trade code.

Who knows? You didn't show the complete code as:

1. There are no exit orders,
2. The code creates impression that bmSeries is being created on every bar.
profile picture

sourkraut

#7
QUOTE:
Who knows? You didn't show the complete code as:

1. There are no exit orders,
2. The code creates impression that bmSeries is being created on every bar.
OK, let me rephrase:

CODE:
Please log in to see this code.



I surrounded all trade code with tests to eliminate the bars that contain zero. There are other ANDed conditions, but the effective code is as above.

Is there any way there could be a "Basis price ... cannot be zero" error, given the above code?
profile picture

Eugene

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

sourkraut

#9
I appreciate, that you're trying to give me a solution to a problem. Unfortunately, I need an answer to the question, regardless of solution. The code below is merely representative of that in the actual strategy.

CODE:
Please log in to see this code.


The zero values are not just in the first bars of one symbol, but also in multiple bars. For that reason I cannot simply start looping at the first valid value, but must test every bar.

My question remains: Is there any way that a trade within the tests for greater than zero could generate the "Basis price ... cannot be zero" error?
profile picture

Eugene

#10
QUOTE:
My question remains: Is there any way that a trade within the tests for greater than zero could generate the "Basis price ... cannot be zero" error?

Before answering, let's expand your condition(s) the following way and see if it makes the error message go away:
CODE:
Please log in to see this code.