Click here to Login





                                                   Does IFF always call embedded functions regardless of true/false?

  0

0
Josh McCormick
2020-08-13 15:45:06


Given the following formula...

mysymbol="IVV";
tf2 = iff(IsEod()==0,0,getseries(mysymbol,close,LastData));

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...

tf3 = iff(0,getseries("TSLA",close,LastData),getseries("AAPL",close,LastData));

...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?

Thanks again for all your help,
Josh McCormick



QuantShare
2020-08-16 16:52:49

  1

Best Answer
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.


Josh McCormick
2020-08-17 16:24:22

  0

Thank you, sir. Solid answers as always.


Josh McCormick
2020-09-04 12:09:19

  0

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?

Thanks as always,
Josh McCormick



QuantShare
2020-09-07 13:16:28

  0

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)


No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
    To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










    QuantShare

    Trading Items
    Covered Call Screener
    Monthly individual stocks put and call volume
    Put minus Call Options Volume - Market Indicator
    Put Call Volume Comparison Indicator
    Covered Call Strategy Indices - Dow DJIA and NASDAQ-100 Index

    How-to Lessons
    How to create trading rules based on Put and Call volume data
    How to automatically arrange charts?
    How to plot put/call ratio of individual stocks
    How to download a trading item from the Sharing Server
    How to display the number of notes per stock

    Related Forum Threads
    Peak / trough indicators and issue with Functions
    Dll Call
    Custom Fitness Functions for Walk Forward Testing
    Logic for GapUp() & GapDown() functions
    How does Simulator work?

    Blog Posts
    How Does QuantShare Work?
    New Ranking and Percentile Composite Functions
    Trading Indicators using the Rank and Percentile functions
    QuantShare Programming Language Tutorial
    How to create your own technical analysis indicators









    QuantShare
    Product
    QuantShare
    Features
    Create an account
    Affiliate Program
    Support
    Contact Us
    Trading Forum
    How-to Lessons
    Manual
    Company
    About Us
    Privacy
    Terms of Use

    Copyright © 2025 QuantShare.com
    Social Media
    Follow us on Facebook
    Twitter Follow us on Twitter
    Google+
    Follow us on Google+
    RSS Trading Items



    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.