Coloring an IndicatorLine by Slope: Questions for Optimal Coding - NinjaTrader Programming | futures io social day trading
futures io futures trading


Coloring an IndicatorLine by Slope: Questions for Optimal Coding
Updated: Views / Replies:14,445 / 59
Created: by Trendseek Attachments:19

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 19  
 
Thread Tools Search this Thread
 

Coloring an IndicatorLine by Slope: Questions for Optimal Coding

  #1 (permalink)
Elite Member
Leipzig / Germany
 
Futures Experience: Intermediate
Platform: NT / TS, MC and Clones
Broker/Data: Interactive Broker
Favorite Futures: Futures, Forex
 
Posts: 24 since Aug 2009
Thanks: 31 given, 34 received

Coloring an IndicatorLine by Slope: Questions for Optimal Coding

Hi there,

There is an easy Job to Do:
If an IndicatorLine ist rising, mark it in a different Color as if the Indicator is falling. Unfortunately there are some Problems and Questions - and perhaps some serious Coding-Traps in NT-Code

At First a general Note about Painting: Painting on the Chart slowing Down your Trading-System - therefore be aware, to use only necessary Drawing-Objects on your Chart. Like a slope- or a Signal-depending coloring of an Indicator.

In the attached Code you will find three different Methods to calculate the Slope and one easy-to-understand - and hopefully not ressource-intensive - Method to Plot a different colored Indicator-Line: If the Line is rising, it would be painting green, if it is falling it will be painting in red and if the slope is less than a Threshold, the Line will be painting in white.

Unfortunaly all three Methods dont work!

As you can see below, the attached Code shows an average RSI with a colored IndicatorLine - but also a rising Indicator is painted in red, and a falling indicator is painting in green
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Here are my Questions:
1) What goes wrong with the Code?
2) Do you know a less ressource-intensive Method for Painting?


Best
Trendseek

Attached Files
Register to download File Type: zip ColoredRSI.zip (6.4 KB, 65 views)
Reply With Quote
The following 2 users say Thank You to Trendseek for this post:
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,651 since Mar 2010
Thanks: 4,226 given, 25,597 received
Forum Reputation: Legendary


Coloring an indicator by slope is pretty simple. Let us assume that you want to color the first PlotSeries of an indicator, which is called Values[0]. Then you need to define two colors, "upColor" and "downColor", which you use for coloring the slope.

You will then need to take into account three cases: rising slope, falling slope, zero slope. Here is the code

 
Code
if (CurrentBar > 0)
{
       if(Values[0][0] > Values [0][1])  
                 PlotColors[0][0] = upColor;
       else if (Values[0][0] < Values[0][1])
                 PlotColors[0][0] = downColor;
       else 
                 PlotColors[0][0] = PlotColors[0][1];
}
Attached is an example for an indicator, which colors the indicator plot and the paint bars based on slope.

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Attached Files
Register to download File Type: zip T3Slope.zip (4.6 KB, 156 views)
Reply With Quote
The following 13 users say Thank You to Fat Tails for this post:
 
  #4 (permalink)
Elite Member
Leipzig / Germany
 
Futures Experience: Intermediate
Platform: NT / TS, MC and Clones
Broker/Data: Interactive Broker
Favorite Futures: Futures, Forex
 
Posts: 24 since Aug 2009
Thanks: 31 given, 34 received

Thx FatTails

That was an impressive Example!

The Source for the correct NT - Plot Statement will be found here:
NT MultiColor Plot Approach - NinjaTrader Support Forum

The Syntax for the Plot-Command:
PlotColors[x][y] = z;
x = Value or "Plot-Index" of the plotted Line (you have defined it in the Properties-Region of the Code)
y = Offset or "Bars Back" of the plottet Line (<--- this was wrong in my Code!)

As Attachment you will find the corrected Codesample.

Next I will give some example for ressource-saving Programming...
Perhaps somebody have some suggestions?

Regards
Trendseek

Attached Files
Register to download File Type: zip RSIColoredv2.zip (6.4 KB, 60 views)
Reply With Quote
 
  #5 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,651 since Mar 2010
Thanks: 4,226 given, 25,597 received
Forum Reputation: Legendary

Coloring According to Slope with a Neutral Zone

If you create an indicator, it should be coded in a consistent way. Your approach to use the ticksize for normalizing slope is inconsistent. Why?

(1) An indicator should have the same or similar settings for different instruments. Or do you have to set the overbought level for the RSI to 30 for ES 03-12 but to 20 to YM 03-12?

(2) Further an indicator should have the same or similar settings for different timeframes. You do not want to use different settings on a 60 min chart then on a 1 min chart.

An example for a royal failure of coloring slopes is the MASlopeMulti V2.83 indicator, which can be found here. It uses the ticksize for normalization and what you get is simply inconsistent. @Erez: The indicator is excellent, I am just talking about the idea to use ticksize for scale normalization.

Below are attached two charts to show how that inconsistency plays out. The first chart compares YM 03-12 to ES 03-12. YM's ticksize relative to volatility is 2.5 times smaller than the tick size of ES. Due to that smaller ticksize, you will notice that with identical indicator settings

-> YM always shows larger angles than ES
-> the neutral zones are much smaller than for ES
-> the percentage of rising and falling zones over the chart is higher than for ES

The second chart shows a 60 min chart of YM with the same settings. The neutral zones now have disappeared altogether, because they are so small that they will not even survive the change of an angle between two bars. Also note that on a 60 min chart, all angles are much larger than on a 5 min chart.

Conclusion: The ticksize is not suited at all to normalize slopes and angles.

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Reply With Quote
The following 10 users say Thank You to Fat Tails for this post:
 
  #6 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,651 since Mar 2010
Thanks: 4,226 given, 25,597 received
Forum Reputation: Legendary

Example for an Indicator Colored Based on Slope Including a Neutral Zone

If we want to define a neutral zone for the slope, we have to check the slope against volatility. This can be done by using any measure for volatility, for example

-> average true range
-> average range
-> standard deviation

But don't use the ticksize. Attached is an example of an experimental study to color the slope of the midband and the channel lines of the Bollinger Bands. The indicator uses the average true range to normalize slope and has a number of options. For example you may color the channel lines according to their own slope, or according to the slope of the midband.

This indicator is consistent across instruments and timeframes. You can use the same setting for YM 03-12 and ES 03-12, irrespective of their different tick sizes. And if you apply that indicator to a 60 min chart of YM, the neutral zone will not dissolve into nothing. Chart and indicator attached.

@Trendseek: Would like to know, whether you will apply that method to the RSI.

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Attached Files
Register to download File Type: zip BollingerUniversalX.zip (30.2 KB, 174 views)
Reply With Quote
The following 15 users say Thank You to Fat Tails for this post:
 
  #7 (permalink)
Elite Member
Naperville IL
 
Futures Experience: Intermediate
Platform: ninjatrader
Broker/Data: NT broker
Favorite Futures: NQ ES 6E GC CL
 
Posts: 954 since Feb 2010
Thanks: 1,184 given, 650 received

Hi

Is it possible to put an alert when price breaks BB, the alert can be a letter, color sign? Thanks

Reply With Quote
 
  #8 (permalink)
Elite Member
Leipzig / Germany
 
Futures Experience: Intermediate
Platform: NT / TS, MC and Clones
Broker/Data: Interactive Broker
Favorite Futures: Futures, Forex
 
Posts: 24 since Aug 2009
Thanks: 31 given, 34 received

One more Step Ahead

As promised, here comes a code-example with ressource-optimized code for calculating our Custom-RSI-Indicator and Plotting the Results on the Chart. You will find the new Indicator-Version attached at this posting.

