NexusFi: Find Your Edge


Home Menu

 





Need confirmation of NT code please


Discussion in NinjaTrader

Updated
    1. trending_up 2,771 views
    2. thumb_up 3 thanks given
    3. group 1 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 
Saroj's Avatar
 Saroj 
Arcata, CA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: index futures, oil
Posts: 482 since Jun 2009
Thanks Given: 232
Thanks Received: 416

Here's some code in an indicator that I am trying to understand (Cycle_Identifier):
============================================
int rnglength = 250;
// pLength is set to 3

double range = 0.0, srange = 0.0;
int j=0;
for (int i=0;i<rnglength;i++) {
if(i>=CurrentBar) break;
j++;
srange = srange + (High[i] - Low[i]);
}
range = srange / j * pLength;
====================================================

1) Looks to me like for each bar, the indicator is recalculation for the last 250 bars, the cumulative bar range (H - L) / 750

Is that right?

2) the code tests to be sure there are at least 250 bars on chart
(if(CurrentBar<rnglength) return; ),
so why is "if(i>=CurrentBar) break;" necessary?


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Topstep Acquires The Futures Desk -- Prop Firm Consolida …
Funded Trading Evaluation Firms
Iran Update May 8: Still Reviewing MOU, Demands Reparati …
Traders Hideout
The May 31 Binary: 60% Trump Declares Iran Ops Over, Onl …
Prediction Markets & Event Contracts
February NFP Preview -- Why This Mornings Jobs Number Co …
Traders Hideout
Kharg Island at 6%, Regime Fall at 1.5% -- The Black Swa …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
23 thanks
2026 Jlab journal
10 thanks
Trying to learn Volume and price action correlation
7 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
  #2 (permalink)
 
cory's Avatar
 cory 
virginia
the coin hunter
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,093

1) it calculates average range of the last 250 bars x 3;
2) my guess is code blew up when bar < 250
then other code was put in to fix that error but the old code didn't get taken out.


Reply With Quote
Thanked by:
  #3 (permalink)
 
RJay's Avatar
 RJay 
Hartford, CT. USA
 Vendor: www.innovative-trading-solutions-online.com 
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: ES
Posts: 687 since Jun 2009
Thanks Given: 765
Thanks Received: 789



Saroj View Post
Here's some code in an indicator that I am trying to understand (Cycle_Identifier):
============================================
int rnglength = 250;
// pLength is set to 3

double range = 0.0, srange = 0.0;
int j=0;
for (int i=0;i<rnglength;i++) {
if(i>=CurrentBar) break;
j++;
srange = srange + (High[i] - Low[i]);
}
range = srange / j * pLength;
====================================================

1) Looks to me like for each bar, the indicator is recalculation for the last 250 bars, the cumulative bar range (H - L) / 750

Is that right?

2) the code tests to be sure there are at least 250 bars on chart
(if(CurrentBar<rnglength) return; ),
so why is "if(i>=CurrentBar) break;" necessary?

Saroj,

This should not be needed in the NT programming. ( My Opinion!!!)

Are the results the same with it commented out??

On another note, I have a big problem with the " range = " line..

---------------------------------------------------------------

range = srange / j * pLength;

--------------------------------------------------------------


Needs brackets above the multiplier or below the divisor?????

No exception for "j" or "pLength" being equal to zero.


RJay


Reply With Quote
Thanked by:
  #4 (permalink)
 
Saroj's Avatar
 Saroj 
Arcata, CA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: index futures, oil
Posts: 482 since Jun 2009
Thanks Given: 232
Thanks Received: 416

The formula should be "range = (srange / j) * pLength+.000001;" (which I have changed it to); or simply not allow a value of pLength = 0; it is initialized to '3' but user changeable.

however it strikes me as very inefficient. First off, for a range chart, it will remain virtually constant (esp across 250 bars); secondly, even on a tick, volume or minute bar, could one calculate srange by subtracting the value 250 bars ago and adding in the current value rather than summing 250 values on each bar?


Started this thread Reply With Quote
  #5 (permalink)
 
RJay's Avatar
 RJay 
Hartford, CT. USA
 Vendor: www.innovative-trading-solutions-online.com 
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: ES
Posts: 687 since Jun 2009
Thanks Given: 765
Thanks Received: 789


Saroj View Post
The formula should be "range = (srange / j) * pLength+.000001;" (which I have changed it to); or simply not allow a value of pLength = 0; it is initialized to '3' but user changeable.

however it strikes me as very inefficient. First off, for a range chart, it will remain virtually constant (esp across 250 bars); secondly, even on a tick, volume or minute bar, could one calculate srange by subtracting the value 250 bars ago and adding in the current value rather than summing 250 values on each bar?

Saroj,

Good luck with this!!

I have so much on my plate right now with my volume watch projects.

Maybe someone else could assist.

RJay


Reply With Quote




Last Updated on September 26, 2009


© 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