Of course as a developer there are advantages, in that I only have to write the calculation code once, and it's easier to maintain. But I'm wondering what the performance advantages are, if any....
I've asked a number of questions and NT support has been incredibly helpful in answering my emails. Thank you NT! I'll post here from now on as I haven't been able to find any threads on this topic.
Currently I'm a bit stumped. I have two answers that seem to conflict. Perhaps my understanding of "hosting" is incorrect? Is there a difference between "hosting" and just accessing an indicator's exposed dataseries? Or perhaps the answer varies depending on whether COBC is true/false/left out?
Below are the two questions/answers that seem to conflict:
Question 1) I'm using the following code quite often:
double changeCC = Close[0] - Close[1]
... I'm using this in many different indicators, all applied to the same dataseries (SPY 1min). I'm wondering if it is faster to:
a) calculate double changeCC = Close[0] - Close[1] in just one indicator, store the result in a dataseries that is publicly visible, then reference that stored value from other hosting indicators. The assumed advantage is I'm not accessing the index values of Close[0] & Close[1] more than once in the original hosted indicator.
b) just call double changeCC = Close[0] - Close[1] once inside each indicator that needs it. The thinking here is that it might be more taxing on system resources to access a dataseries value from another indicator rather than calculate it again. And here I'm guessing the answer depends on how complicated the calculation is... for something simple like Close[0] - Close[1] it might be faster to calculate again inside the indicator.
Answer 1)
1) As the indicator you are accessing has already been added to the script it exists in memory, it is less resource consuming to call the value from the indicator than to recalculate it.
Question 2)
2) Suppose I have an indicator called RangeRatio plotted on a chart. Then on that same chart I have a 2nd plot (hosting indicator) which uses RangeRatio in it's calculation. Is the hosting indicator using the same instance of RangeRatio that is already on the chart? Or are there now two instances in memory... one for the RangeRatio plot, and a second for the indicator accessing the RangeRatio calculation? And if two, then do I correctly understand RangeRatio is being calculated twice, once for each instance, upon every incoming tick?
Answer 2)
Yes, the call from the hosting indicator and the hosted indicator will occupy two instances in memory, calculate separately, and perform the calculations twice on each tick if CalculateOnBarClose is false.
Comment