Beside Questions aboute Code-Optimizing Issues aboute a suitable adaption of the Slope-Calculation is the second Focus, setting by this Thread. Thanks @Fat Tails for his critical and helpfull advices about diffent Methods for a better definition of the neutral-Zone. All of them has advantages and disadvantages - like the TickSize Methode. I will discuss this below.

Lets outline the Main Points of our new Custom RSI-Indicator:

First Topic: To reduce the consumption of ressources ...
a) use the new NT7- Plotmethod !!!
NT MultiColor Plot Approach - NinjaTrader Support Forum

b) Plot- Print- and Draw Methods are ressource-intensive. Use them rarely, they will slow-down your System-Speed dramatically!

c) If possible, use Core-Indicators directly (via initalisition) to speed up your System (--> see the latest Code-Example)

Second Topic: For a proper use of slope-depending coloring use an adaquate THEORY-DRIVEN method to normalize the Slope-Value, that could be founded on volatility-related Aspects of the Indicator and the Chart.
In our Example the RSI is a standardized Indicator. It does not access on Instrument-related aspects like TickSize or the used Timeframe.
Because of the fixed Range of the RSI (the values oscillate between 0 and 100) we even need no more Information about the Volatility.

Below you see a Chart with our latest RSI-based Indicator:
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Our theoretical thoughts about the volatility of the Indicator and the standardization of the slope are simple:
The RSI is a standardized Indicator - you dont need the TickSize of the Instrument or the Volatility of the RSI-Values. The RSI-Values oscillate between 0 and 100 or 30 and 70. (<--- This are the thresholds). For our Example the Range is: 70 - 30 = 40.

Therefore "40" is our Base to normalize the Slope-Values for the avgRSI and middleRSI. If you like, you can insert an adjustment, to consider the higher "smoothness" of the middleRSI and the SD-Bands which will result in lower slope-Values (I dont do that).

---> With this standardization -multiplied with 100- the rise and decline of the Lines between the Bars ( - the slopes - ) could be read as percentage.

Next time I (hopefully) will discussed, (1) how we could insert Tradingsignals into the Code, and which kind of Signal-Presentation are suitable for a ressource-optimized Indicator-Code. (2) Second I spend some more thoughts about the advantages and disadvantages of the different Methods for Sloping.

Regards
Trendseek

Attached Files
Register to download File Type: zip RSIColoredv3.zip (10.8 KB, 123 views)

Last edited by Trendseek; February 19th, 2012 at 09:39 AM.
Reply With Quote
The following 13 users say Thank You to Trendseek for this post:
 
  #9 (permalink)
Elite Member
Atkinson, NH USA
 
Futures Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker/Data: NinjaTrader Brokerage
Favorite Futures: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,925 since Dec 2010
Thanks: 2,962 given, 2,294 received


Fat Tails View Post
If you create an indicator, it should be coded in a consistent way. Your approach to use the ticksize for normalizing slope is inconsistent. Why?

(1) An indicator should have the same or similar settings for different instruments. Or do you have to set the overbought level for the RSI to 30 for ES 03-12 but to 20 to YM 03-12?

(2) Further an indicator should have the same or similar settings for different timeframes. You do not want to use different settings on a 60 min chart then on a 1 min chart.

An example for a royal failure of coloring slopes is the MASlopeMulti V2.83 indicator, which can be found here. It uses the ticksize for normalization and what you get is simply inconsistent. @Erez: The indicator is excellent, I am just talking about the idea to use ticksize for scale normalization.

Below are attached two charts to show how that inconsistency plays out. The first chart compares YM 03-12 to ES 03-12. YM's ticksize relative to volatility is 2.5 times smaller than the tick size of ES. Due to that smaller ticksize, you will notice that with identical indicator settings

-> YM always shows larger angles than ES
-> the neutral zones are much smaller than for ES
-> the percentage of rising and falling zones over the chart is higher than for ES

The second chart shows a 60 min chart of YM with the same settings. The neutral zones now have disappeared altogether, because they are so small that they will not even survive the change of an angle between two bars. Also note that on a 60 min chart, all angles are much larger than on a 5 min chart.

