NexusFi: Find Your Edge


Home Menu

 





Convert MQ4 to Ninjatrader


Discussion in NinjaTrader

Updated
    1. trending_up 4,984 views
    2. thumb_up 15 thanks given
    3. group 3 followers
    1. forum 14 posts
    2. attach_file 8 attachments




 
Search this Thread

Convert MQ4 to Ninjatrader

  #11 (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

I have reviewed the Chande Kroll Stop in detail, and there are basically two points to consider:


Formula used for average true range

The book "The New Technical Trader" by Tushar Chande and Stanley Kroll was published in 1994. Chapter 7 "Controlling Risk: The Key To Profitablity" has the stop explained under the label "Volatility-Based Trailing Stops". From the text it becomes clear that Chande and Kroll have used a 10-period simple moving average of the true range.

The Chande Kroll Stop as implemented by ProRealTime relies on Wilder's ATR(10), which is an exponential moving average of the true range with a smoothing constant k = 0.1.

The third option would be a 10-period exponential moving average with a smoothing constant of k = 0.182.

All three options will be available for the NinjaTrader implementation of the Chande Kroll stop. The original formula used by Chande and Kroll will be the default option ("Arithmetic").


Intra-bar calculation of the ATR

Nearly all volatility based trailing stops are not designed for trading them intra-bar. An average true range should not be calculated when the current bar is still incomplete. In fact with the first tick of a new bar, the true range for that bar is usually zero or close to zero. The result is an instant drop of the ATR(10) of about 10%. Such a drop in volatility may lead to an adjustment of the stop and even trigger a breach of the stopline. However, it is not the stopline that should approach price due to a discontinuity in the formula, but it is price which should either move the stop along or breach it.

The first solution that came to my mind was to use the average true range calculated one bar ago. However, this approach would not work correctly for large breakout bars, as the stop would not take into account the volatility of the breakout. Therefore I have settled for a solution where I use the greater of the ATR(10) calculated for the prior and calculated for the current bar. This solution is the only easy way to calculatw the Chande Kroll Stop intra-bar and does not violate the original idea of its creators. Nevertheless, in case that you wish to use the indicator with setting "CalculateOnBarClose = True", you may revert to the original formula which is labeled "Current_Bar". The modified formula labeled "Current_And_Prior_Bar" will be chosen as the default setting.


Keeping it simple

The indicator is best used with default settings. However, if you wish to compare it with indicators of other software packages such as ProRealTime, you will find the options to make it compatible. For example, if you wish to show the indicator as it does in the ProRealTime version, you would select Wilder's smoothing for the ATR (not in line with the original stop) and would further calculate the ATR for the "Current_Bar" (and should not set the indicator to "COBC=False").


Comparison 1: Original ATR formula (blue & firebrick, solid) versus Wilder's smoothing (black & purple, dashdot)




Comparison 2: Modified default formula (blue & firebrick, solid) versus original formula (black & purple, dashdot)


Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Deepmoney LLM
Elite Quantitative GenAI/LLM
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Futures True Range Report
The Elite Circle
Better Renko Gaps
The Elite Circle
Exit Strategy
NinjaTrader
 
  #12 (permalink)
 Realtimetrader 
Overijssel
 
Experience: Master
Platform: Ninja
Trading: FDAX
Posts: 15 since Aug 2010
Thanks Given: 4
Thanks Received: 2


Fat Tails View Post
I have reviewed the Chande Kroll Stop in detail, and there are basically two points to consider:


Formula used for average true range

The book "The New Technical Trader" by Tushar Chande and Stanley Kroll was published in 1994. Chapter 7 "Controlling Risk: The Key To Profitablity" has the stop explained under the label "Volatility-Based Trailing Stops". From the text it becomes clear that Chande and Kroll have used a 10-period simple moving average of the true range.

The Chande Kroll Stop as implemented by ProRealTime relies on Wilder's ATR(10), which is an exponential moving average of the true range with a smoothing constant k = 0.1.

