Bar Score Over N Bars; Array Question - NinjaTrader Programming | futures io social day trading
futures io futures trading


Bar Score Over N Bars; Array Question
Updated: Views / Replies:1,273 / 8
Created: by aventeren Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

Bar Score Over N Bars; Array Question

  #1 (permalink)
Patient Discipline
Bellingham, WA USA
 
Futures Experience: Beginner
Platform: NT
Broker/Data: Mirus (Broker), Continuum (Data), Dorman (Clearing)
Favorite Futures: Futures
 
aventeren's Avatar
 
Posts: 202 since Mar 2013
Thanks: 426 given, 191 received

Bar Score Over N Bars; Array Question

Howdy--

I have created an indicator that assigns each bar a unique 0, 1 or 2 "score" based on a series of logic conditions. This piece is working fine.

I then wanted to create a running "score" of the unique bar "scores" over the previous n bars. To do this, I figured that creating an array to hold each bar's score would be best, as the size of the array could be limited with a parameter (ie, 10 bars, 50 bars, 100 bars, etc). I then wanted to sum this array values to create the score. But before I could get to summing the array values, I ran into a challenge associated with how to add and keep array values. Here is what I have so far:

//Variables
private int[] array; // creates int array of undefined size and without values
private int arraysize = 50; // variable to define how many values the array will hold (50 bars in this case)

//Initialize()
array = new int[arraysize]; // I initialized my int type array with a size of arraysize (50 in this case)

//OnBarUpdate()
array[0] = barvalue; // barvalue is the generic name I'm using to populate the array's current [0] value with either a 0, 1 or 2

I then used DrawText printed above the current bar to confirm that the barvalue and array[0] values were correct (they were). So what that meant to me is that I was correctly assigning the barvalue into the array's top position.

I then used DrawText to confirm that the array was correctly storing the array[1] values, too--but the array[1] value is always 0.

What am I missing about arrays that will not allow my array to keep values that I assigned to it on the previous bar? Why can't I access the array[1] values that had previously been assigned? Why is the array[1] value being reset to 0?

After I get the array to properly hold values, I'll then need to figure out how to sum the values in the array.

Thanks for your help!

Aventeren

Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Patient Discipline
Bellingham, WA USA
 
Futures Experience: Beginner
Platform: NT
Broker/Data: Mirus (Broker), Continuum (Data), Dorman (Clearing)
Favorite Futures: Futures
 
aventeren's Avatar
 
Posts: 202 since Mar 2013
Thanks: 426 given, 191 received

Alternative DataSeries Approach?


I've been thinking about this, and maybe I could also use a DataSeries to store the barvalue numbers, but if I were to do this, I'm not sure how I would sum the barvalues from N bars ago.

But before I get to the DataSeries summing part, would this be the correct way to implement and get the barvalues to the DataSeries?

//Variables
private DataSeries series; // Creates new DataSeries

//Initialize()
series = new DataSeries;

//OnBarUpdate()
series[0] = barvalue; // Populate the current series slot with the barvalue

Would this be a start?

Reply With Quote
 
  #4 (permalink)
Elite Member
las vegas
 
Futures Experience: Intermediate
Platform: Sierra Chart
Broker/Data: Velocity/IB
Favorite Futures: 6E
 
Posts: 1,147 since Feb 2010
Thanks: 304 given, 836 received

Isn't there a sum function you can use?

Reply With Quote
The following user says Thank You to vegasfoster for this post:
 
  #5 (permalink)
Patient Discipline
Bellingham, WA USA
 
Futures Experience: Beginner
Platform: NT
Broker/Data: Mirus (Broker), Continuum (Data), Dorman (Clearing)
Favorite Futures: Futures
 
aventeren's Avatar
 
Posts: 202 since Mar 2013
Thanks: 426 given, 191 received


vegasfoster View Post
Isn't there a sum function you can use?

So I think shifting to a DataSeries approach might be best, because each bar will have a unique score attached to it.

The summing challenge is how to sum over a specified number of N bars. That's the piece I'm confused on.

Any thoughts?

Reply With Quote
 
  #6 (permalink)
 Vendor: www.traderwerks.com 
Taipei Taiwan
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: Optimus
Favorite Futures: TW
 
Posts: 693 since Jun 2009
Thanks: 440 given, 440 received


aventeren View Post
So I think shifting to a DataSeries approach might be best, because each bar will have a unique score attached to it.

The summing challenge is how to sum over a specified number of N bars. That's the piece I'm confused on.

Any thoughts?


Summation (SUM)

Math. A gateway drug to reality.
Reply With Quote
The following user says Thank You to traderwerks for this post:
 
  #7 (permalink)
Elite Member
las vegas
 
Futures Experience: Intermediate
Platform: Sierra Chart
Broker/Data: Velocity/IB
Favorite Futures: 6E
 
Posts: 1,147 since Feb 2010
Thanks: 304 given, 836 received

Yes, you will need to create a dataseries then use the sum function to get the totals.

Just a thought, but you may look at analyzing negative and positive values separately and/or calculating a ratio of the two, then each dataseries would be something like,

dataseriespositive = Close[0]>Open[0] ? Calculation : null;
dataseriesnegative = Close[0]<Open[0] ? Calculation : null;

Now go make us rich!

Reply With Quote
The following user says Thank You to vegasfoster for this post:
 
  #8 (permalink)
Patient Discipline
Bellingham, WA USA
 
Futures Experience: Beginner
Platform: NT
Broker/Data: Mirus (Broker), Continuum (Data), Dorman (Clearing)
Favorite Futures: Futures
 
aventeren's Avatar
 
Posts: 202 since Mar 2013
Thanks: 426 given, 191 received

Got the DataSeries to Work; Now How to Plot?


traderwerks View Post

So I got this figured out how to use a DataSeries. Here is the code I used:

//Variables
private DataSeries series;
private int sumlength = 10; // Defines how many bars I want in my sum (10 in this case)
private double seriessum; // This is the variable that will hold the sum IT HAS TO BE TYPE DOUBLE BC IT WILL BE HOLDING A DATASERIES!!!

//Initialize()
series = new DataSeries(this); // Need to initialize the DataSeries

// OnBarUpDate()
series.Set(barscore); // Use .Set(variable) to populate the DataSeries (barscore is the score value assigned to each bar)
seriessum = SUM(series, sumlength)[0]; // This is how you sum the score over sumlength bars (10 in this case) IT IS IMPORTANT TO ADD ON THE [0] AFTER THE SUM()...So Don't forget!!!!

So with the above, I am able to sum my bar scores of N bars.

My next challenge is going to be plotting these values. Do make the seriessum values publicly available, in Properties I used a:

[Browsable(false)]
[XmlIgnore()]
public double Seriessum
{
get { return seriessum; }
}

The above should make the Seriessum values available for use in another indicator.

So I created a new indicator, add referenced the IndicatorName (generic name) in the new indicator--and added in a new Plot.

//Initialize()
Add(IndicatorName(parameter1, parameter2, etc)); // Adds the IndicatorName to the new indicator so that I can grab the public values.

// OnBarUpdate()
Add(new Plot(Color.Green, "seriessum"); // From what I understand, this defines the plot for Values[0]

Okay, so I think the above is right. Next, how to I actually plot the scores in this indicator?

Thanks! I REALLY appreciate your help.

Aventeren

Reply With Quote
 
  #9 (permalink)
 Vendor: www.probabletrades.com 
OC, California, USA
 
Futures Experience: Advanced
Platform: IB/TWS, NinjaTrader, thinkorswim
Favorite Futures: stocks, options, futures, VIX
 
shodson's Avatar
 
Posts: 1,859 since Jun 2009
Thanks: 480 given, 3,254 received

LINQ and generic collections make this easier.

in the "using" section up top, include these statements

 
Code
using System.Collections;
using System.Collections.Generic;
using System.Linq;
declare a class-level sorted list to store your scores

 
Code
SortedList<DateTime, int> _scores = null;
then in OnBarUpdate()

 
Code
if (_scores == null)
    _scores = new SortedList<DateTime, int>();
compute your score and add it to the sorted list, using the time of the bar as your index by which it will keep the list sorted

 
Code
int score = {0, 1 or 2, whatever logic you use to compute the score}
_scores.Add(Time[0], score);
To ensure the list has no more than the last n values, just remove the first one (the oldest one)

 
Code
if (_scores.Count > n)
    _scores.RemoveAt(0);
Then you can use LINQ to average all of the values in the list

 
Code
double average = _scores.Values.Average();

Here's a sample I wrote in Visual Studio which demonstrates this.

 
Code
SortedList<DateTime,int> list = new SortedList<DateTime,int>();
list.Add(new DateTime(2000,1,1), 1);
list.Add(new DateTime(2000,1,2), 0);
list.Add(new DateTime(2000,1,3), 2);

double avg = list.Values.Average();    // =1.0

list.RemoveAt(0);                      // removes the "1", list now has the "0" and "2"
list.Add(new DateTime(2000,1,4), 2);   // list is now 0,2,2

avg = list.Values.Average();           // = 1.333


Last edited by shodson; June 21st, 2013 at 03:20 PM.
Reply With Quote
The following 4 users say Thank You to shodson for this post:

Reply



futures io > > > > > Bar Score Over N Bars; Array Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Numbers Bars bar statistic slickiam Sierra Chart 4 February 24th, 2014 06:23 AM
A question about Range Bars rcabri Traders Hideout 5 March 18th, 2011 03:04 PM
Can bars be 'colored' by another bar state? Trader.Jon NinjaTrader Programming 8 August 13th, 2010 05:19 PM
SBS RENKO BARS - question Eric j Traders Hideout 2 November 18th, 2009 07:21 AM
Question about Range Bars Hapster Traders Hideout 2 November 4th, 2009 08:47 PM


All times are GMT -4. The time now is 05:49 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-12 in 0.12 seconds with 19 queries on phoenix via your IP 54.167.44.32