Creating an instrument from calculated data  [SOLVED]

Questions about MultiCharts and user contributed studies.
PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Creating an instrument from calculated data

Postby PD Quig » 26 Jul 2013

I've got a strategy that trades the price delta between two instruments. Right now the delta is an indicator that plots as a line but I want to apply some studies to it that require OLHC data points to calculate. Is there any way to create to this on the fly or do I have to construct a custom instrument out of the raw data? Ideally I'd like to view the delta as candlesticks.

Thoughts?

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Creating an instrument from calculated data

Postby TJ » 26 Jul 2013

I've got a strategy that trades the price delta between two instruments. Right now the delta is an indicator that plots as a line but I want to apply some studies to it that require OLHC data points to calculate. Is there any way to create to this on the fly or do I have to construct a custom instrument out of the raw data? Ideally I'd like to view the delta as candlesticks.
Thoughts?
Nothing prevents you from creating 4 data points of delta on the fly.

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: Creating an instrument from calculated data

Postby PD Quig » 26 Jul 2013

Agreed, but if I want to chart those four points as a candle on a chart?

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Creating an instrument from calculated data

Postby TJ » 26 Jul 2013

Agreed, but if I want to chart those four points as a candle on a chart?
...then plot them as OHLC

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: Creating an instrument from calculated data

Postby PD Quig » 26 Jul 2013

TJ,

I know I can plot four points for each hour, day, etc., but I was hoping not to have to re-create candlestick or bar charting functionality, i.e., drawing small horizontal opening and closing tick trend lines, and vertical bars or bodies of the proper length and color, in order to view the data in a standard format. Am I missing something subtle--or perhaps obvious?--in your comment?

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: Creating an instrument from calculated data

Postby furytrader » 30 Jul 2013

You can use the PlotPB command to easily replicate a bar chart.

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: Creating an instrument from calculated data

Postby PD Quig » 30 Jul 2013

Great idea...that didn't occur to me. Although it still wouldn't allow applying indicators directly to the chart.

User avatar
piranhaxp
Posts: 241
Joined: 18 Oct 2005
Has thanked: 4 times
Been thanked: 30 times

Re: Creating an instrument from calculated data

Postby piranhaxp » 31 Jul 2013

Why not exporting the delta as OHLC in a txt-file with headers :

date, time, open, high, low, close

and mapping it as symbol via ASCII-Mapping gain ?

But I'm not sure ASCII-Mapping will work with the "Resolution" problem as time-format 1, 2 ... 1435 ... etc etc.. Then it should be work as a symbol :)

Please keep me updated it is working or not.

Mike

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: Creating an instrument from calculated data

Postby PD Quig » 31 Jul 2013

I know I could construct a custom instrument from the data, but that comes with the burden of having to update the data regularly and being without real-time data between updates. Not sure what I'm going to do at this point. I can use indicators that only require one price data point per bar but have to code each one of them to take the price delta as the price input. Kind of discourages experimentation...

User avatar
piranhaxp
Posts: 241
Joined: 18 Oct 2005
Has thanked: 4 times
Been thanked: 30 times

Re: Creating an instrument from calculated data

Postby piranhaxp » 31 Jul 2013

Please correct me if I'm wrong, but I thought symbols from ASCII-Mapping are updated automatically.

This means you could write a "study" to calulate your delta and convert it to an OHLC data set. Then you "export these data via FileAppend-command with date & time for each bar in a txt- or csv-file like "delta_OHLC_1min.txt". Maybe I'm wrong, but this file would be written on every new bar and so updated automatically and these updates should be shown in the charts without manual adjustments.

Again, pls correct me if I'm wrong.

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: Creating an instrument from calculated data

Postby PD Quig » 31 Jul 2013

You're probably right. I haven't done any research yet...

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: Creating an instrument from calculated data

Postby PD Quig » 02 Aug 2013

I just wrote a quick indicator to plot the price difference between two different instruments. It works fine when the plot is built from tick data on the fly, but all bars plotted before the live tick stream started plot as one big blob (from zero to the high). I understand why that happens given my code, but now the challenge is to plot the historical data based on the tick data also.

Thoughts?

Code: Select all

variables:
Delta (0),
intrabarpersist Bar_High (0),
intrabarpersist Bar_Low (0);


// calculate delta

Delta = close data1 - close data2;

if barstatus = 0 then begin

Bar_High = Delta;
Bar_Low = Delta;
end;

if barstatus > 0 then begin

if Delta > Bar_High then Bar_High = Delta;
if Delta < Bar_Low then Bar_Low = Delta;
end;


PlotPaintBar(Bar_High,Bar_Low,"Delta",black);
Attachments
Delta_line_chart_vs._bar_chart_showing_the_bars_not_built_on_the_fly.png
(48.64 KiB) Downloaded 1138 times
Delta_line_chart_vs._bar_chart_built_from_tick_data.png
(45.68 KiB) Downloaded 1115 times

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Creating an instrument from calculated data  [SOLVED]

Postby Andrew MultiCharts » 09 Aug 2013

We are considering a feature that would allow to create custom symbols and plot them on charts to base your scripts on them for future versions, but no there is ETA at the moment. I found a feature request in PM, you can vote for it.

In theory the following should be working:
A custom indicator applied to a chart with multiple data series, that would be reading their values, perform some calculations and write the output values down to an ASCII file. By means of ASCII mapping you should be able to read those values in real-time and feed another chart with them where you can apply any other script.


Return to “MultiCharts”