NexusFi: Find Your Edge


Home Menu

 





"OR" clause in NT strategy?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Cachevary with 4 posts (0 thanks)
    2. looks_two shodson with 3 posts (6 thanks)
    3. looks_3 hawks67 with 2 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 1,495 views
    2. thumb_up 6 thanks given
    3. group 3 followers
    1. forum 9 posts
    2. attach_file 1 attachments




 
Search this Thread

"OR" clause in NT strategy?

  #1 (permalink)
 hawks67 
Chicago, IL
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AGN/Rithmic
Trading: CL
Posts: 22 since Apr 2010
Thanks Given: 14
Thanks Received: 2

OK, this could just be me losing my mind...it's been a while since I donned my programmer's cap, and I just can't remember....

I am coding a strategy and one of my conditions really wants an OR clause:

"if the Stoch is here and either this CCI is here or this one is, then do this."

 
Code
if
((Stochastics(7, 14, 3).K[2] > 80)
&&
((CCI(3)[2] > 95) OR (CCI(3)[3] > 95)))
{ action };
(not my exact code, just a simplified example of what I'm trying to do)

But, of course, NT7 doesn't like that. It doesn't like anything close to that.

Is there a form of an OR clause? You know, like one that serves as the partner/opposite of the && clause? I'm kind of starting to use a bunch of nested if/else statements in place of a simple OR, but it's getting very messy...

Thanks in advance,
Gary

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
NexusFi Journal Challenge - May 2024
Feedback and Announcements
REcommedations for programming help
Sierra Chart
How to apply profiles
Traders Hideout
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
48 thanks
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
  #3 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709


In C#

&& = "and"
|| = "or"

|| Operator (C# Reference)

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 hawks67 
Chicago, IL
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AGN/Rithmic
Trading: CL
Posts: 22 since Apr 2010
Thanks Given: 14
Thanks Received: 2

YES! Thank you! Either mybrain.full or mybrain.old.

Started this thread Reply With Quote
  #5 (permalink)
 
Cachevary's Avatar
 Cachevary 
Russia,Khabarovsk
 
Experience: Beginner
Platform: NT
Trading: Gold
Posts: 407 since Feb 2014


shodson View Post
In C#

&& = "and"
|| = "or"

|| Operator (C# Reference)

@shodson,

Hello,

i`m also struggling to buils conditions using || operator.

I have this line to begin with:

 
Code
(this.super.Values[0][1] == this.super.Values[3][1] || this.super.Values[1][1] == this.super.Values[3][1] || this.super.Values[2][1] == this.super.Values[3][1])
that one i need for the Bar[1] to compare the equality of either of two :

this.super.Values[0][1]

this.super.Values[1][1]

this.super.Values[2][1]


to this one:

this.super.Values[3][1]


Now for the Bar[0] i need to know which set was greater or less(< or >) to the this.super.Values[3][1]


I try this:

&& this.super.Values[3][0] > (this.super.Values[0][0] || this.super.Values[0][1] || this.super.Values[0][2])

But,get compile error that says "Operator || cannot be applied to ''double"....

Can you please suggets a corrcet way to get those conditions,please?

Reply With Quote
  #6 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709

|| is a boolean operator. It ORs two boolean expressions like true OR false OR true

you have align your logic into boolean expressions and to think of it like this:

 
Code
the sky is white OR the sky is blue OR the sky is black
not

 
Code
the sky is (white OR blue OR black)
because the things between the ORs are not boolean expressions, they are colors

so what you need to do is

 
Code
&& (this.super.Values[3][0] > this.super.Values[0][0] ||
    this.super.Values[3][0] > this.super.Values[0][1] ||
    this.super.Values[3][0] > this.super.Values[0][2])

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #7 (permalink)
 
Cachevary's Avatar
 Cachevary 
Russia,Khabarovsk
 
Experience: Beginner
Platform: NT
Trading: Gold
Posts: 407 since Feb 2014


shodson View Post
|| is a boolean operator. It ORs two boolean expressions like true OR false OR true

you have align your logic into boolean expressions and to think of it like this:

 
Code
the sky is white OR the sky is blue OR the sky is black
not

 
Code
the sky is (white OR blue OR black)
because the things between the ORs are not boolean expressions, they are colors

so what you need to do is

 
Code
&& (this.super.Values[3][0] > this.super.Values[0][0] ||
    this.super.Values[3][0] > this.super.Values[0][1] ||
    this.super.Values[3][0] > this.super.Values[0][2])

Seems working that way.

Thank you,sir!Appreciate your help and effort.

Have a fantastic weekend!

Reply With Quote
  #8 (permalink)
 
Cachevary's Avatar
 Cachevary 
Russia,Khabarovsk
 
Experience: Beginner
Platform: NT
Trading: Gold
Posts: 407 since Feb 2014

@shodson,

a little problem here.

Now that i have those conditions for the entry in place:

 
Code
If (this.super.Values[0][1] == this.super.Values[3][1] || this.super.Values[1][1] == this.super.Values[3][1] || this.super.Values[2][1] == this.super.Values[3][1])

&& (this.super.Values[3][0] > this.super.Values[0][0] ||  this.super.Values[3][0] > this.super.Values[0][1] || this.super.Values[3][0] > this.super.Values[0][2])
i often have the issue,depicted on the image attached.Could you please take a look and suggest what is happening?

Thank you!

Attached Thumbnails
Click image for larger version

Name:	Entry issue.png
Views:	99
Size:	73.9 KB
ID:	172651  
Reply With Quote
  #9 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709

It's hard for me to say what's wrong without seeing the entire code and knowing what the rules of the strategy are. I suggest you look for more significant help here or here. You really need more Ninjascript/C# programming training and experience.

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #10 (permalink)
 
Cachevary's Avatar
 Cachevary 
Russia,Khabarovsk
 
Experience: Beginner
Platform: NT
Trading: Gold
Posts: 407 since Feb 2014



shodson View Post
|| is a boolean operator. It ORs two boolean expressions like true OR false OR true

you have align your logic into boolean expressions and to think of it like this:

 
Code
the sky is white OR the sky is blue OR the sky is black
not

 
Code
the sky is (white OR blue OR black)
because the things between the ORs are not boolean expressions, they are colors

so what you need to do is

 
Code
&& (this.super.Values[3][0] > this.super.Values[0][0] ||
    this.super.Values[3][0] > this.super.Values[0][1] ||
    this.super.Values[3][0] > this.super.Values[0][2])

@shodson,

and yet,it`s still not what i wanted.Sorry if i didn`t put it clear.

For the Bar[0], i need EXACTLY the comparison - <or> ,for the this.super.Values[3][0] and the ONE,that this exact this.super.Values[3][0] was matched at the Bar[1].For now,the conditions you`ve added just do an arbitrary comparison - which one is grater/lesser another,not for the particular set.

Reply With Quote




Last Updated on January 22, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts