NexusFi: Find Your Edge


Home Menu

 





Coloring an IndicatorLine by Slope: Questions for Optimal Coding


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Fat Tails with 24 posts (87 thanks)
    2. looks_two stephenszpak with 12 posts (0 thanks)
    3. looks_3 Big Mike with 3 posts (4 thanks)
    4. looks_4 Trendseek with 3 posts (15 thanks)
      Best Posters
    1. looks_one Trendseek with 5 thanks per post
    2. looks_two Fat Tails with 3.6 thanks per post
    3. looks_3 NJAMC with 1.5 thanks per post
    4. looks_4 Big Mike with 1.3 thanks per post
    1. trending_up 28,557 views
    2. thumb_up 111 thanks given
    3. group 22 followers
    1. forum 59 posts
    2. attach_file 19 attachments




 
Search this Thread

Coloring an IndicatorLine by Slope: Questions for Optimal Coding

  #51 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


Rad4633 View Post
@Fat Tails

Sir, I was wondering do you have a combo indicator with the bollinger and keltner channels together? , Ive seen one months back that colors candles up or down based off bands and squeeze of both bollinger/keltner. Sorry no picture at this time but Im 100% sure you know what Im referring too

thx in advance for your reply
R


You can add both a UniversalKeltner and Universal Bollinger Band indicator to your chart. If you want to get alerted to a squeeze (Bollinger Band inside Keltner Channel), there is a squeez indicator in the downloads.

So far, I have not coded an indicator that combines both Bollinger Bands and Keltner Channels. I have posted a screenshot some time ago, of a multi-timeframe Keltner Channel. which shows a larger and smaller timeframe Keltner Channel.

Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Ninja Mobile Trader VPS (ninjamobiletrader.com)
Trading Reviews and Vendors
NexusFi Journal Challenge - April 2024
Feedback and Announcements
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Futures True Range Report
The Elite Circle
Better Renko Gaps
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
37 thanks
NexusFi site changelog and issues/problem reporting
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
The Program
19 thanks
  #52 (permalink)
 KrazyTrader 
Dallas, TX/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES, CL
Posts: 51 since Aug 2013
Thanks Given: 56
Thanks Received: 9

Can someone point me to the slope measurement for NT that Fat Tails references.

Reply With Quote
  #53 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102



KrazyTrader View Post
Can someone point me to the slope measurement for NT that Fat Tails references.

Slope is a geometrical measure that depends on the chart compression. With scalable charts, the concept of slope or angles is void.

In the past slope was used as a proxy for momentum. A "steep" trend line was showing that momentum over that period was high. A "flat" trendline would show that momentum was close to zero.

Momentum is just the size of the price move, where an upmove is seen as positive and a downmove is seen as negative momentum. Instead of the slope of a moving average or a linear regression line you would rather measure rise over run. Some explanations are here:

Slope [ChartSchool]

The absolute value of the rise over run does not tell you whether the market is trending or sideways. If you look at a 240 min chart the momentum measured over 20 bars can take much higher values, then the 20-bar momentum on a 1 min chart. Also the momentum depends on the tick value and volatility of an instrument.

Therefore to get a comprehensive and normalized measure for slope or steepness of a move, you need to put the size of that move into relationship with the average bar size. Divide the rise over run - or momentum - by either

- the SMA of the simple range over an extended lookback period
- the SMA of the average range over that lookback period
- or the standard deviation over that lookback period

and you will get a measure for the strength of a move that is coherent across all instruments and timeframes.

Reply With Quote
Thanked by:
  #54 (permalink)
 KrazyTrader 
Dallas, TX/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES, CL
Posts: 51 since Aug 2013
Thanks Given: 56
Thanks Received: 9


Fat Tails View Post
Slope is a geometrical measure that depends on the chart compression. With scalable charts, the concept of slope or angles is void.

In the past slope was used as a proxy for momentum. A "steep" trend line was showing that momentum over that period was high. A "flat" trendline would show that momentum was close to zero.

Momentum is just the size of the price move, where an upmove is seen as positive and a downmove is seen as negative momentum. Instead of the slope of a moving average or a linear regression line you would rather measure rise over run. Some explanations are here:

Slope [ChartSchool]

The absolute value of the rise over run does not tell you whether the market is trending or sideways. If you look at a 240 min chart the momentum measured over 20 bars can take much higher values, then the 20-bar momentum on a 1 min chart. Also the momentum depends on the tick value and volatility of an instrument.

Therefore to get a comprehensive and normalized measure for slope or steepness of a move, you need to put the size of that move into relationship with the average bar size. Divide the rise over run - or momentum - by either

- the SMA of the simple range over an extended lookback period
- the SMA of the average range over that lookback period
- or the standard deviation over that lookback period

and you will get a measure for the strength of a move that is coherent across all instruments and timeframes.

Fat Tails- words can not describe my thanks to you and your mentoring.

Reply With Quote
  #55 (permalink)
 
DavidHP's Avatar
 DavidHP 
Isla Mujeres, MX
Legendary Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Broker: Ninjatrader / Optimus Futures / AmpFutures
Trading: ES / 6E / 6B / CL
Frequency: Every few days
Duration: Minutes
Posts: 1,609 since Aug 2009
Thanks Given: 11,328
Thanks Received: 2,743


Fat Tails View Post
Slope is a geometrical measure that depends on the chart compression. With scalable charts, the concept of slope or angles is void.

@Fat Tails

I've monitored several of the posts on futures.io (formerly BMT) about angles and slopes and it all sounds reasonable considering the type of charts created by NT.

This made me think that maybe there are other considerations about this.

If a trendline is drawn on a tick chart, and lows or highs are connected in the series.
Many times if the lines are set to show on "ALL CHARTS" the lines are either off by a small to considerable amount on range or other chart types.
When trendlines are drawn on tick charts many times the duplicated trendline on a minute chart is totally off the scale.

Would this type of issue, invalidate trendlines?
Does that mean the concept of 'touches' of trendlines is just snake oil since it is dependent upon the type of chart and is not universal?
Or am I over thinking the issue?

Thanks for your response.

Rejoice in the Thunderstorms of Life . . .
Knowing it's not about Clouds or Wind. . .
But Learning to Dance in the Rain ! ! !
Follow me on Twitter Reply With Quote
  #56 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


DavidHP View Post
@Fat Tails

I've monitored several of the posts on futures.io (formerly BMT) about angles and slopes and it all sounds reasonable considering the type of charts created by NT.

This made me think that maybe there are other considerations about this.

If a trendline is drawn on a tick chart, and lows or highs are connected in the series.
Many times if the lines are set to show on "ALL CHARTS" the lines are either off by a small to considerable amount on range or other chart types.
When trendlines are drawn on tick charts many times the duplicated trendline on a minute chart is totally off the scale.

Would this type of issue, invalidate trendlines?
Does that mean the concept of 'touches' of trendlines is just snake oil since it is dependent upon the type of chart and is not universal?
Or am I over thinking the issue?

Thanks for your response.

You have correctly observed that the exact location of a trendline depends on the bar type and bar period. The same is true for a SMA. A SMA on a tick chart will be in a different location than the same period SMA on a minute chart. This does not entirely invalidate these tools for analyzing markets. However, if you apply such tools to exotic bar types, then it is questionable whether there is any support and resistance at the exact location where they print.

The main point to consider is that trendlines and moving averages and many other tools rely on self-fulfilling prophecy. A trendline will only produce a reaction, if that same trendline is watched by any other traders. If you are the only one to watch it on your exotic chart, then it may be well ignored.

This leads us to the question whether there are tools available that do not depend on the bar type and the bar period of a chart and help to find S/R on all charts at the same time. And yes, such tools exist. Please have a look at the VWAP, the market profile or the floor and GLOBEX pivots. But even these tools rely on self-fulfilling prophecy - swarm behaviour - to work.

Reply With Quote
  #57 (permalink)
 little leo 
Sydney
 
Experience: Advanced
Platform: NinjaTrader
Trading: Forex
Posts: 63 since Nov 2015
Thanks Given: 31
Thanks Received: 40

Sorry to re-open this old thread.

Imagine a strategy that buys a bullish candlestick pattern. I want to improve this strategy by only buying when the 20SMA is "rising". For that I've been using a very simple method.

 
Code
private bool IsMARising(int period, EnumMAType type)
{
	double dMA1 = MA(period, type, 0);
	double dMA2 = MA(period, type, 1);
	if (dMA1 > dMA2)
	{
		return true;
	}
	return false;
}
So to know if the 20SMA "is rising", I would call IsMARising(20, EnumMAType.Simple).

@Fat Tails posted a very nice indicator, the "Bollinger Universal V4" that correctly shows if a 20SMA is "rising".



