Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Using declarations
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.ComponentModel.DataAnnotations;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Xml.Serialization;
- using NinjaTrader.Cbi;
- using NinjaTrader.Gui;
- using NinjaTrader.Gui.Chart;
- using NinjaTrader.Gui.SuperDom;
- using NinjaTrader.Data;
- using NinjaTrader.NinjaScript;
- using NinjaTrader.Core.FloatingPoint;
- #endregion
- //This namespace holds Bars types in this folder and is required. Do not change it.
- namespace NinjaTrader.NinjaScript.BarsTypes.TLG_BarsType
- {
- /// <summary>
- /// Modded for NT8b9!!!!
- /// </summary>
- public class Custom2BarsType : NinjaTrader.NinjaScript.Indicators.VolumeRatiosTradePack.backend_files___dont_use.TLG_BARSTYPE
- {
- double barOpen;
- double barMax;
- double barMin;
- double fakeOpen=0;
- int barDirection=0;
- double openOffset=0;
- double trendOffset=0;
- double reversalOffset=0;
- bool maxExceeded=false;
- bool minExceeded=false;
- double tickSize=0.01;
- protected override void OnStateChange()
- {
- base.OnStateChange();
- if(!OnStateChangeValidator()) return;
- if (State == State.SetDefaults)
- {
- Description = @"Custom2 bar type.";
- Name = "Custom2";
- BarsPeriod = new BarsPeriod { BarsPeriodType = (BarsPeriodType) 768, BarsPeriodTypeName = "Custom2BarsType(768)", Value = 1 };
- BuiltFrom = BarsPeriodType.Tick;
- DaysToLoad = 3;
- IsIntraday = true;
- //Properties.Add ( new PropertyDescriptor (Properties.Find("BaseBarsPeriodType", true)) );
- //SetPropertyName("ReversalType", "BrickSize");
- }
- else if (State == State.Configure)
- {
- Name = "Custom2 T" + BarsPeriod.Value +"R" + BarsPeriod.Value2; // +"O" + BarsPeriod.BaseBarsPeriodValue;
- /// 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.
- Properties.Remove(Properties.Find("ReversalType", true));
- PropertyDescriptor BBPT= Properties.Find("BaseBarsPeriodType", true);
- Properties.Remove(BBPT);
- // Properties.Remove(Properties.Find("BaseBarsPeriodValue", true));
- // Properties.Remove(Properties.Find("PointAndFigurePriceType", true));
- SetPropertyName("Value", "Tick Trend");
- SetPropertyName("Value2", "Tick Reversal");
- SetPropertyName("BaseBarsPeriodValue", "Open Offset");
- }
- }
- public override int GetInitialLookBackDays(BarsPeriod barsPeriod, TradingHours tradingHours, int barsBack)
- {
- return 3;
- }
- protected override void OnDataPoint(Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isBar, double bid, double ask)
- {
- if(!OnDataPointValidator(bars, time)) { AddBar(bars, 0, 0, 0, 0, time, 0); return; }
- ///Beta 9 addition!
- // build a session iterator from the bars object being updated
- if (SessionIterator == null)
- SessionIterator = new SessionIterator(bars);
- // check if we are in a new trading session based on the trading hours selected by the user
- bool isNewSession = SessionIterator.IsNewSession(time, isBar);
- // calculate the new trading day
- if (isNewSession)
- SessionIterator.CalculateTradingDay(time, isBar);
- ///End Beta 9 addition
- //### First Bar
- if (bars.Count == 0 || (bars.IsResetOnNewTradingDay && isNewSession))
- {
- tickSize = bars.Instrument.MasterInstrument.TickSize;
- trendOffset = bars.BarsPeriod.Value * tickSize;
- reversalOffset = bars.BarsPeriod.Value2 * tickSize;
- //bars.BarPeriod.BaseBarsPeriodValue = bars.BarsPeriod.Value; //### Remove to customize OpenOffset
- openOffset = Math.Ceiling((double)bars.BarsPeriod.BaseBarsPeriodValue * 1) * tickSize;
- barOpen = close;
- barMax = barOpen + (trendOffset * barDirection);
- barMin = barOpen - (trendOffset * barDirection);
- AddBar(bars, barOpen, barOpen, barOpen, barOpen, time, volume);
- }
- //### Subsequent Bars
- else
- {
- maxExceeded = bars.Instrument.MasterInstrument.Compare(close, barMax) > 0 ? true : false;
- minExceeded = bars.Instrument.MasterInstrument.Compare(close, barMin) < 0 ? true : false;
- //### Defined Range Exceeded?
- if ( maxExceeded || minExceeded )
- {
- double thisClose = maxExceeded ? Math.Min(close, barMax) : minExceeded ? Math.Max(close, barMin) : close;
- barDirection = maxExceeded ? 1 : minExceeded ? -1 : 0;
- fakeOpen = thisClose - (openOffset * barDirection); //### Fake Open is halfway down the bar
- //### Close Current Bar
- UpdateBar(bars, (maxExceeded ? thisClose : bars.GetHigh(bars.Count - 1)), (minExceeded ? thisClose : bars.GetLow(bars.Count - 1)), thisClose, time, volume);
- //### Add New Bar
- barOpen = close;
- barMax = thisClose + ((barDirection>0 ? trendOffset : reversalOffset) );
- barMin = thisClose - ((barDirection>0 ? reversalOffset : trendOffset) );
- AddBar(bars, fakeOpen, (maxExceeded ? thisClose : fakeOpen), (minExceeded ? thisClose : fakeOpen), thisClose, time, volume);
- }
- //### Current Bar Still Developing
- else
- {
- 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);
- }
- }
- bars.LastPrice = close;
- }
- public override void ApplyDefaultBasePeriodValue(BarsPeriod period)
- {
- }
- public override void ApplyDefaultValue(BarsPeriod period)
- {
- //period.BarsPeriodTypeName = "Custom2";
- period.Value = 2;
- period.Value2 = 6;
- period.BaseBarsPeriodValue = 2;
- }
- public override string ChartLabel(DateTime dateTime)
- {
- return dateTime.ToString("T", Core.Globals.GeneralOptions.CurrentCulture);
- }
- public override double GetPercentComplete(Bars bars, DateTime now)
- {
- //return 1.0d;
- return 0;
- }
- }
- }
- /*
- #region NinjaScript generated code. Neither change nor remove.
- namespace NinjaTrader.NinjaScript.Indicators
- {
- public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
- {
- private TLG_BarsType.Custom1BarsType[] cacheCustom1BarsType;
- public TLG_BarsType.Custom1BarsType Custom1BarsType()
- {
- return Custom1BarsType(Input);
- }
- public TLG_BarsType.Custom1BarsType Custom1BarsType(ISeries<double> input)
- {
- if (cacheCustom1BarsType != null)
- for (int idx = 0; idx < cacheCustom1BarsType.Length; idx++)
- if (cacheCustom1BarsType[idx] != null && cacheCustom1BarsType[idx].EqualsInput(input))
- return cacheCustom1BarsType[idx];
- return CacheIndicator<TLG_BarsType.Custom1BarsType>(new TLG_BarsType.Custom1BarsType(), input, ref cacheCustom1BarsType);
- }
- }
- }
- namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
- {
- public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
- {
- public Indicators.TLG_BarsType.Custom1BarsType Custom1BarsType()
- {
- return indicator.Custom1BarsType(Input);
- }
- public Indicators.TLG_BarsType.Custom1BarsType Custom1BarsType(ISeries<double> input )
- {
- return indicator.Custom1BarsType(input);
- }
- }
- }
- namespace NinjaTrader.NinjaScript.Strategies
- {
- public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
- {
- public Indicators.TLG_BarsType.Custom1BarsType Custom1BarsType()
- {
- return indicator.Custom1BarsType(Input);
- }
- public Indicators.TLG_BarsType.Custom1BarsType Custom1BarsType(ISeries<double> input )
- {
- return indicator.Custom1BarsType(input);
- }
- }
- }
- #endregion
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement