Plot Second CandleStick Chart
Author: boreland
Creation Date: 11/24/2016 5:24 PM
profile picture

boreland

#1
I know that it is possible to download bar data for a second symbol, but is it possible to plot a second series of candlesticks in another pain, and is it possible to keep this second chart updated with each new bar?
profile picture

Eugene

#2
QUOTE:
is it possible to plot a second series of candlesticks in another pain,

Yes, provided that your PricePane has Candlestick ChartStyle applied. Secondary panes share the primary pane's chart style. See PlotSymbol in the QuickRef.

QUOTE:
and is it possible to keep this second chart updated with each new bar?

Yes but not in a streaming manner i.e. no partial bar on that pane. It will get updated once a new OHLC bar is added to the Bars object.
profile picture

Cone

#3
Re: It will get updated once a new OHLC bar is added to the Bars object
We got to be careful here. The problem is that the secondary series is requested "on-demand". When paired with a streaming symbol, the on-demand interval is almost never yet "built" on the server at the moment that the streaming symbol updates, therefore the updated bar is not returned for the secondary symbol.. until the next interval. So the secondary symbol is always a bar behind.

Fortunately we've talked about this enough to create a streaming "pairs" solution. I'll find the thread and update this post with it here...
profile picture

Cone

#4
Couldn't find the thread, but found the code. It's a two-script solution.

The idea is to run your secondary symbol in a streaming window and save its Bars object to global memory. Your trading script waits a split second for the new global Bars object and then loads it.

First script is for the secondary symbol:
CODE:
Please log in to see this code.


And this outlines how you'd use it in pairs script:
CODE:
Please log in to see this code.
profile picture

Eugene

#5
QUOTE:
Couldn't find the thread, but found the code. It's a two-script solution.

It's been published in the Wiki ;) Choosing optimal trading tool: Strategy Monitor or Strategy window
profile picture

boreland

#6
Wow! Thank you guys I'll look at this with great interest.
QUOTE:
So the secondary symbol is always a bar behind.
That's not good, but I've implemented a system where I pull in data from IB (bid/ask) so I could also pulling in last price on WLP bar close to implement a trading decision. But of course any order placed within the strategy will use the primary symbol not the secondary.

Is there anyway to open a new chart programmatically with a default strategy attached to it?

Although this might be pointless because there is no way to enable auto-place programmatically, unless you know of a way to do this?

Hmm what happens if you set Bars.Symbol = "some other symbol"? It's certainly is picked up on the charts title even though the data series being plotted is for a different symbol.
profile picture

Cone

#7
Re: So the secondary symbol is always a bar behind.
Just to be clear, this is the case when the secondary symbol is requested on-demand. The code above resolves that problem.

QUOTE:
Is there anyway to open a new chart programmatically with a default strategy attached to it?
Probably only using something like AutoIT.

QUOTE:
enable auto-place programmatically
You mean, enable the Auto-Stage/Place button in the Strategy Window's Alerts tab. Again, AutoIT can probably do that too.

QUOTE:
Bars.Symbol = "some other symbol"?
Probably a really bad idea unless you really know what you're doing. Why would you need to do that?
profile picture

boreland

#8
Re:
QUOTE:
Probably only using something like AutoIT
I'm not familiar with this. Is there any information on this?

I can also confirm that changing the symbol in the code results in the order that is placed using that symbol.

@Cone I'm confused. How do I get the above two script solution to run? I have one script running in a one chart, the second throws an error when run in a second chart. Does that get run in a second chart?
profile picture

Cone

#9
AutoIT: https://www.autoitscript.com/site/
Here's an example of an AutoIT script that I whipped up recently to click a button in Wealth-Lab's Orders tool:
Removing Orders Programmatically from Order Manager

QUOTE:
Does that get run in a second chart?
Right. Run both in streaming charts with same interval.

QUOTE:
the second throws an error when run in a second chart
Be more specific.
Anyway, start the PairsBarsLoader script first, and make sure to edit the pair symbol in the second script to be the one on which PairsBarsLoader is executing. If you don't, I'd expect an error.
profile picture

boreland

#10
So you have a back ground chart that is used to update SetGlobal(s2Bars, Bars). The second chart is then able to read this dataset and use it for what ever. So the problem is that you have to have pre-determined that you want that dataset to exist and be updated.

It would seem possible using AutoIt to possiblely create (sporn) a chart from within another chart. There is good reason to want to do this. I recently integrated the TWS IBApi in my strategies so that I might have access to bid/ask data and market depth information. Having done this I realized that I now have access to IB's market scanner, so I'd like to dynamically generated charts and have them auto-place orders.

How did you figure out the keystrokes for the auto order remove programme, which I note was in response to one of my earlier questions. I really appreciate the effort you made to come up with this creative solution.
profile picture

Cone

#11
I can't take credit for being the first to use AutoIT with Wealth-Lab, but considering what you want to do, it's probably asking too much from an AutoIT script. Just opening a specific strategy would be a challenge with AutoIT, although you could set it as a default strategy for a new Workspace. And then the challenges begin trying to click the right button/tab in a child window. It might be possible, but it would be a real kludge. I'd look for another way... maybe you don't need Wealth-Lab at all for the live trading part? Wait, I'm confused - are you trading with IB or Fidelity?
profile picture

boreland

#12
@Cone
QUOTE:
Wait, I'm confused - are you trading with IB or Fidelity?
Well as you might suspect both, but mainly with Fidelity.

SHIFT_CTLR_C opens a new chart using what ever symbol is in the box, and uses the settings from the data manager.

So this will works:
CODE:
Please log in to see this code.

But I do not know how to:

1. open a chart with a default strategy attached?
2. populate the symbol box in data manager?

In theory 2 should be doable as i think you can enumerate all the windows of the system and send windows messages to any window. There is a tool called windows inspector available here https://www.binaryfortress.com/WindowInspector/Download/
profile picture

Eugene

#13
QUOTE:
But I do not know how to open a chart with a default strategy attached?

A saved Workspace is capable of both tasks: loading a predefined strategy with Streaming on.
profile picture

Cone

#14
SHIFT_CTLR_C is just a new chart, not a Strategy. The problem is opening a specific strategy in a Workspace using CTRL_O, which opens the Strategy Explorer... then you need to find and open a specific strategy.

Anyway, like I already proposed, a Workspace would be the way to go, but then the real work starts there.
profile picture

boreland

#15
There is another way perhaps: SHIFT + KEY_PRESS opens an input dialog box within the chart with whatever letter key pressed entered into the input box first.

Wow check this out:
CODE:
Please log in to see this code.

This works brilliantly:)) It pops open a new symbol dialog box in the top left corner of the current chart, adds the symbol to the box, and hits enter. Sweet! So you open a bunch of dummy charts running the scanner input strategy. Then when you want to go to a particular symbol you run the above piece of code. If you wish to have all these dummy charts minimized and have them pop-up is normal mode the then use this:

CODE:
Please log in to see this code.

All that is left is to place the chart in "Auto-PLace" mode. Figuring out which symbols from the scanner are being traded has to be done in the IB Wrapper class.

Is there possibly an "Auto-PLace" shortcut?

If not, this is a relatively minor thing as one can simply wait for a chart to pop up and enable "Auto-Place" manually I suppose. I'll be testing this live Monday morning.
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).