NexusFi: Find Your Edge


Home Menu

 





routine for getting range statistics


Discussion in NinjaTrader

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




 
Search this Thread

routine for getting range statistics

  #1 (permalink)
 zeller4 
Orlando Florida
 
Experience: Intermediate
Platform: NT8
Trading: CL, NQ, ES, RTY
Posts: 477 since Jun 2009
Thanks Given: 1,416
Thanks Received: 404

Hey BigMike and all you other programmers!

Thanks Mike for a great site!

I'm advancing my understanding of C# - currently going through C#2008 For Dummies.
I'm attempting to see what the hourly or daily range (or whatever variable time I want) is over a certain quantity of bars so I can apply a moving average and review other statistics. I've finally figured out how to get a barcount for the session using the following(in the OnBarUpdate section):
 
Code
if (Bars.FirstBarOfSession)
{ // first bar initialization

barCount = 0;
return;
}
 
for (int i = 0; i < 1; i++)
{
if (FirstTickOfBar)
{
barCount++;// = barCount+1;
}
 
}
Now, i'm trying to use this barcount with the range per bar and I'm not sure how to use this barcount with the following or similar to get the array and average range.
 
Code
double range = High[s] - Low[s];
Eventually, I'm going to attempt getting statistics with results similar to the following:
(these are examples only!)
1. for CL, the average daily range is 52 ticks
2. for CL on Tuesday during 9am-10am, the average hourly range is 35 ticks
3. for CL on Tuesday during 11am-12am, the average hourly range is 7 ticks

I know I need some "data holders" such that the range data gets plugged into the right location - "like colored marbles in the correct sack"


any help or direction anyone could give is much appreciated. Any code snippets would be welcome.
thanks,
Kirk

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
MC PL editor upgrade
MultiCharts
Trade idea based off three indicators.
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Better Renko Gaps
The Elite Circle
 
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
Bigger Wins or Fewer Losses?
24 thanks
Tao te Trade: way of the WLD
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
  #2 (permalink)
 
Big Mike's Avatar
 Big Mike 
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,446 since Jun 2009
Thanks Given: 33,217
Thanks Received: 101,610

Hmm.

Well first, there is CurrentBar and Bars.Count. No need to do your own barcount variable from my understanding of what you want.

If you want to use High - Low as a dataseries, instead of Close for instance, create a new dataseries like so:

#var
private DataSeries hl;

#init
hl = new DataSeries(this);

#onbarupdate
hl.Set(High[0] - Low[0]);

Then you can pass that dataseries to your indicator, like if you want an SMA of the high low, it would be

double _smahl = SMA(hl, 10)[0];

If you are trying to get the range of a period of bars, try using HighestBar and LowestBar, it returns the bar number within a certain period that was the Highest or Lowest. Then you can use that Bar # and lookback at it for more info, like:

double _highestbar = HighestBar(10);

Print(Time[0] + ": the highest bar was " + _highestbar + " bars ago, with a value of " + High[_highestbar]);

You can also use MIN and MAX, but be careful using them over large dataseries, they are a real performance drag.

If you want to limit your lookback period to just today, use Bars.BarsSinceSession.

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 Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #3 (permalink)
 
Big Mike's Avatar
 Big Mike 
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,446 since Jun 2009
Thanks Given: 33,217
Thanks Received: 101,610


Ok either you added some new stuff to your post or I missed the bottom part before I replied. Probably my bad, been a rough week for me

For ATR stuff, you can do a few things. First if you can't use a real daily chart, you can use a 1440m chart. But I would focus on just the cash session if it were me, so I would treat your "daily" request similar to your 9am-10am request and be specific with the time frame, instead of using a 24 hour clock.

Time[0] is your friend. Just use it to figure out what time it is. That way one script can handle multiple requests, like the 'daily' request, the 9am-10am, etc.

GetBar() is your friend, too. You can tell it to look at a specific time frame. This will help you narrow down what bar has happened at 9am, and what bar number ended at 10am. Then use those two bar numbers and a combination of MIN or MAX, or even HighestBar or LowestBar depending on when you're calling them, to get your high and low range.

Sorry, no time to give you more than this right now.

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 Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 zeller4 
Orlando Florida
 
Experience: Intermediate
Platform: NT8
Trading: CL, NQ, ES, RTY
Posts: 477 since Jun 2009
Thanks Given: 1,416
Thanks Received: 404

that's okay,
yes i thought there were a couple points you didn't address in that first post.
hope your week is better (and mine too - didn't even get to open NT today - having a withdrawal or tantrum lol)

the only reason i'm using daily now is so i can easily count the bars in the group, then, i'll start enlarging the pool and explore other details

I appreciate about the Bars.Count. The setup of an array with the possible plot to a screen text grid is where i'm eventually headed.

There's some value in getting the current picture of where we are in relation to a "normal" day. ie on high-end of the typical range, on a low-range or narrow day, within 5 ticks of the bottom of the range and below the open, etc. there's a screenshot of some data coming back to the chart to update in realtime.

2009-10-15_1520

appreciate the help.
kz

Started this thread Reply With Quote




Last Updated on October 15, 2009


© 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