Conclusion: The ticksize is not suited at all to normalize slopes and angles.

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Hi @Fat Tails;

Great discussion. I totally agree. Indicators are applied across many different instruments and they should "behave" the same way regardless of the instrument.

Your point hits home about angle. I have seen this calculated many different ways but haven't thought much about the consistancy. I think I convinced myself to use "Ticks" rather and "TickSize" or Price in calculating angles. When I first thought of it, it seemed to not agree visually on the charts (if plotted), but seemed to make sense from an "Apples to Apples" comparison across instruments.

Do you agree with this approach of do you feel there is a better way to calculate slope?

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Reply With Quote
 
  #10 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,651 since Mar 2010
Thanks: 4,226 given, 25,597 received
Forum Reputation: Legendary



NJAMC View Post
Hi @Fat Tails;

Great discussion. I totally agree. Indicators are applied across many different instruments and they should "behave" the same way regardless of the instrument.

Your point hits home about angle. I have seen this calculated many different ways but haven't thought much about the consistancy. I think I convinced myself to use "Ticks" rather and "TickSize" or Price in calculating angles. When I first thought of it, it seemed to not agree visually on the charts (if plotted), but seemed to make sense from an "Apples to Apples" comparison across instruments.

Do you agree with this approach of do you feel there is a better way to calculate slope?

"Slope" does not exist on scalable charts. The concept "Slope" refers to print outs and was used 50 years ago when charts were printed and neither the time scale nor the price scale were ever changed.


Slope is just a visualization of momentum

Let us take a 20-period SMA. Then the slope of this SMA is the visualization of

-> slope = (last value of SMA - prior value of SMA) / (time between two bars if the chart)

On a chart with a fixed time scale, the denominator never changes, so slope is a proxy for

-> last value of SMA - prior value of SMA = last price - price twenty bars ago = momentum

This shows that slope in the end is just a visualization of momentum, nothing else. With electronic charting software nobody needs angles and slope boxes, you just need to measure momentum. Momentum is the first derivative of price and measures the price change.

Normalizing price change means to compare the price change to the average or the typical change. This means that you have to divide price change by volatility. Volatility can be measured by the average true range, the average range or the standard deviation or any comparable measure.


Ticks are not suited to normalize momentum or slope

But ticks or tick size are not at all suited, because the ticks do not reflect volatility. A simple example shows that ticks do not work:

The daily ATR(20) of ES currently is 16 points or 64 ticks. The daily ATR of YM currently is 139 points or 139 ticks. If you compare the slope of a moving average for both instruments, you should approximately find the same result, as both instruments are index futures and are highly correlated. However, if you divide by the number of ticks, you will have a problem, as YM moves 139 ticks per day, and ES only moves 64 ticks per day.
Therefore you will find much larger angles for ES as compared to YM, which is obviously nonsense.

Forget the ticks, you cannot use them for normalization. And best forget the concept of slope, angles and remember that they were just used to visualize momentum, when charts were printed.

Reply With Quote
The following 13 users say Thank You to Fat Tails for this post:

Reply



futures io > > > > > Coloring an IndicatorLine by Slope: Questions for Optimal Coding

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Some Basic NinjaTrader Coding Questions -- IDataSeries Crow NinjaTrader Programming 7 October 15th, 2017 04:49 AM
Tricky NinjaScript coding {questions} . . . jmejedi NinjaTrader Programming 10 August 2nd, 2014 10:09 PM
InvestorRT axis label coloring Big Mike Investor/RT 3 August 18th, 2011 07:53 AM
NT MA with BG coloring emini_Holy_Grail NinjaTrader 10 January 11th, 2011 07:29 AM
On finding the optimal settings for a range interval trendisyourfriend The Elite Circle 5 December 7th, 2010 02:53 PM


All times are GMT -4. The time now is 12:26 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-10 in 0.17 seconds with 20 queries on phoenix via your IP 54.90.207.75