NexusFi: Find Your Edge


Home Menu

 





Embarrassed at the simplicity, but I don't get it - C# basic syntax


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Crassius with 2 posts (0 thanks)
    2. looks_two sam028 with 1 posts (2 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 Big Mike with 1 posts (1 thanks)
    1. trending_up 3,702 views
    2. thumb_up 5 thanks given
    3. group 2 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 
Crassius's Avatar
 Crassius 
Shenandoah Valley, VA
 
Experience: Advanced
Platform: NT8
Broker: NinjaTrader introduced to Dorman
Trading: ES, CL, 6E, ZN
Posts: 14 since Jan 2011
Thanks Given: 5
Thanks Received: 3

At best I'm teaching myself a little programming by hacking away building indicators, but basically, I'm stumble around trying different things till something works.

I have looked through google etc, and I don't understand why this statement doesn't work.... I must be missing something so basic none of the articles I have read have helped me figure out what is wrong, and why what looks perfectly logical to me just won't compile.

I want to execute a series of statements only if the current bar is within a certain range... this comes up alot when initializing indicators.... so in my ignorance, I write..

if ( CurrentBar >=5 & <=7 )
{
statement
}

Would some kind soul explain to me why that doesn't work, and what I should use instead?


Follow me on X Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
requesting .nrd replay files from 2026 spy and qqq
The Elite Circle
Bitcoin’s 2022 low, 2025 high and 2026 low so far arou …
Cryptocurrency
My Rant with AMP Futures
Trading Reviews and Vendors
Building a free browser DOM/SMC simulator - need some ad …
Platforms and Indicators
AI for Traders — Agents, Memory, Tools & Real-Worl …
Elite Quantitative GenAI/LLM
 
  #3 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,581 since Oct 2009
Thanks Given: 4,267
Thanks Received: 6,212


Have you tried by simply repeating the variable name 'CurrentBar':

if ( CurrentBar >=5 & CurrentBar <=7 )
{
statement
}

Also, i think you need to double the & operator like this : &&

So your instructions should go like this:
if ( CurrentBar >=5 && CurrentBar <=7 )
{
statement
}

In short, you double everything as the computer is dumb and we need to repeat everything twice ;-)


Reply With Quote
Thanked by:
  #4 (permalink)
 
sam028's Avatar
 sam028 
Site Administrator
 
Posts: 3,779 since Jun 2009
Thanks Given: 3,840
Thanks Received: 4,709

It's more
 
Code
                            
if ( CurrentBar>=5 && CurrentBar<=7 )
{
statement
} 


Success requires no deodorant! (Sun Tzu)
Reply With Quote
Thanked by:
  #5 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 R.I.P. 1977-2026 
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,669 since Jun 2009
Thanks Given: 33,669
Thanks Received: 102,599

Join us tomorrow for a webinar on NinjaScript:


Mike




We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on X Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #6 (permalink)
 
Crassius's Avatar
 Crassius 
Shenandoah Valley, VA
 
Experience: Advanced
Platform: NT8
Broker: NinjaTrader introduced to Dorman
Trading: ES, CL, 6E, ZN
Posts: 14 since Jan 2011
Thanks Given: 5
Thanks Received: 3

Many thanks...


Follow me on X Started this thread Reply With Quote




Last Updated on February 22, 2011


© 2026 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 - Downloads - Top
no new posts