What I would like to do is change my IsRising method to something like


 
Code
private bool IsMARising(int period, EnumMAType type)
{
	if( Fat Tail's indicator shows the line in green)
		return true;
	else
		return false;
}
I can see exactly on the OnBarUpdate of anaBollingerUniversal.cs where the lines are made Green, Red or Yellow.



However I don't know how to "output" this value so I could later on read it from within my IsMARising() method.

 
Code
// method called on OnBarUpdate. It will return true or false for the CurrentBar
private bool IsMARising(int period, EnumMAType type)
{
	// assume the instantiation was successful
	IndicatorBase ind = anaBollingerUniversal(Input, midbandMAType, numStdDev, period, smoothed, stdDevPeriod, threshold);
	// 1 = Up, 0 = Neutral, -1 = Down
	if(ind.TrendDirection > 0)
		return true;
	else 
		return false;
}
I tried to create a public property TrendDirection of this indicator, that would return 1,0 or -1, however I can't access it from within my strategy. This is a bit outside my skills, could anyone give a hand please?

I will keep trying and update if I manage to do it.

Thanks everyone for this excellent thread and thanks Fat Tail for the indicator.

Leo

Reply With Quote
  #58 (permalink)
 little leo 
Sydney
 
Experience: Advanced
Platform: NinjaTrader
Trading: Forex
Posts: 63 since Nov 2015
Thanks Given: 31
Thanks Received: 40

Here it is, it works great!

 
Code
private bool IsMARising(int period, EnumMAType type)
		{
			// convert between enums (because my strategy uses different enums for MA types)
			anaBollingerMAType midbandMAType;
			switch (type) 
			{
				case EnumMAType.SMA:
					midbandMAType = anaBollingerMAType.SMA;
					break;
				case EnumMAType.EMA:
					midbandMAType = anaBollingerMAType.EMA;
			}
			double numStdDev = 2.0; // not using, just interested in the MA
			bool smoothed = true;
			int stdDevPeriod = 20; // not using, just interested in the MA
			int threshold = 30; // Slope as percentage of average true range

			Indicator.anaBollingerUniversal ind = anaBollingerUniversal(midbandMAType, numStdDev, period, smoothed, stdDevPeriod, threshold);
			// line is green
			if (ind.Trend[0] > 0)
			{
				return true;
			}
			else {
				return false;
			}
			/* old code
			double dMA1 = MA(period, type, 0);
			double dMA2 = MA(period, type, 1);

			if (dMA1 > dMA2)
			{
				return true;
			}
			return false;
			*/
		}

Reply With Quote
  #59 (permalink)
 KrazyTrader 
Dallas, TX/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES, CL
Posts: 51 since Aug 2013
Thanks Given: 56
Thanks Received: 9


little leo View Post
Here it is, it works great!

 
Code
private bool IsMARising(int period, EnumMAType type)
		{
			// convert between enums (because my strategy uses different enums for MA types)
			anaBollingerMAType midbandMAType;
			switch (type) 
			{
				case EnumMAType.SMA:
					midbandMAType = anaBollingerMAType.SMA;
					break;
				case EnumMAType.EMA:
					midbandMAType = anaBollingerMAType.EMA;
			}
			double numStdDev = 2.0; // not using, just interested in the MA
			bool smoothed = true;
			int stdDevPeriod = 20; // not using, just interested in the MA
			int threshold = 30; // Slope as percentage of average true range

			Indicator.anaBollingerUniversal ind = anaBollingerUniversal(midbandMAType, numStdDev, period, smoothed, stdDevPeriod, threshold);
			// line is green
			if (ind.Trend[0] > 0)
			{
				return true;
			}
			else {
				return false;
			}
			/* old code
			double dMA1 = MA(period, type, 0);
			double dMA2 = MA(period, type, 1);

			if (dMA1 > dMA2)
			{
				return true;
			}
			return false;
			*/
		}


I'm attempting the same thing with @Fat Tails Keltner Universal indicator. Did you add code to anaBollinger or is this a separate indicator reference anaBollinger?

Thanks.

Difference between discomfort and pain = 1 tick
Reply With Quote
Thanked by:
  #60 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102



KrazyTrader View Post
I'm attempting the same thing with @Fat Tails Keltner Universal indicator. Did you add code to anaBollinger or is this a separate indicator reference anaBollinger?

Thanks.


Those indicators already come with a public property that allows for catching the trend. The public property is called Trend and can take the three values

+1 for an uptrend (blue)
- 1 for a downtrend (red)
0 for a neutral trend (gray)

The trend is based on the slope of the midline of the channel.

You can directly access these values via the Strategy Builder, the Market Analyzer or another indicator. You do not need to code anything. The public property Trend is available with both the Bollinger Universal and the Keltner Universal indicators.

Below is a picture showing the three different trend states.

It is possible to use the indicator with two trend states only (uptrend or downtrend). This can be achieved by setting the neutral threshold parameter to 0.



Reply With Quote
Thanked by:




Last Updated on May 25, 2016


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts