NexusFi: Find Your Edge


Home Menu

 





MACD, RSI, CCI indicators with different time frames, coding help?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Fat Tails with 3 posts (6 thanks)
    2. looks_two SirNicolaus with 2 posts (0 thanks)
    3. looks_3 hector24 with 2 posts (1 thanks)
    4. looks_4 viktor17 with 2 posts (0 thanks)
    1. trending_up 13,582 views
    2. thumb_up 7 thanks given
    3. group 6 followers
    1. forum 11 posts
    2. attach_file 2 attachments




 
Search this Thread

MACD, RSI, CCI indicators with different time frames, coding help?

  #1 (permalink)
 hector24 
austin, texas
 
Experience: Intermediate
Platform: ninja trader
Trading: currency futures
Posts: 506 since Jan 2011
Thanks Given: 14
Thanks Received: 234

I was wondering if anyone knows how to code something that could be beneficial to everyone. Currently there is an indicator called Visual EMA and one called Visual SMA. These indicators allow you to see the moving averages of another time frame on the same chart that you have up. Example if you have a 5 minute chart up you can apply one these indicators to get a moving average from a 15 minute chart. I was thinking that maybe someone could code the same concept but have parameters that would let you choose another indicator like a MACD, RSI, CCI or the like. So you could have a 15 minute RSI on your 5 minute chart. Just wondering if this can be done. If anyone could help, it would be appreciated.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
NexusFi Journal Challenge - April 2024
Feedback and Announcements
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
38 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
GFIs1 1 DAX trade per day journal
19 thanks
The Program
18 thanks
  #2 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,397 since Jun 2009
Thanks Given: 33,173
Thanks Received: 101,537

Already done, MTF anything here:



Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #3 (permalink)
 
Zondor's Avatar
 Zondor 
Portland Oregon, United States
 
Experience: Beginner
Platform: Ninjatrader®
Broker: CQG, Kinetick
Trading: Gameplay Klownbine® Trading of Globex
Posts: 1,333 since Jul 2009
Thanks Given: 1,246
Thanks Received: 2,731


Using a 1 period VISUAL SMA in the desired higher time frame as the input of your RSI or whatever DOES NOT seem to work.

I think you would need to call the methods of the AccessVisualSMA indicator from within the RSI etc. Maybe I will fool around with that at some point.

"If we don't loosen up some money, this sucker is going down." -GW Bush, 2008
“Lack of proof that something is true does not prove that it is not true - when you want to believe.” -Humpty Dumpty, 2014
“The greatest shortcoming of the human race is our inability to understand the exponential function.”
Prof. Albert Bartlett
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
 hector24 
austin, texas
 
Experience: Intermediate
Platform: ninja trader
Trading: currency futures
Posts: 506 since Jan 2011
Thanks Given: 14
Thanks Received: 234

Thanks Mike but that does not have the selection parameters that I was thinking about. But thanks anyways.
Zondor thanks I will look into that.

Thanks,
Hector

Started this thread Reply With Quote
Thanked by:
  #5 (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


Zondor View Post
Using a 1 period VISUAL SMA in the desired higher time frame as the input of your RSI or whatever DOES NOT seem to work.

I think you would need to call the methods of the AccessVisualSMA indicator from within the RSI etc. Maybe I will fool around with that at some point.

@Zondor: The VisualSMA repaints back to the last node, if it used in Visual mode. The number of bars that it repaints are exposed, so you can access it via an access indicator. In One-Tick-Correction mode, it repaints 1 bar, in strategy mode it does not repaint at all, which leads to a lag of one bar and does not allow for visual interpolation.

Let us remind that MTF indicators are only needed to avoid non-equidistant bar spacing. Otherwise you can add a transparent secondary bar series to your chart and use it for calculating indicator values.

If you want to avoid non-equidistant bar spacing, there are three paths that lead to the desired outcome:

(1) a multi-timeframe indicator that loads a secondary bar series (type XavMTF or VisualSMA)
(2) a multi-timeframe indicator that first calculates composite bars from N consecutive bars and then calculates the indicator values for those composite bars
(3) directly tweaking the formula

Let us for example take a MACD. The chart below shows a 5 min chart with the MACD calculated for 5 min bars (1x Cornflower), 15 min bars (3x white), 30 min bars (6x, orange), 60 min bars (12x violet red). The MACDs on the midpanel are calculated from composite bars - as MetaTrader does. The MACDs on the lower panel is built from tweaked moving averages. The tweaking was obtained by replacing the period N_old of the EMA for a timeframe multiplier M with the period N_new

k_old = 2/(N_old + 1)
k_new = 1 - Power(1 - k_old, 1/M)
N_new = 2/k_New - 1

