Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
conditional logic using a set of values as determinant
Updated October 5, 2009
Top Posters
looks_one
Saroj
with 5 posts (0 thanks)
looks_two
RJay
with 3 posts (2 thanks)
looks_3
Big Mike
with 1 posts (1 thanks)
looks_4
sefstrat
with 1 posts (1 thanks)
trending_up
2,536 views
thumb_up
4 thanks given
group
2 followers
forum
9 posts
attach_file
0 attachments
conditional logic using a set of values as determinant
October 5th, 2009, 07:03 AM
Arcata, CA
Experience: Intermediate
Platform: NinjaTrader
Trading: index futures, oil
Posts: 485 since Jun 2009
Thanks Given: 232
Thanks Received: 415
I've used languages in the past that allowed one to declare a set of values and then do an 'if' statement against that set... for example:
----------------------
procedure_A_ok = [1, 2, 9];
procedure_B_ok = [2, 3, 9];
v1 = 2
If (v1 == procedure_A_ok) Print ("procedure_A_ok");
------------------------
Output window:
procedure_A_ok
Is this construct available in NS/C# ? I couldn't find anything similar in the User doc... but it could be because I don't know what it is called... I did find the multiple case / Switch logic, but I don't really want that.
Thanks!
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
October 5th, 2009, 08:40 AM
Hartford, CT. USA
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: RTY
Posts: 682 since Jun 2009
Thanks Given: 756
Thanks Received: 787
Saroj
I've used languages in the past that allowed one to declare a set of values and then do an 'if' statement against that set... for example:
----------------------
procedure_A_ok = [1, 2, 9];
procedure_B_ok = [2, 3, 9];
v1 = 2
If (v1 == procedure_A_ok) Print ("procedure_A_ok");
------------------------
Output window:
procedure_A_ok
Is this construct available in NS/C# ? I couldn't find anything similar in the User doc... but it could be because I don't know what it is called... I did find the multiple case / Switch logic, but I don't really want that.
Thanks!
Hi Saroj,
I would do something like this,
if (variable1==1 && variable2==2 && variable3==9)v1 == procedure_A_ok;
RJay
October 5th, 2009, 08:43 AM
Manta, Ecuador
Site Administrator Developer Swing Trader
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,396 since Jun 2009
Thanks Given: 33,172
Thanks Received: 101,532
I would use an array or list and check to see if the value exists in the array.
This is from one of my strategies.
Code
private double NearestAbove () { double _retval = 0 ; double [] _array = { N28 [ 0 ], N18 [ 0 ], N08 [ 0 ], P18 [ 0 ], P28 [ 0 ], P38 [ 0 ], P48 [ 0 ], P58 [ 0 ], P68 [ 0 ], P78 [ 0 ], P88 [ 0 ], PP18 [ 0 ], PP28 [ 0 ]}; if ( _array [ 0 ] > 0 ) _retval = _array [ 0 ]; else return 0 ; for ( int x = _array . Length ; x > 0 ; x --) { //Print("Above: x - 1 =" + (x-1).ToString() + ", _array = " + _array[x-1]); if ( _array [ x - 1 ] > Close [ 0 ]) _retval = _array [ x - 1 ]; }
Mike
October 5th, 2009, 08:53 AM
Hartford, CT. USA
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: RTY
Posts: 682 since Jun 2009
Thanks Given: 756
Thanks Received: 787
Big Mike
I would use an array or list and check to see if the value exists in the array.
This is from one of my strategies.
Code
private double NearestAbove () { double _retval = 0 ; double [] _array = { N28 [ 0 ], N18 [ 0 ], N08 [ 0 ], P18 [ 0 ], P28 [ 0 ], P38 [ 0 ], P48 [ 0 ], P58 [ 0 ], P68 [ 0 ], P78 [ 0 ], P88 [ 0 ], PP18 [ 0 ], PP28 [ 0 ]}; if ( _array [ 0 ] > 0 ) _retval = _array [ 0 ]; else return 0 ; for ( int x = _array . Length ; x > 0 ; x --) { //Print("Above: x - 1 =" + (x-1).ToString() + ", _array = " + _array[x-1]); if ( _array [ x - 1 ] > Close [ 0 ]) _retval = _array [ x - 1 ]; }
Mike
The difference between a real programmer and a guy like me who counts on his fingers.
October 5th, 2009, 09:18 AM
Arcata, CA
Experience: Intermediate
Platform: NinjaTrader
Trading: index futures, oil
Posts: 485 since Jun 2009
Thanks Given: 232
Thanks Received: 415
RJay
Hi Saroj,
I would do something like this,
if (variable1==1 && variable2==2 && variable3==9)v1 == procedure_A_ok;
RJay
Thanks, RJay...that's basically what I'm doing except "or" instead of "and"
October 5th, 2009, 09:19 AM
Arcata, CA
Experience: Intermediate
Platform: NinjaTrader
Trading: index futures, oil
Posts: 485 since Jun 2009
Thanks Given: 232
Thanks Received: 415
Big Mike
I would use an array or list and check to see if the value exists in the array.
This is from one of my strategies.
Code
private double NearestAbove () { double _retval = 0 ; double [] _array = { N28 [ 0 ], N18 [ 0 ], N08 [ 0 ], P18 [ 0 ], P28 [ 0 ], P38 [ 0 ], P48 [ 0 ], P58 [ 0 ], P68 [ 0 ], P78 [ 0 ], P88 [ 0 ], PP18 [ 0 ], PP28 [ 0 ]}; if ( _array [ 0 ] > 0 ) _retval = _array [ 0 ]; else return 0 ; for ( int x = _array . Length ; x > 0 ; x --) { //Print("Above: x - 1 =" + (x-1).ToString() + ", _array = " + _array[x-1]); if ( _array [ x - 1 ] > Close [ 0 ]) _retval = _array [ x - 1 ]; }
Mike
Thanks, Mike... that looks good... another code snippet!
October 5th, 2009, 09:20 AM
Arcata, CA
Experience: Intermediate
Platform: NinjaTrader
Trading: index futures, oil
Posts: 485 since Jun 2009
Thanks Given: 232
Thanks Received: 415
RJay
The difference between a real programmer and a guy like me who counts on his fingers.
LOL... know exactly how you feel.. my problem is that I've used so many different languages in the past... hard to keep straight which is which...
October 5th, 2009, 09:25 AM
Hartford, CT. USA
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: RTY
Posts: 682 since Jun 2009
Thanks Given: 756
Thanks Received: 787
Saroj
Thanks, RJay...that's basically what I'm doing except "or" instead of "and"
if (variable1==1 || variable2==2 || variable3==9)v1 == procedure_A_ok;
October 5th, 2009, 09:42 AM
Austin, TX
Experience: Advanced
Platform: NT/Matlab
Broker: Interactive Brokers
Trading: FX majors
Posts: 285 since Jun 2009
Thanks Given: 20
Thanks Received: 768
In .net 3.5 you can do this much more elegantly using linq.. too bad we can't use .net 3.5 until the NT7 beta is ready probably in the next year or two
October 5th, 2009, 10:30 AM
Arcata, CA
Experience: Intermediate
Platform: NinjaTrader
Trading: index futures, oil
Posts: 485 since Jun 2009
Thanks Given: 232
Thanks Received: 415
sefstrat
In .net 3.5 you can do this much more elegantly using linq.. too bad we can't use .net 3.5 until the NT7
beta is ready probably in the next year or two
hopefully by that time, I'll have a clue about utilizing .net 3.5 or .net anything for that matter..
Last Updated on October 5, 2009