View Full Version : Moving Average of a Indicator
buderim
11-04-2007, 01:33 AM
Hi,
I am sorry to bother you all with such a silly question.
I am trying to plot the moving average of CCI in the CCI window, In Metatrader4 I just drag and drop the MA into the CCI window and it works.
Is there anyway I can do this in NT6 ?
Thanks
Ian
NinjaTrader_Josh
11-04-2007, 01:43 AM
Hi buderim,
You can do this in NT6 by programming a very simple custom indicator. What you want to do in the custom indicator is call the CCI indicator within the SMA indicator. This can be done with the following code:
double smaCCI = SMA(CCI(14), 20)[0];
Please see attached sample for further reference on how to actually plot the values.
To install the indicator:
1) Download file
2) Open NinjaTrader
3) File->Utilities->Import NinjaScript
4) Select file
buderim
11-04-2007, 01:52 AM
Hi Josh,
Thanks for that ,I didnt realise it was that simple !!
I will have a look at it.
Many Thanks
Ian
Here's one I wrote a while back that has two plots... CCI and CCI with HMA averaging. This could easily be adjusted to do SMA averaging if you want an indicator with both plots. I liked the HMA better because it has less lag than an SMA.
buderim
11-04-2007, 03:12 AM
Thanks KBJ,
I will try this version as well.
Ian
dantav
11-09-2007, 03:01 AM
Can anyone help me with this? The SMA file works great, but I find it is too slow for good signals, and the Hull MA is too fast. I would like to use a Wilders MA of the CCI, which should end up somewhere between the 2. Thanks in advance for any help you can offer
DT
Hi buderim,
You can do this in NT6 by programming a very simple custom indicator. What you want to do in the custom indicator is call the CCI indicator within the SMA indicator. This can be done with the following code:
double smaCCI = SMA(CCI(14), 20)[0];
Please see attached sample for further reference on how to actually plot the values.
To install the indicator:
1) Download file
2) Open NinjaTrader
3) File->Utilities->Import NinjaScript
4) Select file
NinjaTrader_Ray
11-09-2007, 06:51 AM
If you post the code or reference documentation, someone may be kind enough to contribute.
sbgtrading
11-17-2007, 02:46 PM
From what I've found on the web, the Wilder MA is calculated by:
WilderMA = EMA(2*WilderPeriod-1);
So, to do a WilderMA on a CCI(14), you have:
int WilderPeriod = 10;
double WilderMAonCCI = EMA(CCI(14),(2*WilderPeriod-1))[0];
Ben
kian1
02-04-2008, 09:06 AM
hello
How do you have condition builder to look for condition when the cci cross above or below the MA,
Thanks,
NinjaTrader_Ray
02-04-2008, 12:37 PM
This might help...
http://www.ninjatrader-support.com/HelpGuideV6/ConditionBuilder-CrossOverConditions.html
kian1
02-04-2008, 12:52 PM
I have the ema ploted on cci and i liket to be able to pon point when the cci crossed above or below its EMA that is ploted.
/// <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.YellowGreen, "CCI"));
Add(new Plot(Color.DarkViolet, "SmoothingPeriod"));
Add(new Plot(new Pen(Color.Orange, 3), "CCI"));
Add(new Plot(new Pen(Color.Green, 3), "CCI_with_EMA_averaging"));
Add(new Line(Color.DarkGray, 200, "Level 2"));
Add(new Line(Color.DarkGray, 100, "Level 1"));
Add(new Line(Color.DarkGray, 0, "Zero line"));
Add(new Line(Color.DarkGray, -100, "Level -1"));
Add(new Line(Color.DarkGray, -200, "Level -2"));
}
/// <summary>
/// Calculates the indicator value(s) at the current index.
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar == 0)
{
Values[0].Set( 0 );
Values[1].Set( 0 );
}
Values[0].Set( CCI(CCIPeriod)[0] );
Values[1].Set( EMA(Values[0], SmoothingPeriod )[0] );
}
#region Properties
/// <summary>
/// </summary>
[Description("Numbers of bars used for CCi calculations")]
[Category("Parameters")]
public int CCIPeriod
{
get { return CCIperiod; }
set { CCIperiod = Math.Max(1, value); }
}
[Description("Numbers of bars used for EMA smoothing")]
[Category("Parameters")]
public int SmoothingPeriod
{
get { return smoothingPeriod; }
set { smoothingPeriod = Math.Max(1, value); }
}
#endregion
}
}
I have the above fomula but it does not plot the CCI and EMA(smoothing) seperatlely when i want to write cross over conditions. in the condition winodw..any idea
NinjaTrader_Ray
02-04-2008, 01:14 PM
Can you clarify -
Do you want to know...
- How to create a condition in the condition builder that checks for a cross condition of CCI over an EMA of CCI
or
- How to do this programatically? If the latter -
if (CrossAbove(CCI(14), EMA(CCI(14), 14), 1))
// Do something....
kian1
02-04-2008, 01:33 PM
Yes, that is correct
when building a condition using the wizard ,, if the indicator has more then one LINE then it it will have a section for Plot drop down with names of the line that you want tested for example:
macd indicator has
plot drop down with MACD,AVE, and DIFF to test against each other.
I want to have the CCI test when it crosses above or below cci EMA avrage. I tried to paste this
if (CrossAbove(CCI(14), EMA(CCI(14), 14), 1))
in the condition builder it it will not paste.
what is worng with the programing i sent you earlier it will not show the +plot in the wizard condition builder..
Thanks much...
NinjaTrader_Ray
02-04-2008, 03:59 PM
In the Condition Builder ....
- On left side, select CCI indicator
- In middle select "CrossAbove"
- On right side select EMA and in the right lower section, click to the right of "Input series" and press the "..." button that shows up, then select CCI
kian1
02-05-2008, 07:56 AM
Thanks,
But what you are suggesting will not plot the ema ON cci,
I did what you said and the ema is ploted on the price chart Not cci
I have attached the pics
I am very surprised that this feature is not in the chart package wizard
we should be able to plot indicator on indicator very easily.
with out being a programmer.
in the attached pic the bottom indicator is the cci with ema plotted but when i want to
have the condition cci crossing its own ema i can Not do it in the condition builder b/c the the plot is not there,as i metioned in the MACD example yesterday..
If I send you the programing code on the bottom indicator that has ema ploted on cci could anyone tell why it will not allow me to build cross over conditions?
Thanks,
kian1
02-05-2008, 08:45 AM
Hi Ray
I see that you were on the woodiescci forum.
do you have the woodies cci pattern automated if so where can i down load it, i like to test all the featurs on ninjatrder before i purchase it for live trading.
Thanks much for the help on the ema on cci issue.
NinjaTrader_Ray
02-05-2008, 09:16 AM
I do see that the EMA is plotting the standard EMA as opposed to the EMA of CCI. I will check to see what expected behaviour is right now.
Despite this, the condition will work as you execpted.
Here is a link in Woodies forum for a strategy I contributed.
http://www.woodiescciclub.com/forum/viewtopic.php?t=5501&sid=70e4c0bfae1566cad235e1fd6d44a391
kian1
02-07-2008, 02:17 PM
Hi Ray,
do you have any news for me?
inregard to indiacator on indicator...
it is very important for me to have ema on cci for my strategy to work
Thanks,
NinjaTrader_Ray
02-07-2008, 02:43 PM
Indicator on indicator does work right now in your strategy. What does not work is the display of an indicator on an indicator. This has been resolved for our next update.
Fecdzo
02-08-2008, 03:56 AM
Hi, everyone!
I am very new to Ninja trader, that is why I would like to ask for your help.
I am using 2 indicators. The MIN and MAX. This shows me the maximum and the minimum of "n" bars on my chart. But I would like to put the average of these two info on my chart as well. How can I do that?
Later on I would like to use the info for exits as well. Will it be possible?
NinjaTrader_Dierk
02-08-2008, 04:02 AM
You certainly can do that by custom NinjaScript coding.
Fecdzo
02-08-2008, 04:29 AM
Thanks but I am just experiencing ninjatrader, so I dont have much programing experienc...
You certainly can do that by custom NinjaScript coding.
NinjaTrader_Dierk
02-08-2008, 04:34 AM
May be the community could help you out?!? As last resort a certified NinjaScript consultant would be at your help: http://www.ninjatrader.com/webnew/partners_onlinetrading_NinjaScript.htm
Pete S
02-08-2008, 05:57 AM
Hi, everyone!
I am very new to Ninja trader, that is why I would like to ask for your help.
I am using 2 indicators. The MIN and MAX. This shows me the maximum and the minimum of "n" bars on my chart. But I would like to put the average of these two info on my chart as well. How can I do that?
Later on I would like to use the info for exits as well. Will it be possible?
Isn't that what the DonchianChannel indicator does?
Pete S
02-08-2008, 05:57 AM
If I send you the programing code on the bottom indicator that has ema ploted on cci could anyone tell why it will not allow me to build cross over conditions?
Thanks,
Do you still need help with this?
kian1
02-11-2008, 10:14 AM
I am trying to download attched file and it says
I can not becuase there is programing error that needs to be resovled I have delleted all custom idicators and strategyes Any ieadas?
NinjaTrader_Ray
02-11-2008, 10:19 AM
Are you using 6.5.XXX or 6.0.XXX?
kian1
02-11-2008, 10:27 AM
I am using 6.0.xxx
NinjaTrader_Ray
02-11-2008, 10:29 AM
You need to use 6.5. Its available for download in this forum under the 6.5 Beta section.
kian1
02-11-2008, 10:52 AM
thanks, Ray
Fecdzo
02-11-2008, 11:27 AM
Isn't that what the DonchianChannel indicator does?
Ohhh...you are right:rolleyes::D thanks
kian1
02-11-2008, 12:34 PM
what does it do?:confused: DonchianChannel indicator
Pete S
02-11-2008, 03:47 PM
what does it do?:confused: DonchianChannel indicator
Highest high and lowest low for a given period. Put it on a chart and take a look.
kian1
02-13-2008, 12:17 PM
I have a set of cirteria when meet, my strategies should get me In or Out
of the market But its triggering the signal 2 bars later
for example i ask to be out of a long when cci cross below Zero
it gets me out 2 Bars later...
Anyone know what i am doing wrong here....
Thanks,
NinjaTrader_Ray
02-13-2008, 12:44 PM
You will have to debug to see what is happening. Here is a guide than can help provide guidance...
http://www.ninjatrader-support.com/vb/showthread.php?t=3418
kian1
02-13-2008, 01:22 PM
// Condition set 2
if (CrossBelow(CCI(14), 100, 1))
{
ExitLong("EXITLONG", "");
DrawArrowDown("My down arrow" + CurrentBar, false, 0, 0, Color.Red);
}
why is the above trigering 2 bars later?
I check and recheck i can not find anything wrong Or I do not know enough to find this problem,
NinjaTrader_Ray
02-13-2008, 01:48 PM
Is this in a backtest or real-time?
kian1
02-13-2008, 01:52 PM
real time demo..
NinjaTrader_Ray
02-13-2008, 01:58 PM
In real-time, executions are plotted where they really occur which is different than in a backtest.
If your CCI cross happens on Bar #100 and you are 2 second charts and the order gets filled 4 seconds later....the execution would be plotted on Bar #102 as an example since it will have an execution time stamp 4 seconds from the time the order was placed.
kian1
02-13-2008, 02:24 PM
I see what you are saying
I am using rang bars.. each candle bar is any where from 4 to 10 minuts
this is filling the order 2 bars later and its market order in a eletronic market,
market orders get filled in a matter of One or Two seconds,in this market
This is delaying a market order after its triggard about an average of 15 minutes give or take few...that is really a long time
kian1
02-13-2008, 02:36 PM
I see what you are saying
I am using rang bars.. each candle bar is any where from 4 to 10 minutes
this is filling the order 1 or 2 bars later and its market order in a eletronic market,
market orders get filled in a matter of One or Two Seconds,in this market
This is delaying a market order after its triggard about an average of 15 Minutes give or take few...that is really a long time
Take look at the attachment where you see market 1,2,3 on cci crossing above its 3 day EMA look above to see where its filling the orders.
also see cci crossing below 100 marked x<100 it should close the trade on red bar with the large blue arrow above. its 40 ticks and 10 minutes later it has not closed the trade yet....
I need this to tirgger a maket order as soon as the crossing happens.
any input is appriciated...
Kian
NinjaTrader_Ray
02-13-2008, 03:17 PM
I can't comment on when you code should trigger entries and exits since I don't know your code. What I can say is this -
- Orders are submitted at the close of a bar where you call an order method --> There is no 15 minute delay
- To double check this you can add Print() call and include the the time of a bar when you place an order, this will show up in the Output window. You can then check this time to the time in the Log tab of when a market order is placed.
- In addition, you can run the SampelMACrossOver strategy and see that orders are really placed when the crosses happen. If your experience is different with the sample strategy then let us know.
kian1
02-15-2008, 11:18 AM
look at the blue arrow where MAs cross and look where it executed the trade.......
my strategy requires the trade to go market and it fill usually with in a second or less in the electronic markets
using a 10 and 25 cross over that is a longer term strategy and it probably cross each other once or twice a day deponding on the time frame under 60 minutes, so the exact execution probably is not as important.
if you come up with anything let me know or anyone else is going through the samething like to hear your ideas.
Thanks
Kian
Pete S
02-15-2008, 01:51 PM
That looks normal to me assuming calculate on bar close is true. The bar you have highlighted the values are either equal or haven't quite crossed yet, you can verify this in the data box. When the next bar closes, the cross condition is true. You get filled at the open of the following bar.
Fecdzo
02-16-2008, 04:48 AM
I have written a very simple strategy and tested it on daily bars. Now that open tick is working I tried test it on minute charts(1 and 5 minute charts) but as soon as an enter signal is generated, it exits immediately at the entry price. But it works fine on daily bars. What could be the problem?
I have tested with all other strategies as well but it wont work. Have I adjusted something wrong?No matter what strategy I use...even if I switch time frames...problem is same....
NinjaTrader_Josh
02-16-2008, 05:49 AM
You will most need to debug your strategy as per these tips: http://www.ninjatrader-support.com/vb/showthread.php?t=3627
http://www.ninjatrader-support.com/vb/showthread.php?t=3418
kian1
02-16-2008, 10:18 AM
Let me see If I uderstand you correctly
so what you are saying is when the cross over happens on bar 1 and it waits for bar 2 to close and it executes the trade on bar 3 at close of bar 2 is that how its working?
if that is the case how can we conrtol the execution time to happen right at crossovers for example.
If I have my entery when cci cross above -100
what the system does if first bar crosses -100 then it waits for the second bar to close then it executes the trade at bar 3 by then the cci could be around -50 or higher and who knows many ticks later that is, That just take the edge away.....
What my system needs is when cci crosses above -100 lets say goes to -99.99
it has to execute the trade.....why does it waits so long 2 bars later
it should not matter if I am using tick,line,candle chart it should execute right at -99.99
Could you explain what the wait is for?
is there a way we could control execution part of the auto trading system?:confused:
thanks,
kian1
02-19-2008, 11:38 AM
Hi
what can I do to have the execution happen the second the cross over takes place...that is very important in my strategy
I can not wait for the close of following bar or 2
NinjaTrader_Ray
02-19-2008, 11:52 AM
See CalculateOnBarClose.
http://www.ninjatrader-support.com/HelpGuideV6/CalculateOnBarClose1.html
kian1
02-19-2008, 12:13 PM
I had checked the box for CalculateOnBarClose and removed it in the wizard and retestd everything it Makes no diffremce if its check or not..
what am I doing worng now..
NinjaTrader_Ray
02-19-2008, 12:43 PM
If you are referring to a backtest then that is correct and expected. You will find information on this in the link I had previously provided.
kian1
02-20-2008, 07:18 AM
i am referring to the live data i use DTN Ifeed data
I check and uncheck the CalculateOnBarClose on wizard and it does not make any diffrence on triggering the trade times it trigggers on close of second bar start of 3rd bar
NinjaTrader_Ray
02-20-2008, 07:37 AM
When you run the strategy on the chart, make sure that the "Calculate on bar close" parameter is set to false.
kian1
02-20-2008, 10:52 AM
its seems to make sense of the live date feed
another subject:
is it possible to have the stratgey on chart to press a certain key on the keyboard automaticly why a buy is triggard?
for example :
when a buy is triggard it would act as if the number 1 key was pressed. and 2 for sell.
NinjaTrader_Ray
02-20-2008, 11:07 AM
Since NinjaScript is C#, that is possible but this is outside of the scope of what we provide support for.
Elliott Wave
05-04-2008, 10:22 PM
EDIT. I figured it out. :)
NinjaTrader_Josh
05-05-2008, 12:05 AM
Not sure what ZeroLagEMA is so I don't know the syntax for it, but generally you don't pass in doubles. You pass in the IDataSeries itself. For example when you use SMA(High, 5)[0] you didn't pass in High[0] you passed in the DataSeries High. I would assume the same would apply to ZeroLagEMA.