Centered Moving Average not refreshed on new data? - NinjaTrader | futures io social day trading
futures io futures trading


Centered Moving Average not refreshed on new data?
Updated: Views / Replies:942 / 6
Created: by TraderWow 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
 

Centered Moving Average not refreshed on new data?

  #1 (permalink)
Trading Apprentice
Berlin, Germany
 
Futures Experience: Intermediate
Platform: MT5
Favorite Futures: Commodities
 
Posts: 5 since May 2012
Thanks: 1 given, 2 received

Centered Moving Average not refreshed on new data?

Hello ninjas,

I have been trying to build an indicator to smooth a centered Moving Average, but somehow the indicator never plots the "refreshed" values. Although I have searched through the forum and read all similar topics (plus all 1027 pages of the NT version 7 Help Guide), I am still unable to fix my indicator. Please give me some hints on what could go wrong. Thanks a lot in advance!


I used the Output window and the chart "Show Data Box" to debug. The array CalValue holds the indicator values, but these values do not match those in the "Show Data Box". Is there something wrong with the Set() command? Or I should shift the bar back or something? I even removed the script from the indicator folder, used a new name for the script, and even re-installed NT 7 but the same problem still persisted.


Please see the script and the Output window below:

****************************************************************
public class TCMA5 : Indicator
{
#region Variables
private bool smooth = true; // Default setting is true
private DataSeries mySMA;
private double[] CalValue;
private double[] Sum;
private double[] Sumw;
#endregion

protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Middle"));
mySMA = new DataSeries(this);
CalValue = new double[50];
Sum = new double[50]; // NT7 limits the number of available bars for calculations at 256
Sumw = new double[50];
Overlay = true;
}

protected override void OnBarUpdate()
{
if (CurrentBar <= 5) return;
Print(" ");

mySMA[0] = SMA(Input, 0)[0];

for (int i = 20; i >= 0; i--)
{
Sum[i] = 9 * mySMA[i];
Sumw[i] = 9;
int k = 8;

for (int j = 1; j <= 8; j++)
{
Sum[i] += k * mySMA[i+j];
Sumw[i] += k;

if (smooth==true & j <= i)
{
Sum[i] += k * mySMA[i-j];
Sumw[i] += k;
}

k--;
}

CalValue[i] = Sum[i] / Sumw[i];
}

/// Plot the array CalValue
for (int p = 0; p <= 20-1; p++)
{
Print("CalValue[" + p.ToString() + "] = " + CalValue[p].ToString());
}
Values[0].Set(CalValue[0]);
}

#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Middle
{
get { return Values[0]; }
}

[Description("")]
[GridCategory("Parameters")]
public bool Smooth
{
get { return smooth; }
set { smooth = value; }
}
#endregion
}

*****************************************************************************



These are the values from the Output Window. The chart is a daily chart of the stock XOM:

*****************************************
CalValue[0] = 88.6862222222222
CalValue[1] = 88.5771698113207
CalValue[2] = 88.4696666666667
CalValue[3] = 88.3572727272727
CalValue[4] = 88.2442253521127
CalValue[5] = 88.1388
CalValue[6] = 88.0338461538461
CalValue[7] = 87.925625
CalValue[8] = 87.8082716049383
CalValue[9] = 87.7025925925926
CalValue[10] = 87.6198765432098
CalValue[11] = 87.5351851851851
CalValue[12] = 87.4653086419753
CalValue[13] = 87.4077777777778
CalValue[14] = 87.3669135802469
CalValue[15] = 87.3176543209876
CalValue[16] = 87.307037037037
CalValue[17] = 87.3366666666666
CalValue[18] = 87.3922222222222
CalValue[19] = 87.4985185185185

***************************************************


However, each time the chart plots the following values. It looks like the ninjascript somehow ignores the section "if (smooth==true & j <= i)". I am puzzled. What's wrong?

**************************************
CalValue[0] = 88.6862222222222
CalValue[1] = 88.3988888888889
CalValue[2] = 88.2133333333333
CalValue[3] = 88.048
CalValue[4] = 87.9091111111111
CalValue[5] = 87.8384444444444
CalValue[6] = 87.5957777777777
CalValue[7] = 87.5348888888889
CalValue[8] = 87.4088888888889
CalValue[9] = 87.4468888888888
CalValue[10] = 87.4566666666666
CalValue[11] = 87.3546666666666
CalValue[12] = 87.3675555555555
CalValue[13] = 87.3731111111111
CalValue[14] = 87.3708888888888
CalValue[15] = 87.0395555555555
CalValue[16] = 87.1595555555555
CalValue[17] = 87.2768888888888
CalValue[18] = 87.3608888888888
CalValue[19] = 87.6359999999999
************************************************

Reply With Quote
The following user says Thank You to TraderWow for this post:
 
  #2 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,653 since Mar 2010
Thanks: 4,226 given, 25,602 received
Forum Reputation: Legendary

 
Code
if (CurrentBar <= 5) return;
Print(" ");

mySMA[0] = SMA(Input, 0)[0];

for (int i = 20; i >= 0; i--)
{
Sum[i] = 9 * mySMA[i];
....


You forgot to set a value for the DataSeries mySMA for the first 6 bars.

Also for CurrentBar = 6 you are accessing mySMA[20]. Obviously this cannot work, as mySMA[20] is not defined for CurrentBar = 6.

Reply With Quote
The following 3 users say Thank You to Fat Tails for this post:
 
  #3 (permalink)
Trading Apprentice
Berlin, Germany
 
Futures Experience: Intermediate
Platform: MT5
Favorite Futures: Commodities
 
Posts: 5 since May 2012
Thanks: 1 given, 2 received


Thanks a lot for the hint, Fat Tails! I fixed the part that you mentioned.

By the way, I think I now understand the issue. It's the assignment of values and thus plotting the correct index!!

I did an experiment and found the following things:

1) On a chart, I limited the number of candlebars to 43 bars. Because the calculations will not involve the "oldest" bar (the 42th bar) and the "newest" bar (the 0th bar), it is expected that there will be 41 groups of data.

2) Next, I checked the Output window and counted the number of group. Sure enough, there are exactly 41 groups of data. This means that the indicator will show on the chart from the 41st bar to the 1st bar. (I don't understand why the indicator starts on the 1st bar instead of the 0th bar. Any idea?)

3) If I write Values[0].Set(CalValue[0]), this means that only the 0th element of each group will be plotted. Sure enough, the "Data Box" verifies that each of the bar (the 41st to the 1st) shows the indicator value of the 0th element.



Here is my need for help --- I only want to plot the values of the "most recent" group. For example, I have the following results from the Output window:

==========================================
:
:
:
New: CalValue[0] = 88.37875
New: CalValue[1] = 88.45875
New: CalValue[2] = 88.3376923076923
New: CalValue[3] = 88.2317948717948
New: CalValue[4] = 88.0007692307692

New: CalValue[0] = 88.6925
New: CalValue[1] = 88.5190625
New: CalValue[2] = 88.5451282051282
New: CalValue[3] = 88.3376923076923
New: CalValue[4] = 88.2317948717948

New: CalValue[0] = 89.10125
New: CalValue[1] = 88.914375
New: CalValue[2] = 88.7094871794872
New: CalValue[3] = 88.5451282051282
New: CalValue[4] = 88.3376923076923
==============================================


I only want the LAST group of data and have them plotted as follows:

CalValue[0] = 89.10125 on the current bar (bar 0)
CalValue[1] = 88.914375 on the previous bar (bar 1)
CalValue[2] = 88.7094871794872 on the two-day-ago bar (bar 2)
CalValue[3] = 88.5451282051282 on the three-day-ago bar (bar 3)
CalValue[4] = 88.3376923076923 on the four-day-ago bar (bar 4)


What codes should I write, or how do I structure my array and indexes in order to get my plot correct?

Thanks a lot for your help!

Reply With Quote
 
  #4 (permalink)
Trading Apprentice
Berlin, Germany
 
Futures Experience: Intermediate
Platform: MT5
Favorite Futures: Commodities
 
Posts: 5 since May 2012
Thanks: 1 given, 2 received

Ich lebe in Pankow! 20 minuten von Berlin!! (Sorry I cannot reply via PM because I am not yet allowed to use that feature. So, I will have to omit most of my PM response here.) Anyway, cheers for the great Oktoberfest!!!


I am still trying different ways to pick only the most recent array and have its values plotted. Sighhhhhhh

Reply With Quote
 
  #5 (permalink)
Trading Apprentice
Berlin, Germany
 
Futures Experience: Intermediate
Platform: MT5
Favorite Futures: Commodities
 
Posts: 5 since May 2012
Thanks: 1 given, 2 received

Problem solved! The technical team from NinjaTrader fixed the codes for me. The fix works beautifully!

Reply With Quote
 
  #6 (permalink)
Elite Member
Los Angeles, CA
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: AMP
Favorite Futures: ES
 
Posts: 30 since Oct 2009
Thanks: 183 given, 22 received


TraderWow View Post
Problem solved! The technical team from NinjaTrader fixed the codes for me. The fix works beautifully!

Would it be possible to share the fix with us as a zip folder or .cs file?

Thanks in advance.

Reply With Quote
 
  #7 (permalink)
Trading Apprentice
Berlin, Germany
 
Futures Experience: Intermediate
Platform: MT5
Favorite Futures: Commodities
 
Posts: 5 since May 2012
Thanks: 1 given, 2 received

No problem! The following is the fix on the last part of the script. Basically, we need to set the condition using if (p == 0).


/// Plot the array CalValue
for (int p = 0; p <= 20-1; p++)
{
Print("CalValue[" + p.ToString() + "] = " + CalValue[p].ToString());
if (p == 0)
Values[0].Set(CalValue[p])
else
Values[0].Set(p, CalValue[p]);
}

Reply With Quote
The following user says Thank You to TraderWow for this post:

Reply



futures io > > > > Centered Moving Average not refreshed on new data?

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Best Moving Average sharmas Elite Automated Trading 62 April 9th, 2012 07:44 PM
Moving Average Kush NinjaTrader Programming 5 November 6th, 2011 01:49 PM
Moving average Help yiman NinjaTrader Programming 4 July 29th, 2011 09:03 AM
Refreshed Bull May Catch its Breath Before Moving Higher Quick Summary News and Current Events 0 March 24th, 2011 11:10 PM
New Moving Average arnaudlx The Elite Circle 10 January 28th, 2011 06:15 AM


All times are GMT -4. The time now is 01:41 AM.

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-16 in 0.14 seconds with 19 queries on phoenix via your IP 23.22.136.56