You can tweak the formulae of many indicators, the period can be calculated in OnStartUp(), therefore the tweaked indicator is faster to calculate than the one built from composite bars. None of them is a genuine MTF indicator, but they can be used for the same purpose. And both of them can be easily used as a trendfilter in a strategy.


Reply With Quote
  #6 (permalink)
 SirNicolaus 
Rochester, NY, United States
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Futures
Posts: 6 since Dec 2012
Thanks Given: 8
Thanks Received: 0

Is there an easy way to take for example a MACD plot from mutliple MACDs and average them into 1 plot then smooth em and post them to the chart as an ema??

example

Fast1 = 1
Slow1 = 4
Smooth1 = 8

Take the plot of the MACD = macd0

Fast2 = 4
Slow2 = 8
Smooth2 = 8

Take plot from macd = int macd1

etc take 4 plots then average them into 1 int output as EMA in an indicator?

Is this doable?

Thanks guys

This is my first post... so if i am in the wrong place just let me know... thanks

Reply With Quote
  #7 (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


SirNicolaus View Post
Is there an easy way to take for example a MACD plot from mutliple MACDs and average them into 1 plot then smooth em and post them to the chart as an ema??

example

Fast1 = 1
Slow1 = 4
Smooth1 = 8

Take the plot of the MACD = macd0

Fast2 = 4
Slow2 = 8
Smooth2 = 8

Take plot from macd = int macd1

etc take 4 plots then average them into 1 int output as EMA in an indicator?

Is this doable?

Thanks guys

This is my first post... so if i am in the wrong place just let me know... thanks

@SirNicolaus: The MACD is an oscillator. You cannot average an oscillator into EMAs.

Also, I doubt that if you take a collection of EMAs and calculate the average of those EMAs that you will get a better EMA.

And then the EMA will only tell you what happened in the past. It is a bad predictor. For details see that book by David Aronson : Evidence Based Technical Analysis.

Reply With Quote
Thanked by:
  #8 (permalink)
 SirNicolaus 
Rochester, NY, United States
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Futures
Posts: 6 since Dec 2012
Thanks Given: 8
Thanks Received: 0


Fat Tails View Post
@SirNicolaus: The MACD is an oscillator. You cannot average an oscillator into EMAs.

Also, I doubt that if you take a collection of EMAs and calculate the average of those EMAs that you will get a better EMA.

And then the EMA will only tell you what happened in the past. It is a bad predictor. For details see that book by David Aronson : Evidence Based Technical Analysis.

well i know when i put 4 MACD on a chart and only show the macd plot i can see it trending and was hoping to combine and average those macd plots into 1 plot... if the plot is a ma EMA HMA i don't care i just want the visual movement and or bar painting

i am looking for divergence across multiple macds but less clutter

Thanks for the Recommended book i will look into it...

Reply With Quote
  #9 (permalink)
viktor17
Prague, Czech Republic
 
Posts: 2 since Feb 2015
Thanks Given: 1
Thanks Received: 0

Hi Fat Tails,

I was trying to modify/tweak MACD indicator based on your formula, but I'm not able to find out what is 'k_old' and 'n_old'. I was trying to change MACD indicator directly from ninjatrader 7. Can you please help me what to exactly change (I'm primary using 5min ES and I want to access MACD of 15min ES) or can you please send me source code of indicator which generated your picture (with tweaked) MACDs?

I can't submit post with links(your image submitted in your post January 7th, 2013 11:39 PM) , because of forum rules - this is my the first post.

Thank you
viktor


Fat Tails View Post
@Zondor: The VisualSMA repaints back to the last node, if it used in Visual mode. The number of bars that it repaints are exposed, so you can access it via an access indicator. In One-Tick-Correction mode, it repaints 1 bar, in strategy mode it does not repaint at all, which leads to a lag of one bar and does not allow for visual interpolation.

Let us remind that MTF indicators are only needed to avoid non-equidistant bar spacing. Otherwise you can add a transparent secondary bar series to your chart and use it for calculating indicator values.

If you want to avoid non-equidistant bar spacing, there are three paths that lead to the desired outcome:

(1) a multi-timeframe indicator that loads a secondary bar series (type XavMTF or VisualSMA)
(2) a multi-timeframe indicator that first calculates composite bars from N consecutive bars and then calculates the indicator values for those composite bars
(3) directly tweaking the formula

Let us for example take a MACD. The chart below shows a 5 min chart with the MACD calculated for 5 min bars (1x Cornflower), 15 min bars (3x white), 30 min bars (6x, orange), 60 min bars (12x violet red). The MACDs on the midpanel are calculated from composite bars - as MetaTrader does. The MACDs on the lower panel is built from tweaked moving averages. The tweaking was obtained by replacing the period N_old of the EMA for a timeframe multiplier M with the period N_new

k_old = 2/(N_old + 1)
k_new = 1 - Power(1 - k_old, 1/M)
N_new = 2/k_New - 1

