Advertisement
Guest User

Smoothed RSI Inverse Fisher Transform - indicator for NinjaT

a guest
Aug 27th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.91 KB | None | 0 0
  1. #region Using declarations
  2. using System;
  3. using System.ComponentModel;
  4. using System.Diagnostics;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Xml.Serialization;
  8. using NinjaTrader.Cbi;
  9. using NinjaTrader.Data;
  10. using NinjaTrader.Gui.Chart;
  11. #endregion
  12.  
  13. // This namespace holds all indicators and is required. Do not change it.
  14. namespace NinjaTrader.Indicator
  15. {
  16. /// <summary>
  17. /// Enter the description of your new custom indicator here
  18. /// </summary>
  19. [Description("This is the Smoothed RSI Inverse Fisher Transform indicator as described in the October 2010 issue of Stocks & Commodities.")]
  20. public class SmoothedRsiInverseFisherTransform : Indicator
  21. {
  22. #region Variables
  23. private int rSI_Period = 4;
  24. private int eMA_Period = 4;
  25. private double rainbow_value, difference, zero_lag_ema, inv_fish_value = 0;
  26. private DataSeries rainbow, ema1, ema2, x;
  27. #endregion
  28.  
  29. /// <summary>
  30. /// This method is used to configure the indicator and is called once before any bar data is loaded.
  31. /// </summary>
  32. protected override void Initialize()
  33. {
  34. rainbow = new DataSeries(this);
  35. ema1 = new DataSeries(this);
  36. ema2 = new DataSeries(this);
  37. x = new DataSeries(this);
  38.  
  39. Add(new Plot(Color.RoyalBlue, PlotStyle.Line, "InvFish"));
  40. Add(new Line(Color.DarkGray, 80, "Eighty"));
  41. Add(new Line(Color.DarkGray, 20, "Twenty"));
  42.  
  43. Overlay = false;
  44. }
  45.  
  46. /// <summary>
  47. /// Called on each bar update event (incoming tick)
  48. /// </summary>
  49. protected override void OnBarUpdate()
  50. {
  51. rainbow_value =
  52. (5 * WMA(2)[0] +
  53. 4 * WMA(WMA(2), 2)[0] +
  54. 3 * WMA(WMA(WMA(2), 2), 2)[0] +
  55. 2 * WMA(WMA(WMA(WMA(2), 2), 2), 2)[0] +
  56. WMA(WMA(WMA(WMA(WMA(2), 2), 2), 2), 2)[0] +
  57. WMA(WMA(WMA(WMA(WMA(WMA(2), 2), 2), 2), 2), 2)[0] +
  58. WMA(WMA(WMA(WMA(WMA(WMA(WMA(2), 2), 2), 2), 2), 2), 2)[0] +
  59. WMA(WMA(WMA(WMA(WMA(WMA(WMA(WMA(2), 2), 2), 2), 2), 2), 2), 2)[0] +
  60. WMA(WMA(WMA(WMA(WMA(WMA(WMA(WMA(WMA(2), 2), 2), 2), 2), 2), 2), 2), 2)[0] +
  61. WMA(WMA(WMA(WMA(WMA(WMA(WMA(WMA(WMA(WMA(2), 2), 2), 2), 2), 2), 2), 2), 2), 2)[0]) / 20;
  62.  
  63. rainbow.Set(rainbow_value);
  64.  
  65. x.Set(0.1 * (RSI(rainbow, rSI_Period, 1)[0] - 50));
  66.  
  67. ema1.Set(EMA(x, eMA_Period)[0]);
  68. ema2.Set(EMA(ema1, eMA_Period)[0]);
  69.  
  70. difference = ema1[0] - ema2[0];
  71.  
  72. zero_lag_ema = ema1[0] + difference;
  73.  
  74. inv_fish_value = ((Math.Exp(2 * zero_lag_ema) - 1) / (Math.Exp(2 * zero_lag_ema) + 1) + 1) * 50;
  75.  
  76. InvFish.Set(inv_fish_value);
  77. }
  78.  
  79. #region Properties
  80. [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
  81. [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
  82. public DataSeries InvFish
  83. {
  84. get { return Values[0]; }
  85. }
  86.  
  87. [Description("")]
  88. [Category("Parameters")]
  89. public int RSI_Period
  90. {
  91. get { return rSI_Period; }
  92. set { rSI_Period = Math.Max(1, value); }
  93. }
  94.  
  95. [Description("")]
  96. [Category("Parameters")]
  97. public int EMA_Period
  98. {
  99. get { return eMA_Period; }
  100. set { eMA_Period = Math.Max(1, value); }
  101. }
  102. #endregion
  103. }
  104. }
  105.  
  106. #region NinjaScript generated code. Neither change nor remove.
  107. // This namespace holds all indicators and is required. Do not change it.
  108. namespace NinjaTrader.Indicator
  109. {
  110. public partial class Indicator : IndicatorBase
  111. {
  112. private SmoothedRsiInverseFisherTransform[] cacheSmoothedRsiInverseFisherTransform = null;
  113.  
  114. private static SmoothedRsiInverseFisherTransform checkSmoothedRsiInverseFisherTransform = new SmoothedRsiInverseFisherTransform();
  115.  
  116. /// <summary>
  117. /// This is the Smoothed RSI Inverse Fisher Transform indicator as described in the October 2010 issue of Stocks & Commodities.
  118. /// </summary>
  119. /// <returns></returns>
  120. public SmoothedRsiInverseFisherTransform SmoothedRsiInverseFisherTransform(int eMA_Period, int rSI_Period)
  121. {
  122. return SmoothedRsiInverseFisherTransform(Input, eMA_Period, rSI_Period);
  123. }
  124.  
  125. /// <summary>
  126. /// This is the Smoothed RSI Inverse Fisher Transform indicator as described in the October 2010 issue of Stocks & Commodities.
  127. /// </summary>
  128. /// <returns></returns>
  129. public SmoothedRsiInverseFisherTransform SmoothedRsiInverseFisherTransform(Data.IDataSeries input, int eMA_Period, int rSI_Period)
  130. {
  131. checkSmoothedRsiInverseFisherTransform.EMA_Period = eMA_Period;
  132. eMA_Period = checkSmoothedRsiInverseFisherTransform.EMA_Period;
  133. checkSmoothedRsiInverseFisherTransform.RSI_Period = rSI_Period;
  134. rSI_Period = checkSmoothedRsiInverseFisherTransform.RSI_Period;
  135.  
  136. if (cacheSmoothedRsiInverseFisherTransform != null)
  137. for (int idx = 0; idx < cacheSmoothedRsiInverseFisherTransform.Length; idx++)
  138. if (cacheSmoothedRsiInverseFisherTransform[idx].EMA_Period == eMA_Period && cacheSmoothedRsiInverseFisherTransform[idx].RSI_Period == rSI_Period && cacheSmoothedRsiInverseFisherTransform[idx].EqualsInput(input))
  139. return cacheSmoothedRsiInverseFisherTransform[idx];
  140.  
  141. SmoothedRsiInverseFisherTransform indicator = new SmoothedRsiInverseFisherTransform();
  142. indicator.BarsRequired = BarsRequired;
  143. indicator.CalculateOnBarClose = CalculateOnBarClose;
  144. indicator.Input = input;
  145. indicator.EMA_Period = eMA_Period;
  146. indicator.RSI_Period = rSI_Period;
  147. indicator.SetUp();
  148.  
  149. SmoothedRsiInverseFisherTransform[] tmp = new SmoothedRsiInverseFisherTransform[cacheSmoothedRsiInverseFisherTransform == null ? 1 : cacheSmoothedRsiInverseFisherTransform.Length + 1];
  150. if (cacheSmoothedRsiInverseFisherTransform != null)
  151. cacheSmoothedRsiInverseFisherTransform.CopyTo(tmp, 0);
  152. tmp[tmp.Length - 1] = indicator;
  153. cacheSmoothedRsiInverseFisherTransform = tmp;
  154. Indicators.Add(indicator);
  155.  
  156. return indicator;
  157. }
  158.  
  159. }
  160. }
  161.  
  162. // This namespace holds all market analyzer column definitions and is required. Do not change it.
  163. namespace NinjaTrader.MarketAnalyzer
  164. {
  165. public partial class Column : ColumnBase
  166. {
  167. /// <summary>
  168. /// This is the Smoothed RSI Inverse Fisher Transform indicator as described in the October 2010 issue of Stocks & Commodities.
  169. /// </summary>
  170. /// <returns></returns>
  171. [Gui.Design.WizardCondition("Indicator")]
  172. public Indicator.SmoothedRsiInverseFisherTransform SmoothedRsiInverseFisherTransform(int eMA_Period, int rSI_Period)
  173. {
  174. return _indicator.SmoothedRsiInverseFisherTransform(Input, eMA_Period, rSI_Period);
  175. }
  176.  
  177. /// <summary>
  178. /// This is the Smoothed RSI Inverse Fisher Transform indicator as described in the October 2010 issue of Stocks & Commodities.
  179. /// </summary>
  180. /// <returns></returns>
  181. public Indicator.SmoothedRsiInverseFisherTransform SmoothedRsiInverseFisherTransform(Data.IDataSeries input, int eMA_Period, int rSI_Period)
  182. {
  183. return _indicator.SmoothedRsiInverseFisherTransform(input, eMA_Period, rSI_Period);
  184. }
  185.  
  186. }
  187. }
  188.  
  189. // This namespace holds all strategies and is required. Do not change it.
  190. namespace NinjaTrader.Strategy
  191. {
  192. public partial class Strategy : StrategyBase
  193. {
  194. /// <summary>
  195. /// This is the Smoothed RSI Inverse Fisher Transform indicator as described in the October 2010 issue of Stocks & Commodities.
  196. /// </summary>
  197. /// <returns></returns>
  198. [Gui.Design.WizardCondition("Indicator")]
  199. public Indicator.SmoothedRsiInverseFisherTransform SmoothedRsiInverseFisherTransform(int eMA_Period, int rSI_Period)
  200. {
  201. return _indicator.SmoothedRsiInverseFisherTransform(Input, eMA_Period, rSI_Period);
  202. }
  203.  
  204. /// <summary>
  205. /// This is the Smoothed RSI Inverse Fisher Transform indicator as described in the October 2010 issue of Stocks & Commodities.
  206. /// </summary>
  207. /// <returns></returns>
  208. public Indicator.SmoothedRsiInverseFisherTransform SmoothedRsiInverseFisherTransform(Data.IDataSeries input, int eMA_Period, int rSI_Period)
  209. {
  210. if (InInitialize && input == null)
  211. throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
  212.  
  213. return _indicator.SmoothedRsiInverseFisherTransform(input, eMA_Period, rSI_Period);
  214. }
  215.  
  216. }
  217. }
  218. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement