Need help understanding connections and relationships; simple conditional accumulator - NinjaTrader Programming | futures io social day trading
futures io futures trading


Need help understanding connections and relationships; simple conditional accumulator
Updated: Views / Replies:529 / 4
Created: by aventeren Attachments:1

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
 

Need help understanding connections and relationships; simple conditional accumulator

  #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

Need help understanding connections and relationships; simple conditional accumulator

Hello, I was curious if someone would be able to help me sort out a simple bit of code that I'm trying to code.

Goal: Calculate two moving averages, then calculate the slopes of those moving averages; if the slopes are less than a threshold assign a 0 value else 1; add the 1s and 0s; plot the result in a bar histogram to get an indication of whether your conditions were satisfied.

I'm getting wrapped around the axel how everything talks and communicates with everything (ie, doubles, arrays, DataSeries, Value.Set, Values[0], plots, etc). My head is spinning and I need help.

I guess that I'll have to start off step-wise by trying to confirm how all of the various inputs will need to talk and communicate with one another. Here are my assumptions:

1. In the Initialize() section, I need to add a new plot of the Accumulator, and I am assuming that I will add this plot via:

Add(new Plot(Color.Blue, PlotStyle.Bar, "Accumulator"));

and I am assuming that this bit of code now defines the plot for Values[0]...but I don't understand where to add values to Values[0].

2. In the OnBarUpdate() section, I need to have the:

if(CurrentBar < 1)
{
return;
}

but I am not sure why. I think this is because if there are not enough bars to do the math, that we just need to return nothing...as we don't have enough information yet. Is that correct?

3. Within the OnBarUpdate() section, I then have determined that I need to have a BarsInProgress sub-section where my magic is going to happen, and I am assuming that I will add this within the overall OnBarUpdate() section by adding in the code:

if(BarsInProgress == 1)
{
//magic
}

On to magic.

4. I have then determined, that within the BarsInProgress == 1 sub-section, that I need to have an additional section that looks at FirstTickOfBar. I have assumed that this is where I need to populate my EMA8 and EMA20 arrays. However, before populating my arrays, I needed to define them, so I defined them as:

private double[] = EMA8Array = new double[8];
private double[] = EMA20Array = new double[20];

Is that right? Do these arrays need to be defined with 8 and 20 spots--or will just 2 or another number suffice? I probably need a little help on why 8/20 versus something else.

I think I would then need to populate the EMA8Array via:

EMA8Array[8] = EMA8Array[7];
EMA8Array[7] = EMA8Array[6];
EMA8Array[6] = EMA8Array[5];
EMA8Array[5] = EMA8Array[4];
EMA8Array[4] = EMA8Array[3];
EMA8Array[3] = EMA8Array[2];
EMA8Array[2] = EMA8Array[1];
EMA8Array[1] = EMA8Array[0];

and I would populate the EMA20Array in a similar fashion:

EMA20Array[20] = EMA20Array[19];
EMA20Array[19] = EMA20Array[18];
EMA20Array[18] = EMA20Array[17];
EMA20Array[17] = EMA20Array[16];
EMA20Array[16] = EMA20Array[15];
EMA20Array[15] = EMA20Array[14];
EMA20Array[14] = EMA20Array[13];
EMA20Array[13] = EMA20Array[12];
EMA20Array[12] = EMA20Array[11];
EMA20Array[11] = EMA20Array[10];
EMA20Array[10] = EMA20Array[9];
EMA20Array[9] = EMA20Array[8];
EMA20Array[8] = EMA20Array[7];
EMA20Array[7] = EMA20Array[6];
EMA20Array[6] = EMA20Array[5];
EMA20Array[5] = EMA20Array[4];
EMA20Array[4] = EMA20Array[3];
EMA20Array[3] = EMA20Array[2];
EMA20Array[2] = EMA20Array[1];
EMA20Array[1] = EMA20Array[0];

Is the above necessary? Do I need to do this? Why or why not?

5. The next step would be to define variables for the moving averages. Let's assume that I am trying to calculate an EMA with a period of 8 based on closes and an EMA with a period of 20 based on the closes. Given that the moving averages will not be integers, I'm assuming that they will need to be type double (as opposed to type int) and that I will define them as

private double EMA8;
private double EMA20;

Is this correct?

6. The next step would be actually calculating the moving averages, but this is where I take a second wrap around the axel, as I am not sure if these should be defined as

EMA8 = EMA(Closes[1], 8);
EMA20 = EMA(Closes[1], 20);

or

EMA8 = EMA(Closes[1], 8).Value[0];
EMA20 = EMA(Closes[1], 20).Value[0];

If they should be defined using the .Value[0] code, I don't understand why. Maybe someone can help me?

7. The next step would then be to pass the EMA8 and EMA20 values into the arrays, and I think I would do this by:

EMA8Array[0] = EMA8;
EMA20Array[0] = EMA20;

Is this right?

8. Now for another turn around the axel: I have read that if you create a new DataSeries and that your chart has 200 bars, that the DataSeries will also have 200 values. So I created new DataSeries by:

private DataSeries EMA8Series;
private DataSeries EMA20Series;

I then think that I need to populate these DataSeries by:

EMA8Series[0] = EMA8Array[0];
EMA20Series[0] = EMA20Array[0];

But this is what is confusing to me, because I think of the arrays as holding values on a tick by tick basis (ie, what was the EMA value one tick ago) and the DataSeries as holding the EMA values that were in place when the previous bar closed. Is that right? How should I be thinking about how doubles talk to arrays talk to DataSeries? And how are tick movements intracandle different from differences between bars (ie, intercandle)? How should I be thinking about how these values are being stored? I'm really confused about this part, ie, intracandle vs. intercandle. I need help.

9. I then came across a bit of code that I need to set the DataSeries by:

EMA8Series.Set(1, EMA8Array[1]);
EMA8Series.Set(2, EMA8Array[2]);
EMA20Series.Set(1, EMA20Array[1]);
EMA20Series.Set(2, EMA20Array[2]);

But I flat don't understand this. I'm hoping that someone can explain to me what the above code would do.

10. Now I would calculate my slopes. But first I created two double variables to hold the slope values:

private double EMA8SlopeValue;
private double EMA20SlopeValue;

and then I would assign values to the slope values via:

EMA8SlopeValue = radToDegrees * (Math.Atan((EMA8Series[0] - EMA8Series[1]) * 2.5 / ATR(Closes[1], 3)[0]));
EMA20SlopeValue = radToDegrees * (Math.Atan((EMA20Series[0] - EMA20Series[1]) * 2.5 / ATR(Closes[1], 3)[0]));

NOTE: I set up a Constant of:

private const double radToDegrees = 180/Math.PI;

So now, I should have slope values in the EMA8SlopeValue and EMA20SlopeValue double variables, which in theory I should be able to now test off of.

11. The next step would be to see if the slope values meet or exceed my slope thresholds, and if they meet my condition I assign a 1 or a 0 to a slope accumulator value. However, I first had to create two more int variables to hold my slope accumulator values:

private int EMA8SlopeAccumulatorValue;
private int EMA20SlopeAccumulatorValue;

I then ran my if statements and assigned a 1 or 0:

if(EMA8SlopeValue < 25 && EMA8SlopeValue > -25)
EMA8AccumulatorValue = 0;
else
EMA8AccumulatorValue = 1;

if(EMA20SlopeValue < 20 && EMA20SlopeValue > -20)
EMA20AccumulatorValue = 0;
else
EMA20AccumulatorValue = 1;

So now, in theory I should have either a 1 or a 0 in my slope accumulator values.

12. Now I need to add the slope accumulator values up, and give that result to the Accumulator plot DataSeries, but that just ain't workin':

Accumulator.Set(EMA8AccumulatorValue + EMA20AccumulatorValue);

So I am able to compile the code, and I get no compile errors. But then I reload the indicator on my chart, and I get zip: it's blank. So now I am here, trying to get some help. I think this is easy, but I just think I am missing some very fundamental understandings of how all of these things relate to one another. I did such a thorough post with the hope that others will be able to learn something from the 10,000' view on how all of these items interrelate.

I really appreciate any help anyone can offer.

I am standing by to answer questions.

Thanks,

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

Log Output: Bar 21, index was outside the bounds of the array


All--

I just opened the Log under the Control Center > Log. Evidently I am getting the following error:

"Error calling "OnBarUpdate' method for indicator 'Name' on bar 21: Index was outside the bounds of the array.

So this makes me think this has something to do with how I have defined and populated my arrays.

Hopefully this bit of info will help...

Thanks,

Aventeren

Reply With Quote
 
  #4 (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

Well...

...I fixed it, but all of my questions still remain.

I changed the array sizes from [1], [3], [8] and [20] to [50] for each, which did the trick. My plot now works (ie, 0, 1 or 2).

I know that I should be pleased, but I'm not. I'm still trying to understand the broader context so I don't run into these problems in the future.

Thanks for any help you can offer.

Aventeren

Reply With Quote
 
  #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

Any way to fix MTF data gaps on LTF Chart?

Howdy--

Does anyone know how to "in fill" the data gaps caused by plotting higher time frames on a lower time frame charts, which occur, I suspect, because of how OnBarUpdate works differently for each time frame.

I have attached a screenshot of what the accumulator looks like for 4 moving averages, with 4 different slope thresholds for 3 different time frames.

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Is there a way to somehow fill in the higher time frame array values?

Ideally, I would see all three time frames have consecutive bars like the 4R Accumulator in Panel 2 (orange).

Thanks,

Aventeren

Reply With Quote

Reply



futures io > > > > > Need help understanding connections and relationships; simple conditional accumulator

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
monitor connections alexman Tech Support 35 March 17th, 2016 06:52 PM
VS2010 Conditional Breakpoints not working? drolles NinjaTrader 0 July 11th, 2012 01:56 PM
Internet Connections tderrick Tech Support 15 April 27th, 2012 05:25 AM
Conditional Nested Boolean Statements serac NinjaTrader Programming 4 November 27th, 2011 07:44 PM
relationships kbit Jokes 0 October 14th, 2011 07:01 PM


All times are GMT -4. The time now is 11:39 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.13 seconds with 20 queries on phoenix via your IP 54.234.255.29