The third option would be a 10-period exponential moving average with a smoothing constant of k = 0.182.

All three options will be available for the NinjaTrader implementation of the Chande Kroll stop. The original formula used by Chande and Kroll will be the default option ("Arithmetic").


Intra-bar calculation of the ATR

Nearly all volatility based trailing stops are not designed for trading them intra-bar. An average true range should not be calculated when the current bar is still incomplete. In fact with the first tick of a new bar, the true range for that bar is usually zero or close to zero. The result is an instant drop of the ATR(10) of about 10%. Such a drop in volatility may lead to an adjustment of the stop and even trigger a breach of the stopline. However, it is not the stopline that should approach price due to a discontinuity in the formula, but it is price which should either move the stop along or breach it.

The first solution that came to my mind was to use the average true range calculated one bar ago. However, this approach would not work correctly for large breakout bars, as the stop would not take into account the volatility of the breakout. Therefore I have settled for a solution where I use the greater of the ATR(10) calculated for the prior and calculated for the current bar. This solution is the only easy way to calculatw the Chande Kroll Stop intra-bar and does not violate the original idea of its creators. Nevertheless, in case that you wish to use the indicator with setting "CalculateOnBarClose = True", you may revert to the original formula which is labeled "Current_Bar". The modified formula labeled "Current_And_Prior_Bar" will be chosen as the default setting.


Keeping it simple

The indicator is best used with default settings. However, if you wish to compare it with indicators of other software packages such as ProRealTime, you will find the options to make it compatible. For example, if you wish to show the indicator as it does in the ProRealTime version, you would select Wilder's smoothing for the ATR (not in line with the original stop) and would further calculate the ATR for the "Current_Bar" (and should not set the indicator to "COBC=False").


Comparison 1: Original ATR formula (blue & firebrick, solid) versus Wilder's smoothing (black & purple, dashdot)




Comparison 2: Modified default formula (blue & firebrick, solid) versus original formula (black & purple, dashdot)


Hi Fat Tails
We have in the past already contact (mail). I appreciate your contribution to the forum enormous. Also, the way you now explains to the Chande Kroll Stop system is enormous. I hope that many traders have something to do with the Chande Kroll Stop. It is a useful tool and I worked there for years. I have searched a long time on the internet whether it was available for NinjaTrader. You give me and other traders have the opportunity to use this indicator. Great job my compliments.

Started this thread Reply With Quote
  #13 (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


I am still hesitating as there are several options to build volatility based stops that work intra-bar.


Comparing Chande Kroll Stop to the SuperTrendM11:

The SuperTrend belongs to the same class of volatility based stops as does the ChandeKrollStop. The long stop is determined by subtracting a multiple of the ATR from a moving average or moving median. The short stop is calculated by adding the same multiple of the ATR to the moving average or median. The problems I had encountered when coding the SuperTrendM11 were similar

(1) The ATR should not be calculated intra-bar, because it is too small when the new bar only consists of a few ticks. The solution I had adopted was to take the ATR one bar ago. This solution makes sure that the stop line does not temporarily move towards price while the range of the current bar is still incomplete.

(2) I had also taken the moving average and median one bar ago. This avoids recalculating the moving average and median intra-bar. In case that price moves against the current trend, there are no side effects from this modification. However, if price makes a large intra-bar move with the current trend

-> the stop line which is calculated from the prior value of moving average or median is further away
-> the stop adjustment takes only place with a delay of 1 bar
-> intra-bar profits generated by the large move are protected to a lesser extent

(3) However there is a practical advantage that comes from calculating the stop based on values 1 bar ago. The stop remains unchanged throughout the life of the bar. When the stop is touched in a backtest, it is clear that the stop was hit because price has approached it. Otherwise, if the stop moved along with price, it cannot be determined whether prices hit the stop or the stop hit (the historical fraction of) the candle

This means that the SuperTrendM11 is fool-proof (safe to use for myself) with automated strategies!


Suggested design is not fool-proof:

