| Coding Forum Collaborate, receive help, or discuss coding related issues. |
![]() | | Tweet | |
| | #1 | ||
![]() | TTM Scalp Average for Ninja | ||
| |
|
| | #2 | ||
![]() | Re: TTM Scalp Average for Ninja | ||
| |
|
| | #3 | ||
![]() | Re: TTM Scalp Average for Ninja | ||
| |
|
| | #4 | ||
![]() | Re: TTM Scalp Average for Ninja | ||
| |
|
| | #5 | ||
![]() | Re: TTM Scalp Average for Ninja | ||
| |
|
| | #6 | ||
![]() | Re: TTM Scalp Average for Ninja | ||
| |
|
| | #7 | ||
![]() | Re: TTM Scalp Average for Ninja Last edited by thehaul; 01-18-2009 at 02:34 AM. Reason: trying to delete a repeat | ||
| |
|
| | #8 | ||
![]() | Re: TTM Scalp Average for Ninja // // Copyright (C) 2008, SBG Trading Corp. www.affordableindicators.com // Use this indicator/strategy at your own risk. No warranty expressed or implied. // Trading financial instruments is risky and can result in substantial loss. // The owner of this indicator/strategy holds harmless SBG Trading Corp. from any // and all trading losses incurred while using this indicator/strategy. // // #region Using declarations using System; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.ComponentModel; using System.Xml.Serialization; //using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Gui.Chart; #endregion namespace NinjaTrader.Indicator { /// <summary> /// /// </summary> [Description("Translated from TradeStation")] [Gui.Design.DisplayName("S eans Average")] public class SeansAverage_v3 : Indicator { #region Variables private const int _UP = 1; private const int _DOWN = -1; // Wizard generated variables private int pLen=4; private bool pRoundToTick = false; private Color pSwingBarColor = Color.White; private DataSeries Midpoints; private int highBarsAgo=1; private int possibleHighBarsAgo = 1; private double possibleHigh = double.MinValue; private double hightoBeat = double.MinValue+1; private int barsSincePaint = 1; private int lowBarsAgo = 1; private int possibleLowBarsAgo = 1; private double possibleLow = double.MaxValue; private double lowtoBeat = double.MaxValue-1; private double triggerPriceSell = double.MinValue+1; private double triggerPriceBuy = double.MaxValue-1; private double theavg=double.MinValue; private int trend = _UP; private double s_low = 1; private double s_high = 1; private bool RunInit = true; #endregion /// <summary> /// This method is used to configure the indicator and is called once before any bar data is loaded. /// </summary> protected override void Initialize() { Add(new Plot(new Pen(Color.Gold,1), PlotStyle.Line, "SeansAvg")); CalculateOnBarClose = true; Overlay = true; PriceTypeSupported = false; Midpoints = new DataSeries (this); } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if(RunInit) { s_low=Low[0]; s_high=High[0]; RunInit=false; } int b=0; if(CurrentBar<highBarsAgo || CurrentBar<lowBarsAgo) return; //************************* ************************* * //****** Find and plot the highest swing high ******* //************************* ************************* * if (trend == _UP) { b = Swing(1).SwingHighBar(0, 1, barsSincePaint+2); if (b > -1) { possibleHighBarsAgo = b; possibleHigh = High[possibleHighBarsAgo]; } if (possibleHigh >= hightoBeat) { highBarsAgo = possibleHighBarsAgo; hightoBeat = possibleHigh; triggerPriceSell = Low[highBarsAgo - 1]; } double temp=High[0]; for(int i=1;i<highBarsAgo;i++)//this calculates the highest high since temp = Math.Max(temp,High[i]); if (Close[0] < triggerPriceSell || temp < hightoBeat) { if(pSwingBarColor != Color.Transparent) { DrawLine("bar"+(CurrentBa r-highBarsAgo),highBarsAgo, High[highBarsAgo],highBarsAgo,Low[highBarsAgo],pSwingBarColor,DashStyle .Solid,ChartControl.BarWi dth+2); // BarColor = pSwingBarColor; // CandleOutlineColor = ChartControl.BarOutlinePe n.Color; } trend = _DOWN; barsSincePaint = highBarsAgo-1; hightoBeat = double.MinValue+1; lowtoBeat = double.MaxValue-1; triggerPriceBuy = double.MaxValue-1; triggerPriceSell = double.MinValue; possibleHigh = double.MinValue; highBarsAgo = 1; s_high = Low[0]; } } // //************************* ************************* * // //****** Find and plot the lowest swing low ********* // //************************* ************************* * if (trend == _DOWN) { b = Swing(1).SwingLowBar(0, 1, barsSincePaint+2); if (b > -1) { possibleLowBarsAgo = b; possibleLow = Low[possibleLowBarsAgo]; } if (possibleLow <= lowtoBeat) { lowBarsAgo = possibleLowBarsAgo; lowtoBeat = possibleLow; triggerPriceBuy = High[lowBarsAgo - 1]; } double temp=Low[0]; for(int i=1;i<lowBarsAgo;i++) //this calculates the lowest low since lowBarsAgo temp = Math.Min(temp,Low[i]); if (Close[0] > triggerPriceBuy || temp > lowtoBeat) { if(pSwingBarColor != Color.Transparent) { DrawLine("bar"+(CurrentBa r-lowBarsAgo),lowBarsAgo,Hi gh[lowBarsAgo],lowBarsAgo,Low[lowBarsAgo],pSwingBarColor,DashStyle .Solid,ChartControl.BarWi dth+2); // BarColor = pSwingBarColor; // CandleOutlineColor = ChartControl.BarOutlinePe n.Color; } trend = _UP; barsSincePaint = lowBarsAgo-1; lowtoBeat = double.MaxValue-1; hightoBeat = double.MinValue+1; triggerPriceBuy = double.MaxValue-1; triggerPriceSell = double.MinValue+1; possibleLow = double.MaxValue; lowBarsAgo = 1; s_low = High[0]; } } Midpoints.Set((s_low + s_high)/2.0); theavg = SMA(Midpoints, pLen)[0]; if(pRoundToTick) theavg = NormalizePrice(theavg); Avg.Set(theavg); barsSincePaint = barsSincePaint+1; if (trend == _UP) highBarsAgo = highBarsAgo + 1; if (trend == _DOWN) lowBarsAgo = lowBarsAgo + 1; } //========================= ========================= =============== private double NormalizePrice(double ThePrice) { int Temp = (int) Math.Round(ThePrice / TickSize); return ((double) Temp * TickSize); } //========================= ========================= =============== #region Properties [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries Avg { get { return Values[0]; } } [Description("Round to nearest tick?")] [Category("Parameters")] public bool RoundToTick { get { return pRoundToTick; } set { pRoundToTick = value; } } [Description("Period")] [Category("Parameters")] public int Period { get { return pLen; } set { pLen = Math.Max(1, value); } } [XmlIgnore()] [Description("Color of swing pivot bar (set to 'Transparent' to disengage coloring)")] [Category("Visual")] public Color SwingBarColor{ get { return pSwingBarColor; } set { pSwingBarColor = value; } } [Browsable(false)] public string ClSerialize { get { return NinjaTrader.Gui.Design.Se rializableColor.ToString( pSwingBarColor); } set { pSwingBarColor = NinjaTrader.Gui.Design.Se rializableColor.FromStrin g(value); } } #endregion } } #region NinjaScript generated code. Neither change nor remove. // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { public partial class Indicator : IndicatorBase { private SeansAverage_v3[] cacheSeansAverage_v3 = null; private static SeansAverage_v3 checkSeansAverage_v3 = new SeansAverage_v3(); /// <summary> /// Translated from TradeStation /// </summary> /// <returns></returns> public SeansAverage_v3 SeansAverage_v3(int period, bool roundToTick) { return SeansAverage_v3(Input, period, roundToTick); } /// <summary> /// Translated from TradeStation /// </summary> /// <returns></returns> public SeansAverage_v3 SeansAverage_v3(Data.IDat aSeries input, int period, bool roundToTick) { checkSeansAverage_v3.Peri od = period; period = checkSeansAverage_v3.Peri od; checkSeansAverage_v3.Roun dToTick = roundToTick; roundToTick = checkSeansAverage_v3.Roun dToTick; if (cacheSeansAverage_v3 != null) for (int idx = 0; idx < cacheSeansAverage_v3.Leng th; idx++) if (cacheSeansAverage_v3[idx].Period == period && cacheSeansAverage_v3[idx].RoundToTick == roundToTick && cacheSeansAverage_v3[idx].EqualsInput(input)) return cacheSeansAverage_v3[idx]; SeansAverage_v3 indicator = new SeansAverage_v3(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarC lose = CalculateOnBarClose; indicator.Input = input; indicator.Period = period; indicator.RoundToTick = roundToTick; indicator.SetUp(); SeansAverage_v3[] tmp = new SeansAverage_v3[cacheSeansAverage_v3 == null ? 1 : cacheSeansAverage_v3.Leng th + 1]; if (cacheSeansAverage_v3 != null) cacheSeansAverage_v3.Copy To(tmp, 0); tmp[tmp.Length - 1] = indicator; cacheSeansAverage_v3 = tmp; Indicators.Add(indicator) ; return indicator; } } } // This namespace holds all market analyzer column definitions and is required. Do not change it. namespace NinjaTrader.MarketAnalyze r { public partial class Column : ColumnBase { /// <summary> /// Translated from TradeStation /// </summary> /// <returns></returns> [Gui.Design.WizardConditio n("Indicator")] public Indicator.SeansAverage_v3 SeansAverage_v3(int period, bool roundToTick) { return _indicator.SeansAverage_v 3(Input, period, roundToTick); } /// <summary> /// Translated from TradeStation /// </summary> /// <returns></returns> public Indicator.SeansAverage_v3 SeansAverage_v3(Data.IDat aSeries input, int period, bool roundToTick) { return _indicator.SeansAverage_v 3(input, period, roundToTick); } } } // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { public partial class Strategy : StrategyBase { /// <summary> /// Translated from TradeStation /// </summary> /// <returns></returns> [Gui.Design.WizardConditio n("Indicator")] public Indicator.SeansAverage_v3 SeansAverage_v3(int period, bool roundToTick) { return _indicator.SeansAverage_v 3(Input, period, roundToTick); } /// <summary> /// Translated from TradeStation /// </summary> /// <returns></returns> public Indicator.SeansAverage_v3 SeansAverage_v3(Data.IDat aSeries input, int period, bool roundToTick) { if (InInitialize && input == null) throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method"); return _indicator.SeansAverage_v 3(input, period, roundToTick); } } } #endregion | ||
| |
|
![]() |
| Tags |
| average, coding, ninja, ttm |
| Thread Tools | Search this Thread |
| Display Modes | |
| |
| ∧ Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Free MP for Ninja | darthtrader | Market Profile | 17 | 01-19-2009 05:55 PM |
| ? Ninja Trader | bobby | Introduce Yourself | 2 | 11-22-2008 02:02 PM |
| Using .eld Indicators in Ninja Trader | coldsigh | Coding Forum | 3 | 10-09-2008 01:44 AM |
| Ninja Trader and Interactive Brokers | Freddie | Brokers and Data Feeds | 3 | 02-21-2007 11:30 PM |
| Question with Ninja.... | Soultrader | Brokers and Data Feeds | 9 | 01-25-2007 12:18 PM |