Condition: split happened X bars ago
Author: kelvinyip
Creation Date: 12/20/2017 2:41 PM
profile picture

kelvinyip

#1
I have this code below and I want to break out of the loop when split happened X days ago. When I run it, it doesn't matter what the daysSince number is, fdr.DaysSinceFundamentalItem(bar, out daysSince) always returns true...

What is the proper way to do this ? Which fidelity data should I enable to get split data?

thx


CODE:
Please log in to see this code.
profile picture

Eugene

#2
This function returns the number of calendar days since the last split and, since it was found, it's always true. Are you sure you need this and not the number of bars?
profile picture

Eugene

#3
There are various way to do it. Here's one. Requires Community Components installed (for AddTradingDays). The idea here is to test for the most recent split using GetFundamentalItem (more info in the QuickRef).

CODE:
Please log in to see this code.
profile picture

kelvinyip

#4
Actually, I just don't want to trigger buy if the stock was split yesterday or today .
So, fdr.DaysSinceFundamentalItem(bar, out daysSince) !=1 || fdr.DaysSinceFundamentalItem(bar, out daysSince) !=0 would do it ?
profile picture

Eugene

#5
Are you sure you've seen post #2?
QUOTE:
Actually, I just don't want to trigger buy if the stock was split yesterday or today .

CODE:
Please log in to see this code.
profile picture

kelvinyip

#6
I think post 2 is what I need. thx
profile picture

Eugene

#7
You're welcome.
profile picture

kelvinyip

#8
I am running a 15min strategy from the monitor and I get this. NSP happens to have split recently. what sort of code can I put in to get around this ?
I tried the code on post#2 and it works on daily...but somehow not on intraday... thanks in advance

12/21/2017 6:59:39 AM: Processing 2:1 Stock Split for NSP ...
12/21/2017 6:59:39 AM: Processing 2:1 Stock Split for NSP ...
12/21/2017 6:59:39 AM: Error(3): Object reference not set to an instance of an object.
12/21/2017 6:59:39 AM: Leaving Update Thread from catch
profile picture

Eugene

#9
This works on intraday. Strictly for trading, N/A to backtesting:
CODE:
Please log in to see this code.
profile picture

kelvinyip

#10
What actually causes this type of error ? Let's say I actually want to consider this symbol even though it had a split recently. What/which Fidelity data set am I supposed to update so the split processing would work properly ? I selected Fidelity as datasource. This is in 15 min timeframe market monitoring mode

thx

12/21/2017 6:59:39 AM: Processing 2:1 Stock Split for NSP ...
12/21/2017 6:59:39 AM: Processing 2:1 Stock Split for NSP ...
12/21/2017 6:59:39 AM: Error(3): Object reference not set to an instance of an object.
12/21/2017 6:59:39 AM: Leaving Update Thread from catch
profile picture

Eugene

#11
QUOTE:
What actually causes this type of error ?

Let's say it's not the WealthScript code which is discussed here in the thread "Condition: split happened X bars ago".
profile picture

kelvinyip

#12
What did I do wrong here ? 12222017 contains the same symbol set as the 15mins used in this code except 12222017 is daily... When it hits NSP, I get that errror above. thanks

************code sample below******

CODE:
Please log in to see this code.
profile picture

Eugene

#13
Well your code runs OK for me in the SM on Google 5-minute and EOD data (in "20171222") for NSP:
QUOTE:
Symbols already up to date: NSP,
Loading Data for NSP
1393 bars returned
Creating Executor
Executing: NSP
Run Once Processing Completed
Run Now Ended
Leaving Populate Thread
profile picture

kelvinyip

#14
I did SetScaleCompressed( 15 );

does it have to be 5 mins ?? I am getting this errror everyday .... what should I check ?
profile picture

Eugene

#15
Your
CODE:
Please log in to see this code.

works on lower intraday multiples like 1-Minute, 3-Min, 5-Min only. It has no effect on Daily data nor on 15 min scale - if your question concerned this.
profile picture

kelvinyip

#16
I caught this line in the data update just now

NLR 38145 bars 12/26/2017 3:15 PM 0 bars added
Processing 2:1 Stock Split for NSP ...
Provider update complete for Fidelity Investments

Perhaps, this type of update is not timely... (fidelity dataset) ?
profile picture

Eugene

#17
I'm not sure what do you want from me? I've already provided you different code that works. I cannot reproduce any error.

Unless Cone has a different expert opinion on this it looks intentional and normal to me:
QUOTE:
Processing 2:1 Stock Split for NSP ...
Provider update complete for Fidelity Investments


Do you always keep your Fidelity DataSet(s) up to date by running a scheduled or manual update before market hours?

Finally, does the question (or is this an issue) you're raising in this thread negatively affect anything?
profile picture

kelvinyip

#18
I just got the error message again... It does affect my normal operation because the scanning process will quit out. For now, I am manually removing NSP and the monitor would scan properly
profile picture

Eugene

#19
Does it affect this very code only? If so, wrap your logic in a try/catch block. Or would processing the same DataSet stop out at NSP when running plain vanilla code like "Moving Average Crossover"?

Re: your code, I'd like to notice the following. Being run on 15-minute data, SetScaleCompressed(15) is simply N/A. But if it were run on a different bar scale like 5-min, it'd open a can of worms. Because RestoreScale() is missing and due to the restriction in putting trading directives inside a SetScale... block, any trading directives (BuyAtMarket, SellAtClose...) that go below SetScaleCompressed() would be in la-la land.
profile picture

kelvinyip

#20
oh, I only run it on 15 mins, so I can get rid of the SetScaleCompressed... I didn't know I can put regular java stuff like try catch. Cool, let me try that. thx
profile picture

Eugene

#21
Before you try it out, what about "Moving Average Crossover" first?
profile picture

kelvinyip

#22
I used the out of the box "Moving Average Crossover" , I suppose that's the one.. and ran it on the 15 mins time frame with NSP added back into my daily and 15mins dataSets...

same error

12/27/2017 8:03:34 AM: Processing 2:1 Stock Split for NSP ...
12/27/2017 8:03:34 AM: Processing 2:1 Stock Split for NSP ...
12/27/2017 8:03:34 AM: Error(3): Object reference not set to an instance of an object.
12/27/2017 8:03:34 AM: Leaving Update Thread from catch
profile picture

Eugene

#23
Okay, as I told in post #11 we've deviated way too far from subject which is "Condition: split happened X bars ago". That task is done, and for the rest I've run out of my suggestions. Everything since post #8 is off topic so this is going to be my final reply here.

If this error negatively affects the processing of any Strategy running in the SM, please start a new topic for what seems to be a general SM issue and copy all relevant information including the logs, settings and procedure to reproduce. Thanks.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).