Advertisement
Guest User

Untitled

a guest
Jun 30th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.06 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.     /// ATR on chart
  18.     /// </summary>
  19.     [Description("ATR on chart")]
  20.     public class ATRonchart : Indicator
  21.     {
  22.         #region Variables
  23.         // Wizard generated variables
  24.             private int aTREMA = 10; // Default setting for ATREMA
  25.         // User defined variables (add any user defined variables below)
  26.         #endregion
  27.  
  28.         /// <summary>
  29.         /// This method is used to configure the indicator and is called once before any bar data is loaded.
  30.         /// </summary>
  31.         protected override void Initialize()
  32.         {
  33.             Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Dot, "ATRonchart"));
  34.             CalculateOnBarClose = true;
  35.             PriceTypeSupported = true;
  36.         }
  37.  
  38.         /// <summary>
  39.         /// Called on each bar update event (incoming tick)
  40.         /// </summary>
  41.         protected override void OnBarUpdate()
  42.         {
  43.          Plot0.Set(Close[0]+ATR(10)[0]); //This is causing me some trouble for some fucking reason.
  44.         }
  45.  
  46.         #region Properties
  47.         [Browsable(false)]  // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
  48.         [XmlIgnore()]       // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
  49.         public DataSeries ATRDot
  50.         {
  51.             get { return Values[0]; }
  52.         }
  53.  
  54.         [Description("ATR Exponential MA")]
  55.         [GridCategory("Parameters")]
  56.         public int ATREMA
  57.         {
  58.             get { return aTREMA; }
  59.             set { aTREMA = Math.Max(1, value); }
  60.         }
  61.         #endregion
  62.     }
  63. }
  64.  
  65. #region NinjaScript generated code. Neither change nor remove.
  66. // This namespace holds all indicators and is required. Do not change it.
  67. namespace NinjaTrader.Indicator
  68. {
  69.     public partial class Indicator : IndicatorBase
  70.     {
  71.         private ATRonchart[] cacheATRonchart = null;
  72.  
  73.         private static ATRonchart checkATRonchart = new ATRonchart();
  74.  
  75.         /// <summary>
  76.         /// ATR on chart
  77.         /// </summary>
  78.         /// <returns></returns>
  79.         public ATRonchart ATRonchart(int aTREMA)
  80.         {
  81.             return ATRonchart(Input, aTREMA);
  82.         }
  83.  
  84.         /// <summary>
  85.         /// ATR on chart
  86.         /// </summary>
  87.         /// <returns></returns>
  88.         public ATRonchart ATRonchart(Data.IDataSeries input, int aTREMA)
  89.         {
  90.             if (cacheATRonchart != null)
  91.                 for (int idx = 0; idx < cacheATRonchart.Length; idx++)
  92.                     if (cacheATRonchart[idx].ATREMA == aTREMA && cacheATRonchart[idx].EqualsInput(input))
  93.                         return cacheATRonchart[idx];
  94.  
  95.             lock (checkATRonchart)
  96.             {
  97.                 checkATRonchart.ATREMA = aTREMA;
  98.                 aTREMA = checkATRonchart.ATREMA;
  99.  
  100.                 if (cacheATRonchart != null)
  101.                     for (int idx = 0; idx < cacheATRonchart.Length; idx++)
  102.                         if (cacheATRonchart[idx].ATREMA == aTREMA && cacheATRonchart[idx].EqualsInput(input))
  103.                             return cacheATRonchart[idx];
  104.  
  105.                 ATRonchart indicator = new ATRonchart();
  106.                 indicator.BarsRequired = BarsRequired;
  107.                 indicator.CalculateOnBarClose = CalculateOnBarClose;
  108. #if NT7
  109.                 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
  110.                 indicator.MaximumBarsLookBack = MaximumBarsLookBack;
  111. #endif
  112.                 indicator.Input = input;
  113.                 indicator.ATREMA = aTREMA;
  114.                 Indicators.Add(indicator);
  115.                 indicator.SetUp();
  116.  
  117.                 ATRonchart[] tmp = new ATRonchart[cacheATRonchart == null ? 1 : cacheATRonchart.Length + 1];
  118.                 if (cacheATRonchart != null)
  119.                     cacheATRonchart.CopyTo(tmp, 0);
  120.                 tmp[tmp.Length - 1] = indicator;
  121.                 cacheATRonchart = tmp;
  122.                 return indicator;
  123.             }
  124.         }
  125.     }
  126. }
  127.  
  128. // This namespace holds all market analyzer column definitions and is required. Do not change it.
  129. namespace NinjaTrader.MarketAnalyzer
  130. {
  131.     public partial class Column : ColumnBase
  132.     {
  133.         /// <summary>
  134.         /// ATR on chart
  135.         /// </summary>
  136.         /// <returns></returns>
  137.         [Gui.Design.WizardCondition("Indicator")]
  138.         public Indicator.ATRonchart ATRonchart(int aTREMA)
  139.         {
  140.             return _indicator.ATRonchart(Input, aTREMA);
  141.         }
  142.  
  143.         /// <summary>
  144.         /// ATR on chart
  145.         /// </summary>
  146.         /// <returns></returns>
  147.         public Indicator.ATRonchart ATRonchart(Data.IDataSeries input, int aTREMA)
  148.         {
  149.             return _indicator.ATRonchart(input, aTREMA);
  150.         }
  151.     }
  152. }
  153.  
  154. // This namespace holds all strategies and is required. Do not change it.
  155. namespace NinjaTrader.Strategy
  156. {
  157.     public partial class Strategy : StrategyBase
  158.     {
  159.         /// <summary>
  160.         /// ATR on chart
  161.         /// </summary>
  162.         /// <returns></returns>
  163.         [Gui.Design.WizardCondition("Indicator")]
  164.         public Indicator.ATRonchart ATRonchart(int aTREMA)
  165.         {
  166.             return _indicator.ATRonchart(Input, aTREMA);
  167.         }
  168.  
  169.         /// <summary>
  170.         /// ATR on chart
  171.         /// </summary>
  172.         /// <returns></returns>
  173.         public Indicator.ATRonchart ATRonchart(Data.IDataSeries input, int aTREMA)
  174.         {
  175.             if (InInitialize && input == null)
  176.                 throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
  177.  
  178.             return _indicator.ATRonchart(input, aTREMA);
  179.         }
  180.     }
  181. }
  182. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement