Indicator from Ninjascript to Thinkscript

Saylarr

Member
VIP
Anyone who can help me convert this indicator that is in Ninjascript to Thinkscript so I can use it in TOS?


Here is the code:

Code:
#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.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion

//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
    public class XTL : Indicator
    {
        private int period = 35;
        private int fixedValue = 37;
       
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description                                    = @"The primary purpose of the Expert Trend Locator (XTL) is to help identify the early stages of a potential major Elliott Wave 3 building.";
                Name                                        = "XTL";
                Calculate                                    = Calculate.OnBarClose;
                IsOverlay                                    = true;
                DisplayInDataBox                            = false;
                DrawOnPricePanel                            = true;
                DrawHorizontalGridLines                        = true;
                DrawVerticalGridLines                        = true;
                PaintPriceMarkers                            = true;
                ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                //See Help Guide for additional information.
                IsSuspendedWhileInactive                    = true;
               
                BrushUp                                        = Brushes.Blue;
                BrushNeutral                                = Brushes.DarkGray;
                BrushDown                                    = Brushes.Red;
               
            }
            else if (State == State.Configure)
            {
            }
        }

        protected override void OnBarUpdate()
        {
            if (CCI(period)[0] > fixedValue)
            {
                BarBrush = BrushUp;
            }
            else if (-fixedValue <= CCI(period)[0] && CCI(period)[0] <= fixedValue)
            {
                BarBrush = BrushNeutral;
            }
            else if (CCI(period)[0] < -fixedValue)
            {
                BarBrush = BrushDown;
            }
           
        }
       
        #region Properties
       
        [NinjaScriptProperty]
        [Display(Name = "Period", Description = "", GroupName = "Parameters", Order = 1)]
        public int Period
        {
            get { return period; }
            set { period = Math.Max(1, value); }
        }
       
        [XmlIgnore()]
        [Display(Name = "Uptrend", GroupName = "Colors", Order = 2)]
        public Brush BrushUp
        { get; set; }
       
        [Browsable(false)]
        public string BrushUpSerialize
        {
            get { return Serialize.BrushToString(BrushUp); }
               set { BrushUp = Serialize.StringToBrush(value); }
        }
       
        [XmlIgnore()]
        [Display(Name = "Neutral", GroupName = "Colors", Order = 3)]
        public Brush BrushNeutral
        { get; set; }
       
        [Browsable(false)]
        public string BrushNeutralSerialize
        {
            get { return Serialize.BrushToString(BrushNeutral); }
               set { BrushNeutral = Serialize.StringToBrush(value); }
        }
       
        [XmlIgnore()]
        [Display(Name = "Downtrend", GroupName = "Colors", Order = 4)]
        public Brush BrushDown
        { get; set; }
       
        [Browsable(false)]
        public string BrushDownSerialize
        {
            get { return Serialize.BrushToString(BrushDown); }
               set { BrushDown = Serialize.StringToBrush(value); }
        }
       
        #endregion
    }
}

#region NinjaScript generated code. Neither change nor remove.

namespace NinjaTrader.NinjaScript.Indicators
{
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
        private XTL[] cacheXTL;
        public XTL XTL(int period)
        {
            return XTL(Input, period);
        }

        public XTL XTL(ISeries<double> input, int period)
        {
            if (cacheXTL != null)
                for (int idx = 0; idx < cacheXTL.Length; idx++)
                    if (cacheXTL[idx] != null && cacheXTL[idx].Period == period && cacheXTL[idx].EqualsInput(input))
                        return cacheXTL[idx];
            return CacheIndicator<XTL>(new XTL(){ Period = period }, input, ref cacheXTL);
        }
    }
}

namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
        public Indicators.XTL XTL(int period)
        {
            return indicator.XTL(Input, period);
        }

        public Indicators.XTL XTL(ISeries<double> input , int period)
        {
            return indicator.XTL(input, period);
        }
    }
}

namespace NinjaTrader.NinjaScript.Strategies
{
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
        public Indicators.XTL XTL(int period)
        {
            return indicator.XTL(Input, period);
        }

        public Indicators.XTL XTL(ISeries<double> input , int period)
        {
            return indicator.XTL(input, period);
        }
    }
}

#endregion
 

adii800

Member
hey @Saylarr, I am thinking of making a strategy that rides the trend using this indicator as it appears to hold value.

What indicators and time frames do you use this with that have yielded the best results?

Thanks!
 

Don

New member
In my opinion, this indicator paint bar to Bullish (Cyan) Neutral (White) and Bearish (Red).
Using CCI with a period of 35.
When CCI above 37: Bullish
CCI below -37: Bearish
CCI between -37 and 37: Neutral
 

Saylarr

Member
VIP
An explanation of what the indicator does would be nice;)



It is an approximation to the XTL indicator of Esignal's Advanced get. Its function is the same, to use the alternation of color signals between candles to plot break or reversal targets.
As they say below, it works with an average with the CCI.

Regards
 

Similar threads

Top