I expect the variable 'tf2' to contain the closing price data for the symbol IVV unless I'm on an intraday chart. On an intraday chart, it would simply contain the number zero. This is happening as expected. But what I didn't expect is that when I went into Accounts -> Realtime Monitor -> Data Feeds -> IEX Exchange -> the symbol IVV had a subscription regardless of if I was on the historical chart or the intraday chart. I thought this was odd so I created a more generic case...
...and then I saw that I had a brand new subscription to both symbols (TSLA and AAPL).
QUESTION:
=========
Regardless of the initial true/false variable, does iff call any listed functions and fully evaluates both the true and the false case, and if so, is this the expected/intended behavior? Are there other situation like this? Or is this just symbol caching behavior?
Yes, both cases are evaluated then for each bar, the condition is checked and depending on the result the first or second result is returned for that bar. If you want to avoid that, you can create your own C# custom function that execute just once and either returns 0 or GetSeries.
I've run into a curious artifact which I think might be related to this, and I was hoping to get your input:
I'm plotting a short ratio. Where shorting data is available, the array contains a value (0-100). Where data is not available, it contains NaN. When it comes time for it to plot the array, when it runs into NaN, I want it to use the last good value... UNLESS it is plotting most recent bar. In that situation, I want it to display NOTHING (leave it as NaN and do not use the last good value). I'm using iff to do it. (UpdateColor would have to affect two bars to prevent a line from being drawn.)
Here's the crazy part...
If my code says, "Use the last good value, but if we're on the last candle, use the number 100 instead" (as a test case), then it works GREAT!
Plot (iff(StringEqual(Date(),Now())!=1,NanToLast(short_ratio),100),Date()." ".Now()." Short Ratio",colorBlack,ChartLine,StyleWidth3|StyleHideYAxisValue);
IMAGE: https://i.imgur.com/pQ8IJhV.png
(Focus your attention on the black line towards the middle of the graph.)
So now I adjust my code where it says, "Use the last good value, but if we're on the last candle, just pass along the short_ratio as-is." It plots crazy!
Plot (iff(StringEqual(Date(),Now())!=1,NanToLast(short_ratio),short_ratio),Date()." ".Now()." Short Ratio",colorBlack,ChartLine,StyleWidth3|StyleHideYAxisValue);
IMAGE: https://i.imgur.com/qZ0PIkJ.png
(Focus on the same black line. Suddenly, we're *always* plotting short_ratio and NEVER using NanToLast even when we should be).
I'm wondering if this is a bug, but I can leave that with you. Any thoughts on how I can work around this?
I see holes in the black lines and this is normal since when short_ratio is set to Nan, nothing is drawn (not the first line nor the second line connecting to that Nan value)
Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.