LowestBar and HighestBar return incompatible type
Author: sourkraut
Creation Date: 7/31/2013 9:22 PM
profile picture

sourkraut

#1
I get errors from the following code, if I try to make the "barToo" an int type.
I would have thought the purpose of the subject indicators are, to discover a bar number, so one can retrieve other values associated with that bar.

However, C# will not convert FROM double TO int.

CODE:
Please log in to see this code.


The above debug statement returned
CODE:
Please log in to see this code.

on July 30, 2013, when run on AAPL stock.

Clearly the numbers match, but the types don't.
Am I missing something?

TIA


Eb
profile picture

streak

#2
With the cursor after LowestBar.Value use Ctrl+Sft+Space. It shows up as type double.

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

Eugene

#3
Also in its online documentation, LowestBar:

CODE:
Please log in to see this code.


QUOTE:
However, C# will not convert FROM double TO int.


A double can not be equal to integer without converting with Convert.ToInt32 (and rounding) or casting with (int) (and truncating) first because a double may contain a floating point value.
profile picture

sourkraut

#4
Thanks, the link http://www2.wealth-lab.com/WL5WIKI/LowestBar.ashx implies, that

CODE:
Please log in to see this code.


will give me an int keyBar.

I'll try this asap.

Eb
profile picture

Eugene

#5
Eb, this is not going to work. Just follow streak's suggestion.
profile picture

sourkraut

#6
With a slight modification, it did work:

CODE:
Please log in to see this code.


However, Streak's code:

CODE:
Please log in to see this code.


generates a compile error, that you cannot cast a double to int,


Eb

profile picture

Eugene

#7
QUOTE:
generates a compile error, that you cannot cast a double to int,


Not at all. No compile error in 6.5. (Actually, even a possible difference in installed .NET framework versions couldn't explain that.) streak's statement is perfectly valid from syntax standpoint.
profile picture

sourkraut

#8
Sorry, you are right. I had not tested that approach in 6.5 yet. Only upgraded from 6.4? yesterday.

profile picture

sourkraut

#9
Streak, your suggestion works after all.
I have no idea what caused the compile error. Though sometimes I get gremlins in the editor, that disappear, if I close and reload the strategy.

Thank you.


As to why a bar number is returned as a double, I will refrain from compllaining about it, to avoid distraction from my many other complaints.
profile picture

streak

#10
Probably just that, I think, all dataseries objects are of type double (could be very awkward if there was a mix).
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).