Runtime Error: Basis price for Position entry cannot be zero
Author: luce50
Creation Date: 6/18/2009 1:34 PM
profile picture

luce50

#1
Using a patchwork of posts from this wonderful site, I have been able to cobble together some code to perform a few simple tasks. However, reality has now set in and I am unable to understand the reason(s) causing the above error. The following code worked prior to an adjustment shown below:

CODE:
Please log in to see this code.


Upon changing the ShortAtMarket methodology using the SetContext command, I began to receive the above mentioned error. My concept is simple. If the 1st intraday bar's (Close > Open), then buy ETF QLD, if it is less than the Open, then buy the ETF QID. Here's the "new" code:

CODE:
Please log in to see this code.

I'm sure I've missed something obvious and would be very appreciative for some corrective guidance.

Thank you,

Robert
profile picture

Cone

#2
Robert, some tips:

1. Use the CODE tag button when posting code (as I've done for you)

2. Never use bar + n, where n > 1 in a trading signal. If you want to do something 2 bars in advance from the current bar, you need to program it another way to avoid other problems.

3. Close[bar+1] is peeking. You can't refer to data in the future. bar + 1 is for Trading Signals. You analyze what happened on this bar, and doing something on the next bar, i.e., trade on bar + 1.

Work on getting all that right, then let's take another look at your full script. You're a beginner, so don't leave anything out.
profile picture

luce50

#3
Cone, thank you for information. I will do my best to incorporate your observations. It looks as though I have several logic errors. I read about "peeking" in the WLP documentation and thought I had avoided its use -- obviously not.

Robert
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).