How to create a new Bars object with value = Nothing?
Author: hlh
Creation Date: 12/13/2010 1:26 PM
profile picture

hlh

#1
Hi,

being new to C# (and still using WL4 for most of my trading) I run into a simple problem for any basic programmer:

Trying to get an external symbol (VIX) from several sources in case one does not update I tried to code the following:

CODE:
Please log in to see this code.


I am trying to create this vix Bars object and don't know how to create a new (Bars) object in WL6/C# with the value Nothing (you see I am coming from VB.NET, and even there objects and stuff are challenging for me). Because when I tried to create it in the if {} with 'Bars vix = GetExternal... ' it did not work either as I then got an error 'vix not declared' in my last line 'DataSeries vixSMA ...' (so I assumed this was because it is behind/inside this if block?).

Thank you!
profile picture

Cone

#2
That's right. The compiler keeps track of the scope of the variable. If declared in a block then it's scoped for that block and blocks within that block.
profile picture

Eugene

#3
The problem is that the variable hasn't been initialized but the code is trying to use it. You need to assign a value directly, or use the new keyword to instantiate a new Bars object. Also, using a switch/case block could help get it more organized:
CODE:
Please log in to see this code.
profile picture

hlh

#4
Very cool, thank you!

Great to know how to only instantiate a new Bars object, and of course the switch/case looks more elegant.

One thing I don't understand is your remark:
// Calculate stop value using the Symbol Info Manager data (must be entered)

Thanks
profile picture

Eugene

#5
Oh that. Disregard it. It was a copy/paste error :)
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).