Advertisement
retesere20

---recycler-----

Jun 27th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.00 KB | None | 0 0
  1. #region Using declarations
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.ComponentModel.DataAnnotations;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Xml.Serialization;
  13. using NinjaTrader.Cbi;
  14. using NinjaTrader.Gui;
  15. using NinjaTrader.Gui.Chart;
  16. using NinjaTrader.Gui.SuperDom;
  17. using NinjaTrader.Data;
  18. using NinjaTrader.NinjaScript;
  19. using NinjaTrader.Core.FloatingPoint;
  20.  
  21. #endregion
  22.  
  23. //This namespace holds Bars types in this folder and is required. Do not change it.
  24. namespace NinjaTrader.NinjaScript.BarsTypes.TLG_BarsType
  25. {
  26. /// <summary>
  27. /// Modded for NT8b9!!!!
  28. /// </summary>
  29. public class Custom2BarsType : NinjaTrader.NinjaScript.Indicators.VolumeRatiosTradePack.backend_files___dont_use.TLG_BARSTYPE
  30. {
  31. double barOpen;
  32. double barMax;
  33. double barMin;
  34. double fakeOpen=0;
  35.  
  36. int barDirection=0;
  37. double openOffset=0;
  38. double trendOffset=0;
  39. double reversalOffset=0;
  40.  
  41. bool maxExceeded=false;
  42. bool minExceeded=false;
  43.  
  44. double tickSize=0.01;
  45.  
  46.  
  47. protected override void OnStateChange()
  48. {
  49.  
  50. base.OnStateChange();
  51. if(!OnStateChangeValidator()) return;
  52.  
  53. if (State == State.SetDefaults)
  54. {
  55. Description = @"Custom2 bar type.";
  56. Name = "Custom2";
  57.  
  58. BarsPeriod = new BarsPeriod { BarsPeriodType = (BarsPeriodType) 768, BarsPeriodTypeName = "Custom2BarsType(768)", Value = 1 };
  59. BuiltFrom = BarsPeriodType.Tick;
  60. DaysToLoad = 3;
  61. IsIntraday = true;
  62.  
  63. //Properties.Add ( new PropertyDescriptor (Properties.Find("BaseBarsPeriodType", true)) );
  64. //SetPropertyName("ReversalType", "BrickSize");
  65.  
  66. }
  67. else if (State == State.Configure)
  68. {
  69.  
  70. Name = "Custom2 T" + BarsPeriod.Value +"R" + BarsPeriod.Value2; // +"O" + BarsPeriod.BaseBarsPeriodValue;
  71. /// I kept the UI name short b/c as of NT8b6 the name space at the toolbar is very short. You would not see the values.
  72. Properties.Remove(Properties.Find("ReversalType", true));
  73. PropertyDescriptor BBPT= Properties.Find("BaseBarsPeriodType", true);
  74. Properties.Remove(BBPT);
  75. // Properties.Remove(Properties.Find("BaseBarsPeriodValue", true));
  76. // Properties.Remove(Properties.Find("PointAndFigurePriceType", true));
  77.  
  78. SetPropertyName("Value", "Tick Trend");
  79. SetPropertyName("Value2", "Tick Reversal");
  80. SetPropertyName("BaseBarsPeriodValue", "Open Offset");
  81.  
  82. }
  83. }
  84.  
  85. public override int GetInitialLookBackDays(BarsPeriod barsPeriod, TradingHours tradingHours, int barsBack)
  86. {
  87. return 3;
  88. }
  89.  
  90.  
  91. protected override void OnDataPoint(Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isBar, double bid, double ask)
  92. {
  93. if(!OnDataPointValidator(bars, time)) { AddBar(bars, 0, 0, 0, 0, time, 0); return; }
  94.  
  95. ///Beta 9 addition!
  96. // build a session iterator from the bars object being updated
  97. if (SessionIterator == null)
  98. SessionIterator = new SessionIterator(bars);
  99.  
  100. // check if we are in a new trading session based on the trading hours selected by the user
  101. bool isNewSession = SessionIterator.IsNewSession(time, isBar);
  102.  
  103. // calculate the new trading day
  104. if (isNewSession)
  105. SessionIterator.CalculateTradingDay(time, isBar);
  106.  
  107. ///End Beta 9 addition
  108.  
  109.  
  110. //### First Bar
  111. if (bars.Count == 0 || (bars.IsResetOnNewTradingDay && isNewSession))
  112. {
  113. tickSize = bars.Instrument.MasterInstrument.TickSize;
  114. trendOffset = bars.BarsPeriod.Value * tickSize;
  115. reversalOffset = bars.BarsPeriod.Value2 * tickSize;
  116. //bars.BarPeriod.BaseBarsPeriodValue = bars.BarsPeriod.Value; //### Remove to customize OpenOffset
  117. openOffset = Math.Ceiling((double)bars.BarsPeriod.BaseBarsPeriodValue * 1) * tickSize;
  118.  
  119. barOpen = close;
  120. barMax = barOpen + (trendOffset * barDirection);
  121. barMin = barOpen - (trendOffset * barDirection);
  122.  
  123. AddBar(bars, barOpen, barOpen, barOpen, barOpen, time, volume);
  124. }
  125. //### Subsequent Bars
  126. else
  127. {
  128. maxExceeded = bars.Instrument.MasterInstrument.Compare(close, barMax) > 0 ? true : false;
  129. minExceeded = bars.Instrument.MasterInstrument.Compare(close, barMin) < 0 ? true : false;
  130.  
  131. //### Defined Range Exceeded?
  132. if ( maxExceeded || minExceeded )
  133. {
  134. double thisClose = maxExceeded ? Math.Min(close, barMax) : minExceeded ? Math.Max(close, barMin) : close;
  135. barDirection = maxExceeded ? 1 : minExceeded ? -1 : 0;
  136. fakeOpen = thisClose - (openOffset * barDirection); //### Fake Open is halfway down the bar
  137.  
  138. //### Close Current Bar
  139. UpdateBar(bars, (maxExceeded ? thisClose : bars.GetHigh(bars.Count - 1)), (minExceeded ? thisClose : bars.GetLow(bars.Count - 1)), thisClose, time, volume);
  140.  
  141. //### Add New Bar
  142. barOpen = close;
  143. barMax = thisClose + ((barDirection>0 ? trendOffset : reversalOffset) );
  144. barMin = thisClose - ((barDirection>0 ? reversalOffset : trendOffset) );
  145.  
  146. AddBar(bars, fakeOpen, (maxExceeded ? thisClose : fakeOpen), (minExceeded ? thisClose : fakeOpen), thisClose, time, volume);
  147. }
  148. //### Current Bar Still Developing
  149. else
  150. {
  151. UpdateBar(bars, (close > bars.GetHigh(bars.Count - 1) ? close : bars.GetHigh(bars.Count - 1)), (close < bars.GetLow(bars.Count - 1) ? close : bars.GetLow(bars.Count - 1)), close, time, volume);
  152. }
  153.  
  154. }
  155. bars.LastPrice = close;
  156.  
  157. }
  158.  
  159. public override void ApplyDefaultBasePeriodValue(BarsPeriod period)
  160. {
  161.  
  162. }
  163.  
  164. public override void ApplyDefaultValue(BarsPeriod period)
  165. {
  166. //period.BarsPeriodTypeName = "Custom2";
  167. period.Value = 2;
  168. period.Value2 = 6;
  169. period.BaseBarsPeriodValue = 2;
  170. }
  171.  
  172. public override string ChartLabel(DateTime dateTime)
  173. {
  174. return dateTime.ToString("T", Core.Globals.GeneralOptions.CurrentCulture);
  175. }
  176.  
  177. public override double GetPercentComplete(Bars bars, DateTime now)
  178. {
  179. //return 1.0d;
  180. return 0;
  181. }
  182. }
  183. }
  184.  
  185. /*
  186.  
  187. #region NinjaScript generated code. Neither change nor remove.
  188.  
  189. namespace NinjaTrader.NinjaScript.Indicators
  190. {
  191. public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
  192. {
  193. private TLG_BarsType.Custom1BarsType[] cacheCustom1BarsType;
  194. public TLG_BarsType.Custom1BarsType Custom1BarsType()
  195. {
  196. return Custom1BarsType(Input);
  197. }
  198.  
  199. public TLG_BarsType.Custom1BarsType Custom1BarsType(ISeries<double> input)
  200. {
  201. if (cacheCustom1BarsType != null)
  202. for (int idx = 0; idx < cacheCustom1BarsType.Length; idx++)
  203. if (cacheCustom1BarsType[idx] != null && cacheCustom1BarsType[idx].EqualsInput(input))
  204. return cacheCustom1BarsType[idx];
  205. return CacheIndicator<TLG_BarsType.Custom1BarsType>(new TLG_BarsType.Custom1BarsType(), input, ref cacheCustom1BarsType);
  206. }
  207. }
  208. }
  209.  
  210. namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
  211. {
  212. public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
  213. {
  214. public Indicators.TLG_BarsType.Custom1BarsType Custom1BarsType()
  215. {
  216. return indicator.Custom1BarsType(Input);
  217. }
  218.  
  219. public Indicators.TLG_BarsType.Custom1BarsType Custom1BarsType(ISeries<double> input )
  220. {
  221. return indicator.Custom1BarsType(input);
  222. }
  223. }
  224. }
  225.  
  226. namespace NinjaTrader.NinjaScript.Strategies
  227. {
  228. public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
  229. {
  230. public Indicators.TLG_BarsType.Custom1BarsType Custom1BarsType()
  231. {
  232. return indicator.Custom1BarsType(Input);
  233. }
  234.  
  235. public Indicators.TLG_BarsType.Custom1BarsType Custom1BarsType(ISeries<double> input )
  236. {
  237. return indicator.Custom1BarsType(input);
  238. }
  239. }
  240. }
  241.  
  242. #endregion
  243.  
  244. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement