Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Multi Time Frame and EMA diffs
Collapse
X
-
Hello higler,
The code I showed does show that the diff is being updated tick by tick. The issue is that you are looking at two EMAs which are reacting effectively in parallel and thus are not changing relative to each other, keeping the diff value the same. If you change 1 of the EMAs to an SMA then I think you will see an intra bar differences.
Print ("CB: "+CurrentBars[0]+" Diff: "+Diff[0]);
-
Paul - Thank you or your help. I ran your code on my system and get the same results as you. What I find interesting, and don't understand (I'm not a mathematician), is that although the 2 different time frame EMA's update on every tick the difference between the two remains the same until the next minute bar, at which time the difference changes and again remains constant throughout the minute, etc. I would have thought that the difference between the two different time frame EMA's would at least change a little during the minute since it changes immediately (sometimes by quite a bit) at the beginning of a new minute. Maybe it has to do with how EMA's are calculated and weighted in their calculation. But, thank you.Last edited by higler; 10-12-2015, 08:05 AM.
Leave a comment:
-
Thank you. I'm going to take your code and run it on my system to see what happens.
Leave a comment:
-
Hello,
Thanks for your reply.
I'm still not sure why you are not seeing the tic by tic change. I took your code and modified it to show the difference directly between the moving averages. I captured it in a video: http://screencast.com/t/crpUALVpN3iV
Leave a comment:
-
I have listed the code below. See also the 2 attachments. Attachment "MultiTest 1min 3min plots.jpg" shows the 1 minute and 3 minute plots. They both update real time tick by tick. Attachment "Diff of 1min 3min.jpg" plots the difference. It does not update tick by tick (only at the end of each minute) even though the 1 min and 3 min plots are updating tick by tick. I've shown it on two different charts because if all three plots are shown simultaneously that it gets too compressed.
Code follows:
public class hMultiTest : Indicator
{
#region Variables
double ema1Minute = 0;
double ema3Minute = 0;
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Line, "The1EMA"));
Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "The3EMA"));
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Diff"));
Add(PeriodType.Minute, 3);
Overlay = false;
CalculateOnBarClose = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
if ((CurrentBars[0] <= 10) || (CurrentBars[1] <= 10)) return;
ema1Minute = EMA(Closes[0], 10)[0];
ema3Minute = EMA(Closes[1], 10)[0];
The1EMA.Set(ema1Minute);
The3EMA.Set(ema3Minute);
Diff.Set(ema1Minute - ema3Minute);
}
#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 The1EMA
{
get { return Values[0]; }
}
[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 The3EMA
{
get { return Values[1]; }
}
[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 Diff
{
get { return Values[2]; }
}
#endregion
}
Leave a comment:
-
Hello higler,
Thanks for your post.
When the data is first loaded on the chart it will be processing historical data and from that basis will calculate as if CalculateOnbarClose = true. Once the indicator is connected to live data it should be processing on a tic by tic basis.
I've replicated the code you've shown and I do see that when connected to live data all three traces are updating in realtime, tick by tick.
Can you provide a screenshot of what you are seeing and perhaps a bit more of your code?
Leave a comment:
-
Originally posted by higler View PostHope this makes sense.
I have a multi time frame indicator called MultiTest. For instance, I added 3 minute bars data to MultiTest using Add(PeriodType.Minute, 3). I applied the MultiTest indicator to a 1 minute chart. I have the indicator set to CalculateOnBarClose = false so as to update on every tick. I then calculate EMA's for the two different time frames:
ema1Minute = EMA(Closes[0], 10)[0];
ema3Minute = EMA(Closes[1], 10)[0];
.
Without seeing your code, I cant be sure but is it possible that you arn't putting the
calcualtion for the difference in the correct "BarsInProgress" sequence. Naturally your vars would also have to be global so they dont reset to 0 between BarsInProgress.
e.g
I think the sequence would need to be as follows
if (BarsInProgress == 0)
{
assign your 1 min ema val here
}
if (BarsInProgress == 1)
{
assign your 3 min ema val here
now do your calculation
}
Leave a comment:
-
Multi Time Frame and EMA diffs
Hope this makes sense.
I have a multi time frame indicator called MultiTest. For instance, I added 3 minute bars data to MultiTest using Add(PeriodType.Minute, 3). I applied the MultiTest indicator to a 1 minute chart. I have the indicator set to CalculateOnBarClose = false so as to update on every tick. I then calculate EMA's for the two different time frames:
ema1Minute = EMA(Closes[0], 10)[0];
ema3Minute = EMA(Closes[1], 10)[0];
I can plot these and they update real time (tick by tick) using something like this:
The1MinuteEMA.Set(ema1Minute);
The3MinuteEMA.Set(ema3Minute);
However, if I take the difference of the 2 EMA's and try and plot then I can't get tick by tick updating of the difference. It only updates at the end of the 1 minute bar. For instance, if I do the following then I don't get tick by tick updating:
Diff.Set(ema1Minute - ema3Minute)
This only updates at the end of a the 1 minute bar and not tick by tick.
I don't understand why the Diff of the two different time frame EMA's won't plot tick by tick while either of the individual EMA's will plot tick by tick. Thank you.Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by algospoke, 04-17-2024, 06:40 PM
|
6 responses
48 views
0 likes
|
Last Post
by algospoke
Today, 06:18 PM
|
||
Started by arvidvanstaey, Today, 02:19 PM
|
4 responses
11 views
0 likes
|
Last Post Today, 04:08 PM | ||
Started by samish18, 04-17-2024, 08:57 AM
|
16 responses
61 views
0 likes
|
Last Post
by samish18
Today, 03:30 PM
|
||
Started by jordanq2, Today, 03:10 PM
|
2 responses
9 views
0 likes
|
Last Post
by jordanq2
Today, 03:23 PM
|
||
Started by traderqz, Today, 12:06 AM
|
10 responses
18 views
0 likes
|
Last Post
by traderqz
Today, 02:49 PM
|
Leave a comment: