Indicator calculation order

Questions about MultiCharts and user contributed studies.
albertc
Posts: 13
Joined: 21 May 2009

Indicator calculation order

Postby albertc » 06 Jun 2010

I want to apply two different indicators to one chart with one indicator passing shared variables to the other via GlobalVariable.dll and ELCollections.dll. However, the receiver code in one indicator requires the sender code in the other indicator to finish before it can do anything. As such, is there a way for PowerLanguage or MC to dictate which indicator loads first? Can I specify that one indicator completely finish its calculations before another indicator starts running?

Any assistance would be greatly appreciated. Thanks!

bowlesj3
Posts: 1977
Joined: 21 Jul 2007
Has thanked: 155 times
Been thanked: 395 times

Postby bowlesj3 » 06 Jun 2010

I am pretty sure that they run in top down (alpha) sequence within a chart. You can be sure of this by putting a fileappend command in both studies which writes to the same file and maybe you would write out the study name and the bar number and the bar's time too. Of course you put this on the last bar on the chart.


FileAppend("C:\Trace_.txt",
"study1" + " " +
"time_s" + " " +
numtostr(time_s,0) + " " +
NewLine);


FileAppend("C:\Trace_.txt",
"study2" + " " +
"time_s" + " " +
numtostr(time_s,0) + " " +
NewLine);

I was thinking later that you could limit these studies to execute not on every tick for your test. Either that or include the tick number in the fileappend along with the last price(close).

Unfortunately the order that charts are executed within a workspace seems to be random. Multithreading I think. Here if things need to be in order you have to set up GV links to be sure whatever has been done in the other study (many times the next tick is when the second study run of the set gets done).

albertc
Posts: 13
Joined: 21 May 2009

Postby albertc » 06 Jun 2010

Hi bowlesj3,

You're right about how indicators are processed in a top-down sequence (after rearranging the order of the indicators a few times). Unfortunately, the indicator I want to process first should be placed on the bottom of the chart window. That's why I had issues with variables syncing. Although I could rearrange the order of the indicators on the chart, this is not ideal from a visual perspective. What would be ideal is MC allowing us to decide which indicators to process first irrespective of the order they appear on the chart.

bowlesj3
Posts: 1977
Joined: 21 Jul 2007
Has thanked: 155 times
Been thanked: 395 times

Postby bowlesj3 » 07 Jun 2010

What would be ideal is MC allowing us to decide which indicators to process first irrespective of the order they appear on the chart.


I agree (it would require a sequence number however). I use A_ or A1, etc. The A keeps all my indicators/studies at the top of the editor together and the numbers or letters after that A are to order them in the chart window. So I have my own sequence system build right into the name and it is best to have it as the first item anyway in that list.



Although I could rearrange the order of the indicators on the chart, this is not ideal from a visual perspective.


The rest of the name is such that they relate to each other.

having said that, I am at the point where I make few code changes now (just focusing on trading now). When one gets to that point one does not care to look at the list of studies much. You just start your machine in the morning (whenever) and do your thing. These items go to a priority level so low you forget all about them. That is all that really matters in the end.

On the other hand the order for me is very important in that I send key strokes out to turn them on and off at times (or do other things). However being visually pleasing is not the concern here. It is just that the program has to work.

albertc
Posts: 13
Joined: 21 May 2009

Postby albertc » 10 Jun 2010

With regard to my issue of variables syncing, I ended up writing an additional indicator which does nothing other than calculating the required values and mapping them to a shared list using ELCollections. This "dummy" indicator is added to SubChart #1 while the indicator that I want to appear on the bottom of the chart just pulls the variables from the shared list. It's an ugly hack, but like you, I'm also a pragmatic person. It'll have to do for now.

However, with that said, I occasionally get this error message while loading a workspace with the dummy indicator: Error in study "Study Name" :: Not enough series length. Bars reference value:(number).

I suspect this error is due to the fact that I'm applying the dummy indicator to Base Data #2. Maybe it's something to do with multithreading? But I thought TS SUPPORT had already resolved this bug in MC 5.5 (which I'm using) according to their release notes. Apparently not. This issue bugs me to no end.

bowlesj3
Posts: 1977
Joined: 21 Jul 2007
Has thanked: 155 times
Been thanked: 395 times

Postby bowlesj3 » 10 Jun 2010

As far as I remember, the error is that it is trying to reference back enough bars that it can not even find a bar. In other words it is trying to reference back before the first bar on the chart for that data series.

It is not the same as trying to refrence back past the maxbarsback setting which can cause the hidden recalculate (meaning it restarts the study and redoes all code since currentbar = 1).

albertc
Posts: 13
Joined: 21 May 2009

Postby albertc » 10 Jun 2010

Thank you for your insight. Is there a way to prevent this error from happening? Can I write something in the indicator to tell MC to not reference bars before the data is even loaded?

bowlesj3
Posts: 1977
Joined: 21 Jul 2007
Has thanked: 155 times
Been thanked: 395 times

Postby bowlesj3 » 11 Jun 2010

If your study is using an index/subscript in its logic MC has no way of knowing your index will exceed either the MaxBarsBack setting or actually reference back farther than the number of the bars on the chart. No compiler is that smart (it would have to be able to figure out your logic). If you exceed the MaxBarsBack setting (but is still not yet referencing back beyond the first bar on the chart) MC does know and it does the recalculate with a larger MaxBarsBack setting (over and over again) until it gets one that is large enough. I had a bug once that caused MC to set the Maxbarsback setting to 8,000 ish. It is probably during this process of the hidden recalulate that it detects that there is no more room left in the chart to increase the MaxBarsBack setting.


Return to “MultiCharts”