BuyAtStop(bar+1, (Bars.Open[bar+1] + Value)
Author: akardar1
Creation Date: 2/25/2017 1:08 AM
profile picture

akardar1

#1
Hi WL,

Is there anything wrong with this ?
Technically its peeking because I don't know the opening price of tomorrow's bar until the open, but it does not seem like an unreasonable peek for backtesting.

CODE:
Please log in to see this code.


Even though it seems like a valid peak, it does give the "run time error, index was out of range, must be non-negative and less than the size of the collection" message - presumably because I am trying to access a bar which does not exist on the chart ?

Thanks
AK

profile picture

Eugene

#2
Hi AK,

Just one word, and it's GetSessionOpen. To get a start, look it up in the QuickRef and review this latest example.

There's more to be found by typing in the first few symbols (getses...) in the forum's Search box or by googling for site:wealth-lab.com/Forum/ getsessionopen, but that should do it for a start.
profile picture

akardar1

#3
Hi Eugene,

Thanks.
GetSessionOpen seems great, I can see how this would work.
However, I am only using WL for backtesting & the performance visualizers. So I can do without the Alerts/Strategy Monitor.
Executions and alerts are managed with another software tied to a brokerage account etc.
Anyway, my static data provider (CSI) doesn't provide partial bar data, so I cant use GetSessionOpen even if I wanted to.

My concern here is ensuring that the Backtesting logic is sound and is why I asked whether the peek above is valid for a historical backtest. I don't see any issues with it apart from the fact that:

1) It would not generate timely Alerts without GetSessionOpen - do you agree ?

2) When I run the strategy on a symbol where the last bar on the chart (on the right) meets the condition for a trade the next day BuyAtStop(bar+1, (Bars.Open[bar+1] + Value))), I will see the "run time error, index was out of range".
I can only suspect that this due to the fact that there is no bar+1 on the chart yet...
(I do not see the run time error for symbols where the last bar on the chart does not meet the condition for a trade the next day).
How do I work around this ?



profile picture

Eugene

#4
QUOTE:
Executions and alerts are managed with another software tied to a brokerage account etc.

On a related note, did you know that it's finally happened? A 3rd party has recently created a solution for automated trading with Interactive Brokers using WL Developer 6 (static/streaming data included). GetSessionOpen support should also be there if I'm not mistaken:

http://ib-automated-trading.com/

QUOTE:
1) It would not generate timely Alerts without GetSessionOpen - do you agree ?

That's right. Without GetSessionOpen (or Open.PartialValue) you cannot execute your logic for alerts. It only works in backtests - until the penultimate bar.

QUOTE:
BuyAtStop(bar+1, (Bars.Open[bar+1] + Value))), I will see the "run time error, index was out of range".

In this case, you should avoid the natural IOOR runtime error in the code, for example, by...

#1 either preventing the main (trading) loop from checking the last charted bar
CODE:
Please log in to see this code.


#2 ...or before firing an alert
CODE:
Please log in to see this code.



profile picture

akardar1

#5
QUOTE:
did you know that it's finally happened?

Wow, that's major news. At first glance this looks great, I'll dig deeper. Hopefully this is a trend that continues.
IB's data is good, but not ideal, do you see any issues with using a given data provider for historical data (like CSI for instance), and using
GetSessionOpen to retrieve the open/partial bar information from another (Streaming) data provider, like IB ?

QUOTE:
#1 either preventing the main (trading) loop from checking the last charted bar

Of course, worked a treat.
profile picture

Eugene

#6
QUOTE:
using a given data provider for historical data (like CSI for instance), and using
GetSessionOpen to retrieve the open/partial bar information from another (Streaming) data provider, like IB ?

That will not work out: GetSessionOpen is static data provider's feature which doesn't exist in MetaStock/ASCII providers (by design).
profile picture

akardar1

#7
Thank you