You can tweak the formulae of many indicators, the period can be calculated in OnStartUp(), therefore the tweaked indicator is faster to calculate than the one built from composite bars. None of them is a genuine MTF indicator, but they can be used for the same purpose. And both of them can be easily used as a trendfilter in a strategy.


Reply With Quote
  #10 (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



viktor17 View Post
Hi Fat Tails,

I was trying to modify/tweak MACD indicator based on your formula, but I'm not able to find out what is 'k_old' and 'n_old'. I was trying to change MACD indicator directly from ninjatrader 7. Can you please help me what to exactly change (I'm primary using 5min ES and I want to access MACD of 15min ES) or can you please send me source code of indicator which generated your picture (with tweaked) MACDs?

I can't submit post with links(your image submitted in your post January 7th, 2013 11:39 PM) , because of forum rules - this is my the first post.

Thank you
viktor


Maybe that my description was not very clear. I will take your example. You wish to access a MACD calculated from a 15 min chart on a 5 min chart. This means that there is a timeframe multiplier of M = 3. The MACD is basically built from two exponential moving averages. The signal line itself is an exponential moving average of the MACD. As we know, exponential moving averages use a smoothing constant of

k = 2/(1+n)

where n is the period of the moving average. It is also possible to use a smoothing constant of k= 1/n. This was the solution adopted by Welles Wilder and is known as Wilder's Average. The now prevailing formula of k= 2/(1+n) was chosen by Jack Hutson (see Stocks & Commodities, Volume 2, Issue March 1984) to harmoize the average age of data for simple and exponential moving averages. The coefficient k is used to calculate the current value of the exponential moving average via a recursive formula

(1) ...... EMA[0] = k*Close[0] + (1-k)*EMA[1]

where EMA[0] is the current value of the moving average and EMA[1] is the previous value of the moving average. Now let us come back to the task to calculate an EMA from the 15 min bars. In this case you would need to take every third bar to perform the calculations

(2) ...... EMA[0] = k*Close[0] + (1-k)*EMA[3]

Now I look for an appropriate q to replace (2) with (1):

(3) ...... EMA[0] = q*Close[0]+(1-q)*EMA[1] = q*Close[0]+(1-q)*q*Close[1]+(1-q)*(1-q)*EMA[2] = q*Close[0]+(1-q)*q*Close[1]+(1-q)*(1-q)*q*Close[2]+(1-q)*(1-q)*(1-q)*EMA[3]

The 15 minute chart does not have the resolution of the 5 min chart, hence I replace Close[1] and Close[2] with Close[0]. However, I am mostly interested in the last term (1-q)*(1-q)*(1-q)*EMA[3], because this term tells me to what extent prior price action is taken into account. Therefore to obtain the 5 min smoothing constant q from my 15 min smoothing constant k, it is necessary that

(4) ...... (1-q)*(1-q)*(1-q) = 1 - k -> q = 1 - Math.Pow(1-k, 1/3)


This is the equation that allows me to obtain the smoothing constant required to display the 15-min EMA on a 5-min chart. Now let us take a MACD(12,26,9) on a 15 min chart. We wish to display this MACD on a 5-min chart.

The smoothing constants for the EMAs are

k1 = 2 /(12 +1) = 2/13 = 0.1538
k2 = 2/(26 +1) = 2/27 = 0.0741
k3 = 2/(9 +1) = 2/10 = 0.2000

By applying the formula above we can now calculate the smoothing constants required for displaying that same EMA on a 5-min chart

q1 = 1 - Math.Pow(1-0.1538, 1/3) = 1 - 0.9458 = 0.0542
q2 = 1 - Math.Pow(1-0.0741, 1/3) = 1 - 0.9747 = 0.0253
q3 = 1 - Math.Pow(1-0.2000, 1/3) = 1 - 0.9283 = 0.0717

q1, q2 and q3 are the three smoothing constants which you need to use to calculate the 3 exponential moving averages. With q = 2/(n+1) you may also calculate the periods as n = 2/q - 1

n1 = 2/0.0542 - 1 = 35.90
n2 = 2/0.0253 - 1 = 78.05
n3 = 2/0.0717 - 1 = 26.89

The solution of the puzzle is that you can approximate your MACD (12,26,9) calculated from 15 min bars with a MACD(35.90, 78.05, 26.89) calculated from a 5 min chart. Please note that broken (non-integer) periods are allowed for exponential moving averages, but that the default EMA/MACD do not support them.

Now let us compare the outcome. The chart below has loaded a secondary bar series of 15-min bars which I have set to transparent. You will find the tweaked (high definition) MACD calculated from 5 minute data and below the original MACD calculated from 15 min data. As you can see, the tweaked version is an excellent approximation of the original MACD and is fit for all practical purposes.


Reply With Quote
Thanked by:




Last Updated on February 29, 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