The approach that I had suggested in post # 11 of this thread may lead to problems when the indicator is used for automated trading. It is not clear whether price moved to the stop or whether the stop approached the bar. Therefore I have now added an option to the indicator, which uses the same basic design as I have already used for the SuperTrend and the Chandelier Stop.

The result is shown in the chart below. You will easily see that the modified Chande Kroll Stop (blue and red) lags by one bar during a strong trend. However, the lag is non-existent during consolidations and reversals. Personally, I prefer this solution to the other approaches. You get an indicator which is slightly different from the original, but it can be used intra-bar without problems and does not cause intra-bar problems with standard backtests.


Reply With Quote
Thanked by:
  #14 (permalink)
 Realtimetrader 
Overijssel
 
Experience: Master
Platform: Ninja
Trading: FDAX
Posts: 15 since Aug 2010
Thanks Given: 4
Thanks Received: 2


Fat Tails View Post
I am still hesitating as there are several options to build volatility based stops that work intra-bar.


Comparing Chande Kroll Stop to the SuperTrendM11:

The SuperTrend belongs to the same class of volatility based stops as does the ChandeKrollStop. The long stop is determined by subtracting a multiple of the ATR from a moving average or moving median. The short stop is calculated by adding the same multiple of the ATR to the moving average or median. The problems I had encountered when coding the SuperTrendM11 were similar

(1) The ATR should not be calculated intra-bar, because it is too small when the new bar only consists of a few ticks. The solution I had adopted was to take the ATR one bar ago. This solution makes sure that the stop line does not temporarily move towards price while the range of the current bar is still incomplete.

(2) I had also taken the moving average and median one bar ago. This avoids recalculating the moving average and median intra-bar. In case that price moves against the current trend, there are no side effects from this modification. However, if price makes a large intra-bar move with the current trend

-> the stop line which is calculated from the prior value of moving average or median is further away
-> the stop adjustment takes only place with a delay of 1 bar
-> intra-bar profits generated by the large move are protected to a lesser extent

(3) However there is a practical advantage that comes from calculating the stop based on values 1 bar ago. The stop remains unchanged throughout the life of the bar. When the stop is touched in a backtest, it is clear that the stop was hit because price has approached it. Otherwise, if the stop moved along with price, it cannot be determined whether prices hit the stop or the stop hit (the historical fraction of) the candle

This means that the SuperTrendM11 is fool-proof (safe to use for myself) with automated strategies!


Suggested design is not fool-proof:

The approach that I had suggested in post # 11 of this thread may lead to problems when the indicator is used for automated trading. It is not clear whether price moved to the stop or whether the stop approached the bar. Therefore I have now added an option to the indicator, which uses the same basic design as I have already used for the SuperTrend and the Chandelier Stop.

The result is shown in the chart below. You will easily see that the modified Chande Kroll Stop (blue and red) lags by one bar during a strong trend. However, the lag is non-existent during consolidations and reversals. Personally, I prefer this solution to the other approaches. You get an indicator which is slightly different from the original, but it can be used intra-bar without problems and does not cause intra-bar problems with standard backtests.


Hi Fat Tails,

As you show me in the graph the difference is extremely small. The Chande Kroll Stop I want to use for manual intraday trading and there I will not have a system (to) make. I understand your explanation completely. The program I leave entirely up to you

Thanks for your reply.

Started this thread Reply With Quote
  #15 (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


Realtimetrader View Post
Hi Fat Tails,

As you show me in the graph the difference is extremely small. The Chande Kroll Stop I want to use for manual intraday trading and there I will not have a system (to) make. I understand your explanation completely. The program I leave entirely up to you

Thanks for your reply.


I have settled for a simple implementation that lets you calculate ATR & 10 bar high/low either from the current or the prior bar. Calculating it from the current bar leads to the problems that I have described. Calculating it from the prior bar is playing safe for automated strategies and applying the indicator intra-bar.

But I prefer to let the user decide on selecting the proper formula.

The indicator can be found here:


Reply With Quote
Thanked by:




Last Updated on October 14, 2015


© 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