Some questions about indicator data

Moderator: admin

Some questions about indicator data

Postby robocod » Wed May 16, 2012 4:29 am

Hello, I am new to MarketScope coding. I'm looking at porting some of my indicators and packages to run on MarketScope.

One of the key differences that I noticed so far is that on my old platform, the chart was loaded with all the required bars (e.g. say 1000 bars). Bars were indexed from numBars-1 to 0 in this case, with 0 being the most recent. As new bars were added with the live data stream, the number of bars would increase of course, with bar 0 always being the most recent.

I understand that with MarketScope the bars are numbered the other way around, with 0 being the oldest, and source:size()-1 being the most recent I guess. That's ok.

But, one key difference with MarketScope is that you can extend the chart. (This wasn't possible with my old platform). So, if for example I scrolled back 2 months on the chart, new bars would be added.

Now, I saw some handling for host:execute("getHistory", ...) and host:execute("extendHistory", ...) which are used to extend the history. But this seems to be for manually added data streams. I didn't see this being done for the 'primary' data stream, i.e. instance.source. (By the way, do you use a special name for this stream? I'll call it the 'primary stream' for now). Does this 'primary stream' also need to be managed to get more data when the chart is re-sized, or is it handled automagically somehow?

When the chart is re-sized in this way, what happens to Update()? Does the 'mode' value indicator that I need to re-calculate the whole thing?

By the way, I also assume that Init() is only called once, when the indicator is added to the chart. Is Prepare() also only called once? What if the timeframe is changed? Does this call Prepare() again?

Sorry, for so many questions. I'll be on the learning curve for a while yet.
User avatar
robocod
FXCodeBase: Graduate
 
Posts: 298
Joined: Thu May 10, 2012 4:25 pm

Re: Some questions about indicator data

Postby sunshine » Thu May 17, 2012 2:45 am

Hi robocod,

Thanks for your post. Please see the responses below.
robocod wrote:Now, I saw some handling for host:execute("getHistory", ...) and host:execute("extendHistory", ...) which are used to extend the history. But this seems to be for manually added data streams. I didn't see this being done for the 'primary' data stream, i.e. instance.source. (By the way, do you use a special name for this stream? I'll call it the 'primary stream' for now). Does this 'primary stream' also need to be managed to get more data when the chart is re-sized, or is it handled automagically somehow?

The functions host:execute("getHistory", ...) and host:execute("extendHistory", ...) are used only in case the indicator needs data other than instance.source data. So you don't need to manage the 'primary stream'. Moreover, you can't do this. It is handled automatically.

robocod wrote:When the chart is re-sized in this way, what happens to Update()? Does the 'mode' value indicator that I need to re-calculate the whole thing?

When a large number of periods appears at the beginning of the source (for example, when you scroll the history into past in Marketscope), the Update function will be executed for all periods as for the initial creation.
Please see also Update(period, mode)

robocod wrote:By the way, I also assume that Init() is only called once, when the indicator is added to the chart. Is Prepare() also only called once? What if the timeframe is changed? Does this call Prepare() again?

Prepare() is called each time when the indicator is applied to the new data, for example when a timeframe or instrument is changed.
sunshine
 


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 66 guests