![]() |
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
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Aug 2008
Posts: 1
Thanks: 0
Thanked 0 times in 0 posts
|
Hello -
I am using the KAMA in one of my strategies (I use the Strategy Wizard BTW) and I would like it to do the following: - IF: middle parameter (say, "period 10") is flat, or doesn't move up or down by more than one tick within 5 bars - THEN: close long and/or close short position Does anyone know how to do this? I can't seem to find a way to include a flat condition. Thanks. |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
If you mean that it has a range less than 1 tick you could do something like:
if (MAX(KAMA(int fast,int period,int slow), 5)[0] - MIN(KAMA(int fast,int period,int slow), 5)[0] < TickSize) // Its flat
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Nov 2012
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
Hi,
I'm reviving this thread! I too am having trouble coding an MA flat condition to avoid chop. My MA is the anaHoltEMA which has a period and trend setting that I use for long-term market trend. Originally I tried using this code to determine if an order should be placed or not using the wizard: like this: if (Slope(anaHoltEMA(Period, Trend).HoltEMA, 5, 0) > 20) or as part of another condition: && if Slope(anaHoltEMA(Period, Trend).HoltEMA, 5, 0) > 20 Unfortunately none of these work and I've played with every numerical setting with no joy. It will either not do anything or take out all my long trades even when the slope is steep. As a thought, since I also have a working "rising/falling condition with the anaHoltEMA is it possible to simply add a slope value to that rather than adding an entire new condition? What do I need in order to set a certain slope value above which all trades must take place? Here's a screenshot of what I need to filter: http://postimage.org/image/6gv0w9myv/full/ Thanks to anyone who can help me out.
Last edited by Shadowshorter; 02-18-2013 at 10:19 PM.
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,407
Thanks: 252
Thanked 975 times in 958 posts
|
Shadowshorter, likely the value you check for in the slope is simply too steep, so it would never register any trades with that hard a slope being considered in the entry condition for your script. Keep in mind this is a rise over run slope calculation and not expressed in radians / angle. What I would suggest is creating an indicator or print to see which slope value you get in your 'chop zone' and then from there defining what rule to include to attempt better trade filtering for your scalper.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Nov 2012
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
Hi Bertrand,
So there isn't an easy way to tell ninja trader when the MA is neither rising or falling? I'm trying to get a fully automated system here and using an indicator which prints something for me to initiate a manual trade defeats the whole purpose. How can I bracket ma rising and falling conditions so that a value from X to Y means the ma should be considered rising or falling, leaving everything else as a no trade area. I'm not a programmer so if i have to write a complicated indicator its never going to happen. Thanks for your time Bertrand, Shadow |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,407
Thanks: 252
Thanked 975 times in 958 posts
|
Shadowshorter, the idea to create the indicator was to better understand for which slopes you would then actually need to filter in your strategy condition, as the slope you used was just too hard a condition - there's per se no flat MA or slope, it would need to defined exactly what that would constitute in terms of a condition, as in the real world the MA will not be 100% flat, but just meander for example with a very low slope, even-though your eye might say : it's flat.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Junior Member
Join Date: Nov 2012
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
Hi Bertrand,
My understanding is that a slope of 100 is a vertical line or should it be a value of 0? If I set an ma slope value of 10 and say that I can only go long or short if the slope value is higher than 10 I should be filtering all the price action below an ma slope of 10 correct? Or should it be the other way round with a slope of 90 instead of 10? Thanks |
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,407
Thanks: 252
Thanked 975 times in 958 posts
|
This understanding is unfortunately not correct - the slope you access uses a rise over runs calculation and therefore does not represent an angle.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Junior Member
Join Date: Nov 2012
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
Thanks for your reply.
My problem is that when I add the slope function i was using before without the rising/falling condition, no matter what numeric value I use for the slope, 1 or 100 or 20 or 80 or whatever, it either takes out all my long trades or none of them. What am I doing wrong here: if (ZeroLagTEMA(40).ZeroTEMA[0] > ZeroLagHATEMA(40).ZeroHATEMA[0] && Position.MarketPosition == MarketPosition.Flat && Slope(anaHoltEMA(80, 20).HoltEMA, 10, 0) > 5 && Close[0] > ZeroLagHATEMA(40).ZeroHATEMA[0]) { EnterLong(1, "Long1"); |
|
|
|
|
|
#10 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,407
Thanks: 252
Thanked 975 times in 958 posts
|
Correct, that's what I understood and my recommendation still stands - print or plot the slope value you work so that you can actually visualize the condition you're setting up, this filter here is too hard to let any trades comes through, in other words - try a lower #, as this steep of a slope filter everything out.
&& Slope(anaHoltEMA(80, 20).HoltEMA, 10, 0) > 5
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Junior Member
Join Date: Nov 2012
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
I've input this:
protected override void OnBarUpdate() { // Condition set 1 if (Slope(anaHoltEMA(80, 20).HoltEMA, 10, 0) < #) { BarColor = Color.Black; } } Okay, I'm getting some results. But I had no idea I would be using slope values of 0.0002. When I go further the Wizard turns these values to 1E-05. How do I interpret that? Looks like I'm going to have to create 2 conditions to bracket the flat ma status (one + value, one - value).
Last edited by Shadowshorter; 02-19-2013 at 09:47 AM.
|
|
|
|
|
|
#12 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,407
Thanks: 252
Thanked 975 times in 958 posts
|
Glad to hear, yes at this point if you go further to lower slopes it would switch to scientific notation format - http://chemlabs.uoregon.edu/GeneralR..._notation.html
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Junior Member
Join Date: Nov 2012
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
Okay, got it. One more question. What do I need to add to this condition in order for the strategy to not take any trades when the ma slope is defined as flat without closing any already opened positions:
// Condition set 2 if (Slope(anaHoltEMA(80, 20).HoltEMA, 5, 0) < 0.00091 && Slope(anaHoltEMA(80, 20).HoltEMA, 2, 0) > -0.003) { BarColor = Color.Fuchsia; } I can't seem to do it in the wizard. Thanks
Last edited by Shadowshorter; 02-19-2013 at 03:17 PM.
|
|
|
|
|
|
#14 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,407
Thanks: 252
Thanked 975 times in 958 posts
|
Shadowshorter, if you have those slope condition with your entry sets, it should not influence the exits at all, so even those your flat conditions for non entry are triggered the current open trade would be held until other means take it out.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#15 |
|
Junior Member
Join Date: Nov 2012
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
Hi Bertrand,
Thanks for your time. But what do i need to add to tell my strategy to NOT take trades during this ma flat condition? The only thing I can get it to do is paint the bars concerned.but I have no idea what the right command is to say: IF ma is flat then take no trades. Thanks |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Add to ATM Strategy "Trailing "Limit"" | shawnj | Suggestions And Feedback | 2 | 10-10-2008 08:01 PM |
| "'OrderRejected'. Strategy has sent cancel requests" & "There is no market data..." | Elliott Wave | Strategy Development | 6 | 04-12-2008 12:03 AM |
| 2 instances of strategy when clicking "apply" and "okay" | dtf139 | Historical NinjaTrader 6.5 Beta Threads | 2 | 01-07-2008 11:25 PM |
| Control center "strategies" tab, "Positions tab, and "Market Analyzer" not | funk101 | Strategy Development | 6 | 04-10-2007 03:44 AM |
| Show "Flat" if an Overnight Trade is Closed | aspTrader | Miscellaneous Support | 6 | 05-10-2005 01:39 AM |