- ago
How can I access unfinished bar info from code for realtime trading? Is strategy cycle run every time the price update for unfinished bar recived?
0
444
13 Replies

Reply

Bookmark

Sort
- ago
#1
Short answer: you do not need this for real-time trading. But you can access the opening price shortly after with ExecuteSessionOpen:

https://www.wealth-lab.com/Discussion/GetSessionOpen-access-daily-Open-today-s-partial-bar-from-strategy-code-6362
0
Cone8
 ( 21.65% )
- ago
#2
Strategies run at the end of the [next] complete bar. To calculate things more quickly, you must use smaller intervals - 1-minute bars.. n-second bars.. n-Tick bars (though I wouldn't recommend ticks unless you have a very fast, high-end machine).
0
- ago
#3
But it would be great to somehow work with unfinished bar. It will be a great way to react to price change quickly (Already using 1 min bars for crypto). There can be a separate method in UserStrategyBase like RealtimePriceChange(OHLCV) { do smth } executed same way as Execute on next price change
0
MIH8
- ago
#4
Maybe you could describe what kind of interaction you want and what is the reason for it. Then you could be given a more differentiated answer.

There are different tools streaming data, like the Quotes Tool, Chart Tool and to some degree the strategy monitor too (live bar is streamed and is building bars with small scale e.g. 10 seconds).

Which information is to be queried exclusively and relevantly on this time scale to make your strategy successful?

And now a very crucial question. Do you have sufficient historical data to backtest the desired trading scale under one minute?

An "unfinished bar" is normally just a construct of a lower time scale.


0
- ago
#5
My idea was to implement a trailing stop for highly volatile markets. It can be implemented via broker integration or just passing streaming data of the last unfinished bar to UserStrategyBase. Not all brokers support trailing stop and it will be a huge work to rewrite all broker extensions, but adding info about last unfinished bar seems like a not complicated task and it will give the user more creativity because it will allow user to do some actions during sudden huge price changes and not to react to them only after bar closes.
0
MIH8
- ago
#6
Ok, it's the same topic as in the other thread. Surely you want to backtest the effect of a trailing stop as you use it for trading. Some points to think about.

1. even though a trailing stop order can be placed with the broker using eod, you need to backtest it beforehand. Since there is no streaming with a moving bar when backtesting, you may want to think about intraday trading.

2. one option is to build the eod strategy with compressed data on a lower time scale. These utilities can be found in the documentation of the framework. However, this way you get access to a lower scale where you can easily use a trailing stop. This way you can trade the strategy and backtest it in the same way, which is very important.

3. the critical point here is that you need the intraday data. Before you say that 1-min is not sensitive enough, check the differences between 5-min and 1-min. Do a backtest. I think you will be surprised to see that the results do not improve on the lower time scale. You can repeat this with 30/15min, 15/5min and 5/1min, and if you have enough 10s data, test 1min/10s.

4. If you are not in a position to develop this strategy, do not have the time or are not in mood for it, the WL team offers the service https://www.wealth-lab.com/Support/Concierge

5. applying the trailing stop to a bar that has no information about the timing of the prices in the backtest will surely backfire.
0
Cone8
 ( 21.65% )
- ago
#7
QUOTE:
it would be great to somehow work with unfinished bar.
Let's be clear so that you have realistic expectations.
Your WealthLab strategy can work with complete bars only - this is not going to change in any future that I can foresee.
0
MIH8
- ago
#8
Hello chuhchuhh,

i am curious. As you seem to be very experienced according to your profile i ask myself now, how do you build the bridge between backtest and trading?

Is your strategy already established and tested successfully (with different other tools) and you simply need a technical instrument inside the WL software?

So, please take my comments as usual WL user who would not be able to backtest the trailing stop within a bar beforehand. The usual WL user would/should use a intraday strategy to confirm that the trailing stop does work (for the desired time scale)
0
ww58
- ago
#9
As a suggestion that may be useful for some strategies is implementation of callbacks in wl. For example, onTradeClose, onBarStart etc
0
- ago
#10
QUOTE:
i am curious. As you seem to be very experienced according to your profile i ask myself now, how do you build the bridge between backtest and trading?

Before using wealth-lab I had my own backtester and trading strategies that work on 1s interval, also some market neutral strategies. I'm new to wealthlab and at the moment discovering its capabilities. So I'm planing to use wealth-lab for quick idea testing, data history management and maybe real time trading. And when I'm discovering something that I think will be useful for all wealthlab community I'm writing questions to this forum.
QUOTE:
Is your strategy already established and tested successfully (with different other tools) and you simply need a technical instrument inside the WL software?

As I mentioned before I have a couple of running strategies. I'm using WL software to discover something new and have one program to access all the markets.
0
- ago
#11
QUOTE:
3. the critical point here is that you need the intraday data. Before you say that 1-min is not sensitive enough, check the differences between 5-min and 1-min. Do a backtest. I think you will be surprised to see that the results do not improve on the lower time scale. You can repeat this with 30/15min, 15/5min and 5/1min, and if you have enough 10s data, test 1min/10s.

Not in case of crypto - some assets can go up 300% and down 300% in two minutes (low liquidity assets). In crypto 1 min timeframe is the lowest supported. I've tryed to switch to 10 sec timeframe on chart with streaming turned on and it's not allowed. Maybe I'm doing somthing wrong? Can I choose 10 sec interval for the streaming chart or strategy monitor for crypto?
0
- ago
#12
QUOTE:
There are different tools streaming data, like the Quotes Tool, Chart Tool and to some degree the strategy monitor too (live bar is streamed and is building bars with small scale e.g. 10 seconds).

Thank you!
Found the way to do it! First choose scale 10 sec and then stream. Scale change not working if data is already streaming (streamed data for 1 min candles and switch to 10 sec not switching).
1
Cone8
 ( 21.65% )
- ago
#13
Which Data Provider?
0

Reply

Bookmark

Sort