![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Apr 2008
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
I'd like to build a zerolag MACD but run into a problem, perhaps somebody can give me a hint (Zerolag is defined by calculating the EMA and then the EMA of that EMA):
The MACD I got which is: double EMA1 = EMA(Input, Fast)[0]; double EMA2 = EMA(EMA(Input, Fast), Fast)[0]; zeroEMA.Set(EMA1 + (EMA1 - EMA2)); double EMA3 = EMA(Input, Slow)[0]; double EMA4 = EMA(EMA(Input, Slow), Slow)[0]; zeroEMAs.Set(EMA3 + (EMA3 - EMA4)); double macd = zeroEMA[0] - zeroEMAs[0] ; Now I need the same using the "macd" as input aboveto calculate the trigge for which I put: double EMA8 = EMA(macd, smooth)[0]; double EMA9 = EMA(EMA(macd, Smooth), smooth)[0]; macdAvg.Set(EMA8 + (EMA8 - EMA9)); but that doesn't work. Does somebody perhaps know what I have to put so it recognizes the "macd" as a "input" variable. I tried putting a "private Dataseries macd" under variables but that does nothing. Any help would be appreciated. Martin |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Mar 2008
Posts: 731
Thanks: 0
Thanked 1 time in 1 post
|
I don't know exactly but why not use the ZeroLagEMA indicator already included with NinjaTrader as the basis for your indicator? It might help simply things
Simply add two ZeroLagEMAs then a third plot with a bar line style for the difference. I hope that helps, I look forward to the result.
Last edited by Elliott Wave; 05-21-2008 at 05:06 PM.
|
|
|
|
|
|
#3 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
To have the MACD as a DataSeries input for the EMA you need to do something like EMA(MACD(12, 26, 9), Fast)[0].
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#4 | |
|
Junior Member
Join Date: Apr 2008
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
Thank you, but you need to work around it. I think I found the solution and I'll go through it and maybe you can check it to see if you think it's right:
The original MACD is this: fastEma.Set((2.0 / (1 + Fast)) * Input[0] + (1 - (2.0 / (1 + Fast))) * fastEma[1]); slowEma.Set((2.0 / (1 + Slow)) * Input[0] + (1 - (2.0 / (1 + Slow))) * slowEma[1]); double macd = fastEma[0] - slowEma[0]; double macdAvg = (2.0 / (1 + Smooth)) * macd + (1 - (2.0 / (1 + Smooth))) * Avg[1]; Which is the same as: fastEma.Set((EMA(Input,Fast)[0]) - (EMA(Input,Slow)[0])); double macd = fastEma[0] ; macdAvg2.Set(EMA(fastEma,Smooth)[0]); double macdAvg = macdAvg2[0]; The "slowEma" is gone as I already put it into the "fastEma" set. Build a new "macdAvd2" set and then use the fastEma as the input as seen above. Under variables add "private DataSeries macdAvg2;" and under initialize add "macdAvg2 = new DataSeries(this);" The "new" code above and the origial MACD as given in NT plot the same thing. So it's right. So now I just changed the EMA to ZeroLagEMA and the final code looks like this: fastEma.Set((ZeroLagEMA(Input,Fast)[0]) - (ZeroLagEMA(Input,Slow)[0])); double macd = fastEma[0] ; macdAvg2.Set(ZeroLagEMA(fastEma,Smooth)[0]); double macdAvg = macdAvg2[0]; The rest of the MACD is the same as the original indicator. This "seems" to work except I don't have another charting programme to see if it is really the right thing. Could you verify this ? If it is right it could be put into the indicator collection here in the forum. Martin ![]() Quote:
|
|
|
|
|
|
|
#5 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Due to bandwidth reasons we cannot provide support in checking every indicator for accuracy. I suggest you just run through it manually with a calculator for a few values and if they match up then you probably have it right.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Mar 2008
Posts: 731
Thanks: 0
Thanked 1 time in 1 post
|
I'm not aware of any program that has a ZeroLagMACD as standard so the best thing to do is export it and post it as an attachment in this thread. Once its been tested a bit and there's a chance to iron out any kinks, then you can post it in the file sharing section and everyone can benefit.
|
|
|
|
|
|
#7 | |
|
Junior Member
Join Date: Apr 2008
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
Thank you. A reference can be found here: http://www.meta-formula.com/Metastock-Formulas-Z.html
I'll try to verify my formula and if it is correct I'l post the results. Quote:
|
|
|
|
|
|
|
#8 |
|
Junior Member
Join Date: Apr 2008
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
Unfortunately I cannot export the indicator from my computer, I get an error message. It says "error CS0103" . I think I need to add the EMA to the export file but it's not on the list when I select the files(indicators) for export.
Is there a trick to this ? Basically I think I need to export my indicator, the ZeroLagEMA and the EMA. Any hint ? |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Mar 2008
Posts: 731
Thanks: 0
Thanked 1 time in 1 post
|
AKIAK you just need to give a name to the file at the top, add the ZeroLag MACD and when you click export it should automatically include any other required indicators.
|
|
|
|
|
|
#10 | |
|
Senior Member
Join Date: Mar 2008
Posts: 731
Thanks: 0
Thanked 1 time in 1 post
|
I'm not sure what formula you've used, but I found this tidbit regarding low lag MACD...
Quote:
|
|
|
|
|
|
|
#11 |
|
Junior Member
Join Date: Apr 2008
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
Still can't export it. I could post the code.
Regarding JMA: I have actually built "a" JMA MACD (basically a MACD with 3 JMAs which resulted in nothing => meaning I couldn't find any good values for the JMAs. But I think I did it wrong anyway because it's not a MACD with 3 JMAs but rather the difference of 2 JMA with a trailing JMA (I suppose this could also be done with a ZeroLagEMA as well). So when I did this a month ago I didn't realize that what he (Jurik) describes as a "MACD" is not quite the same as the traditional MACD. Still learning but getting there... |
|
|
|
|
|
#12 |
|
Junior Member
Join Date: Apr 2008
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
I need to correct that: the JMA MACD I did is right, but finding good values has been difficult. Haven't tried optimizing it though.
|
|
|
|
|
|
#13 |
|
Senior Member
Join Date: Mar 2008
Posts: 731
Thanks: 0
Thanked 1 time in 1 post
|
Good idea. Then I'll compile it and see if I can export it...
By the way, how are the Jurik indicators? Is the JMA much different than the ZeroLagEMA or T3? I'm considering getting them, but there doesn't seem to be much feedback on them in the forum. If know one is talking about them, I guess that means they probably work well
Last edited by Elliott Wave; 06-05-2008 at 02:11 PM.
|
|
|
|
|
|
#14 | |
|
Junior Member
Join Date: Apr 2008
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
Okay, so here comes the code for the ZeroLag MACD and also I am adding the "Leader of th MACD" code. This is a new indicator which TASC is featuring next month (it's not out yet, but since Worden already is using it in Blocks I quickly did the code...hopefully I'm not gonna get shot for this. Perhaps you could compile this as well for the community....) Regarding the JMA: I guess it depends on your "system", what is good is the DMX (which is a better version than the DM (DM+/DM-), however one has to admit that whatever indicators you are using, there will always be false signals no matter what. The JMA uses a "Phase" and a length, so if you put this into a MACD for example, rather than having 3 inputs (fast, slow, smooth) you have to figure out 6 >= fast with phase & length and so on. This is why I said in my earlier post that I have not found any "good" values..and there are no hints anywhere either. I found one (!) set of example values for the JMA MACD on some obscure russian board... but they made no sense either. Also the numbers are very different from regular MA, so let's say if you use an EMA of 20 the JMA might actually be 30 in length to get a "similar" picture and then you can start playing around with the phase which runs from -100 to +100 in order to change the lag. So you got more room to work with which can be good but I guess also frustrating. I bought a 3 month liscence for about $150 which I think is good in order to try it. So far I have to admit that I haven't made up my mind if I'm going to keep them. However the JMA does "hug" the price action better than a ZeroLagEMA and certainly T3 or TEMA (they will just over- or undershoot like heck...). I could post a screen shot of a JMA compared to say ZeroLag so let me know. Anyway, now here's the code for ZeroLagMACD and the "Leader f MACD" variables: private int fast = 12; private int slow = 26; private int smooth = 9; private DataSeries fastEma; private DataSeries diffArr; initialize: Add(new Plot(Color.Green, "Macd")); Add(new Plot(Color.DarkViolet, "Avg")); Add(new Plot(new Pen(Color.DodgerBlue, 2), PlotStyle.Bar, "Diff")); Add(new Line(Color.DarkGray, 0, "zero line")); fastEma = new DataSeries(this); macdAvg2 = new DataSeries(this); diffArr = new DataSeries(this); onbarupdate: if (CurrentBar == 0) { fastEma.Set(Input[0]); macdAvg2.Set(Input[0]); Value.Set(0); Avg.Set(0); Diff.Set(0); } else { fastEma.Set((ZeroLagEMA(Input,Fast)[0]) - (ZeroLagEMA(Input,Slow)[0])); double macd = fastEma[0] ; macdAvg2.Set(ZeroLagEMA(fastEma,Smooth)[0]); double macdAvg = macdAvg2[0]; Value.Set(macd); Avg.Set(macdAvg); Diff.Set(macd - macdAvg); } Properties: /// <summary> /// </summary> [Browsable(false)] [XmlIgnore()] public DataSeries Avg { get { return Values[1]; } } /// <summary> /// </summary> [Browsable(false)] [XmlIgnore()] public DataSeries Default { get { return Values[0]; } } /// <summary> /// </summary> [Browsable(false)] [XmlIgnore()] public DataSeries Diff { get { return Values[2]; } } /// <summary> /// </summary> [Description("Number of bars for fast EMA")] [Category("Parameters")] public int Fast { get { return fast; } set { fast = Math.Max(1, value); } } /// <summary> /// </summary> [Description("Number of bars for slow EMA")] [Category("Parameters")] public int Slow { get { return slow; } set { slow = Math.Max(1, value); } } /// <summary> /// </summary> [Description("Number of bars for smoothing")] [Category("Parameters")] public int Smooth { get { return smooth; } set { smooth = Math.Max(1, value); } } "Leader of the MACD": variables: private int fast = 12; private int slow = 26; private int smooth = 9; private DataSeries fastMACD; private DataSeries macdAvg2; private DataSeries fastEma; private DataSeries slowEma; private DataSeries slow1S; private DataSeries slowF; private DataSeries fast1S; private DataSeries fastF; initialize: Add(new Plot(Color.Green, "Macd")); Add(new Plot(Color.DarkViolet, "Avg")); Add(new Plot(new Pen(Color.Navy, 2), PlotStyle.Bar, "Diff")); Add(new Plot(Color.Red, "Leader")); Add(new Line(Color.DarkGray, 0, "Zero line")); fastMACD = new DataSeries(this); macdAvg2 = new DataSeries(this); fastEma = new DataSeries(this); slowEma = new DataSeries(this); slow1S = new DataSeries(this); slowF = new DataSeries(this); fast1S = new DataSeries(this); fastF = new DataSeries(this); onbarupdate: if (CurrentBar == 0) { fastMACD.Set(Input[0]); macdAvg2.Set(Input[0]); fastEma.Set(Input[0]); slowEma.Set(Input[0]); slow1S.Set(Input[0]); slowF.Set(Input[0]); fast1S.Set(Input[0]); fastF.Set(Input[0]); Value.Set(0); Avg.Set(0); Diff.Set(0); Leader.Set(0); } else { slowEma.Set(Close[0] - EMA(Input,Slow)[0]) ; slow1S.Set(EMA(slowEma,Slow)[0]); slowF.Set(slow1S[0] + EMA(Input,Slow)[0]); double slowFX = slowF[0]; fastEma.Set(Close[0] - EMA(Input,Fast)[0]) ; fast1S.Set(EMA(fastEma,Fast)[0]); fastF.Set(fast1S[0] + EMA(Input,Fast)[0]); double fastFX = fastF[0]; fastMACD.Set((EMA(Input,Fast)[0]) - (EMA(Input,Slow)[0])); double macd = fastMACD[0] ; macdAvg2.Set(EMA(fastMACD,Smooth)[0]); double macdAvg = macdAvg2[0]; Value.Set(macd); Avg.Set(macdAvg); Diff.Set(macd - macdAvg); Leader.Set(fastFX - slowFX); } Properties: /// <summary> /// </summary> [Browsable(false)] [XmlIgnore()] public DataSeries Avg { get { return Values[1]; } } /// <summary> /// </summary> [Browsable(false)] [XmlIgnore()] public DataSeries Default { get { return Values[0]; } } /// <summary> /// </summary> [Browsable(false)] [XmlIgnore()] public DataSeries Diff { get { return Values[2]; } } /// <summary> /// </summary> [Browsable(false)] [XmlIgnore()] public DataSeries Leader { get { return Values[3]; } } /// <summary> /// </summary> [Description("Number of bars for fast EMA")] [Category("Parameters")] public int Fast { get { return fast; } set { fast = Math.Max(1, value); } } /// <summary> /// </summary> [Description("Number of bars for slow EMA")] [Category("Parameters")] public int Slow { get { return slow; } set { slow = Math.Max(1, value); } } /// <summary> /// </summary> [Description("Number of bars for smoothing")] [Category("Parameters")] public int Smooth { get { return smooth; } set { smooth = Math.Max(1, value); } } Enjoy......
|
|
|
|
|
|
|
#15 | ||
|
Senior Member
Join Date: Mar 2008
Posts: 731
Thanks: 0
Thanked 1 time in 1 post
|
Quote:
Quote:
A couple screen shots would be cool if you get a chance, maybe comparing the JMA to the ZeroLagEMA and T3 with the DM, and DMX on panels below. By the way recently in TASC, there was a ZeroLagTEMA and ZeroLAGHATEMA (Heiken Ashi) which you may find of use. According to Jurik's own site the "Modified Optimal Elliptical Filter" is about the closest thing to the JMA. I'm trying to convert it to NT. I've posted the code in another thread so hopefully if I can't figure it out soon someone will...
|
||
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Programming connections | Gumphrie | Connecting | 6 | 12-11-2009 03:09 AM |
| Programming references | bobajob78 | General Programming | 1 | 02-11-2008 03:32 PM |
| Programming error message | Betty | Installation and Licensing | 1 | 11-05-2007 09:09 AM |
| Advanced Programming | sbtrader | General Programming | 3 | 10-26-2007 10:11 AM |
| Need Help Programming Custom Indicator from TS to NT | stevestrading | Indicator Development | 4 | 06-20-2007 04:31 PM |