Converting indicator from ninjascript to thinkscript

S

snowboard06

New member
Hello all!

I have an indicator I have created on NinjaTrader that I would like possibly converted to thinkscript if at all possible. Any brilliant minds out there able to help me out? I am more than willing to share the indicator for anyone interested.

Thanks a bunch!
Chris
 
BenTen

BenTen

Administrative
Staff
VIP
Please post your code so others can take a look at it.
 
S

snowboard06

New member
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 RGArrow345 : Indicator
    {
        private double priorValueLow3;
        private double priorValueHigh3;
        private double priorValueLow4;
        private double priorValueHigh4;
        private double priorValueLow5;
        private double priorValueHigh5;
        private Stochastics Stochastics1;
        private Bollinger Bollinger1;
        private Bollinger Bollinger2;
        private Bollinger Bollinger3;
        
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description                                    = @"Enter the description for your new custom Indicator here.";
                Name                                        = "RGArrow345";
                Calculate                                    = Calculate.OnEachTick;
                IsOverlay                                    = false;
                DisplayInDataBox                            = true;
                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                    = false;
                PeriodD                    = 8;
                PeriodK                    = 14;
                Smooth                    = 3;
                PeriodBB                = 20;
                StdDev4                    = 4;
                StdDev3                 = 3;
                StdDev5                 = 5;
                NumberLow                = 20;
                NumberHigh                = 80;
            }
            else if (State == State.Configure)
            {
            }
            else if (State == State.DataLoaded)
            {               
                Stochastics1            = Stochastics(Close, Convert.ToInt32(PeriodD), Convert.ToInt32(PeriodK), Convert.ToInt32(Smooth));
                Bollinger1                = Bollinger(Close, StdDev3, Convert.ToInt32(PeriodBB));
                Bollinger2                = Bollinger(Close, StdDev4, Convert.ToInt32(PeriodBB));
                Bollinger3              = Bollinger(Close, StdDev5, Convert.ToInt32(PeriodBB));
            }
        }

        protected override void OnBarUpdate()
        {
            //Add your custom indicator logic here.
            if (BarsInProgress != 0)
                return;

            if (CurrentBars[0] < 1)
            return;
            
            Print(Times[0][0].ToString() + @" PriceLow[1]: {1} " + Low[1].ToString() + @" > BollingerLower3[1]: {2} " + Bollinger1.Lower[1].ToString() + @" & PriceLow[0]: {3} " + Low[0].ToString() + @" < BollingerLower3[0]: {4} " + Bollinger1.Lower[0].ToString() + @" & StochasticK[0]: {5} " + Stochastics1.K[0].ToString() + @" < 20 ");
            
            Print(Times[0][0].ToString() + @" PriceHigh[1]: {1} " + High[1].ToString() + @" < BollingerUpper3[1]: {2} " + Bollinger1.Upper[1].ToString() + @" & PriceHigh[0]: {3} " + High[0].ToString() + @" > BollingerUpper3[0]: {4} " + Bollinger1.Upper[0].ToString() + @" & StochasticK[0]: {5} " + Stochastics1.K[0].ToString() + @" > 80 ");
            
            // Set 1
            if (IsFirstTickOfBar)
                
                priorValueLow3 = Bollinger1.Lower[0];
            
            if ((Stochastics1.K[0] < NumberLow)
                 && (Bollinger1.Lower[0] <= priorValueLow3 && (CrossBelow(Low, Bollinger1.Lower, 1))))
            {
                Draw.ArrowUp(this, @"GreenArrowUp"+CurrentBar, false, 0, (Low[0] + (-2 * TickSize)) , Brushes.Lime);
            }
            
            if (Bollinger1.Lower[0] <= priorValueLow3)
            {
                priorValueLow3 = Bollinger1.Lower[0];
            }
            
            // Set 2
            if (IsFirstTickOfBar)
                
                priorValueHigh3 = Bollinger1.Upper[0];
                
            if ((Stochastics1.K[0] > NumberHigh)
                 && (Bollinger1.Upper[0] >= priorValueHigh3 && (CrossAbove(High, Bollinger1.Upper, 1))))
            {
                Draw.ArrowDown(this, @"RedArrowDown"+CurrentBar, false, 0, (High[0] + (2 * TickSize)) , Brushes.Red);
            }
            
            if (Bollinger1.Upper[0] >= priorValueHigh3)
            {
                priorValueHigh3 = Bollinger1.Upper[0];
            }
            
            // Set 3
            if (IsFirstTickOfBar)
                
                priorValueLow4 = Bollinger2.Lower[0];
            
            if ((Stochastics1.K[0] < NumberLow)
                 && (Bollinger2.Lower[0] <= priorValueLow4 && (Low[0] < Bollinger2.Lower[0])))
            {
                Draw.ArrowUp(this, @"GreenArrowUp"+CurrentBar, false, 0, (Low[0] + (-2 * TickSize)) , Brushes.Lime);
            }
            
            if (Bollinger2.Lower[0] <= priorValueLow4)
            {
                priorValueLow4 = Bollinger2.Lower[0];
            }
            
            // Set 4
            if (IsFirstTickOfBar)
                
                priorValueHigh4 = Bollinger2.Upper[0];
                
            if ((Stochastics1.K[0] > NumberHigh)
                 && (Bollinger2.Upper[0] >= priorValueHigh4 && (High[0] > Bollinger2.Upper[0])))
            {
                Draw.ArrowDown(this, @"RedArrowDown"+CurrentBar, false, 0, (High[0] + (2 * TickSize)) , Brushes.Red);
            }
            
            if (Bollinger2.Upper[0] >= priorValueHigh4)
            {
                priorValueHigh4 = Bollinger2.Upper[0];
            }
            
            // Set 5
            if (IsFirstTickOfBar)
                
                priorValueLow5 = Bollinger3.Lower[0];
            
            if ((Stochastics1.K[0] < NumberLow)
                 && (Bollinger3.Lower[0] <= priorValueLow5 && (Low[0] < Bollinger3.Lower[0])))
            {
                Draw.ArrowUp(this, @"GreenArrowUp"+CurrentBar, false, 0, (Low[0] + (-2 * TickSize)) , Brushes.Lime);
            }
            
            if (Bollinger3.Lower[0] <= priorValueLow5)
            {
                priorValueLow5 = Bollinger3.Lower[0];
            }
            
            // Set 6
            if (IsFirstTickOfBar)
                
                priorValueHigh5 = Bollinger3.Upper[0];
                
            if ((Stochastics1.K[0] > NumberHigh)
                 && (Bollinger3.Upper[0] >= priorValueHigh5 && (High[0] > Bollinger3.Upper[0])))
            {
                Draw.ArrowDown(this, @"RedArrowDown"+CurrentBar, false, 0, (High[0] + (2 * TickSize)) , Brushes.Red);
            }
            
            if (Bollinger3.Upper[0] >= priorValueHigh5)
            {
                priorValueHigh5 = Bollinger3.Upper[0];
            }
        }

        #region Properties
        [NinjaScriptProperty]
        [Range(1, int.MaxValue)]
        [Display(Name="PeriodD", Order=1, GroupName="Parameters")]
        public int PeriodD
        { get; set; }

        [NinjaScriptProperty]
        [Range(1, int.MaxValue)]
        [Display(Name="PeriodK", Order=2, GroupName="Parameters")]
        public int PeriodK
        { get; set; }

        [NinjaScriptProperty]
        [Range(1, int.MaxValue)]
        [Display(Name="Smooth", Order=3, GroupName="Parameters")]
        public int Smooth
        { get; set; }

        [NinjaScriptProperty]
        [Range(1, int.MaxValue)]
        [Display(Name="PeriodBB", Order=4, GroupName="Parameters")]
        public int PeriodBB
        { get; set; }

        [NinjaScriptProperty]
        [Range(1, int.MaxValue)]
        [Display(Name="StdDev4", Order=5, GroupName="Parameters")]
        public int StdDev4
        { get; set; }
        
        [NinjaScriptProperty]
        [Range(1, int.MaxValue)]
        [Display(Name="StdDev3", Order=6, GroupName="Parameters")]
        public int StdDev3
        { get; set; }
        
        [NinjaScriptProperty]
        [Range(1, int.MaxValue)]
        [Display(Name="StdDev5", Order=7, GroupName="Parameters")]
        public int StdDev5
        { get; set; }
        
        [NinjaScriptProperty]
        [Range(1, int.MaxValue)]
        [Display(Name="NumberLow", Order=8, GroupName="Parameters")]
        public int NumberLow
        { get; set; }
        
        [NinjaScriptProperty]
        [Range(1, int.MaxValue)]
        [Display(Name="NumberHigh", Order=9, GroupName="Parameters")]
        public int NumberHigh
        { get; set; }
        #endregion

    }
}

#region NinjaScript generated code. Neither change nor remove.

namespace NinjaTrader.NinjaScript.Indicators
{
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
        private RGArrow345[] cacheRGArrow345;
        public RGArrow345 RGArrow345(int periodD, int periodK, int smooth, int periodBB, int stdDev4, int stdDev3, int stdDev5, int numberLow, int numberHigh)
        {
            return RGArrow345(Input, periodD, periodK, smooth, periodBB, stdDev4, stdDev3, stdDev5, numberLow, numberHigh);
        }

        public RGArrow345 RGArrow345(ISeries<double> input, int periodD, int periodK, int smooth, int periodBB, int stdDev4, int stdDev3, int stdDev5, int numberLow, int numberHigh)
        {
            if (cacheRGArrow345 != null)
                for (int idx = 0; idx < cacheRGArrow345.Length; idx++)
                    if (cacheRGArrow345[idx] != null && cacheRGArrow345[idx].PeriodD == periodD && cacheRGArrow345[idx].PeriodK == periodK && cacheRGArrow345[idx].Smooth == smooth && cacheRGArrow345[idx].PeriodBB == periodBB && cacheRGArrow345[idx].StdDev4 == stdDev4 && cacheRGArrow345[idx].StdDev3 == stdDev3 && cacheRGArrow345[idx].StdDev5 == stdDev5 && cacheRGArrow345[idx].NumberLow == numberLow && cacheRGArrow345[idx].NumberHigh == numberHigh && cacheRGArrow345[idx].EqualsInput(input))
                        return cacheRGArrow345[idx];
            return CacheIndicator<RGArrow345>(new RGArrow345(){ PeriodD = periodD, PeriodK = periodK, Smooth = smooth, PeriodBB = periodBB, StdDev4 = stdDev4, StdDev3 = stdDev3, StdDev5 = stdDev5, NumberLow = numberLow, NumberHigh = numberHigh }, input, ref cacheRGArrow345);
        }
    }
}

namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
        public Indicators.RGArrow345 RGArrow345(int periodD, int periodK, int smooth, int periodBB, int stdDev4, int stdDev3, int stdDev5, int numberLow, int numberHigh)
        {
            return indicator.RGArrow345(Input, periodD, periodK, smooth, periodBB, stdDev4, stdDev3, stdDev5, numberLow, numberHigh);
        }

        public Indicators.RGArrow345 RGArrow345(ISeries<double> input , int periodD, int periodK, int smooth, int periodBB, int stdDev4, int stdDev3, int stdDev5, int numberLow, int numberHigh)
        {
            return indicator.RGArrow345(input, periodD, periodK, smooth, periodBB, stdDev4, stdDev3, stdDev5, numberLow, numberHigh);
        }
    }
}

namespace NinjaTrader.NinjaScript.Strategies
{
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
        public Indicators.RGArrow345 RGArrow345(int periodD, int periodK, int smooth, int periodBB, int stdDev4, int stdDev3, int stdDev5, int numberLow, int numberHigh)
        {
            return indicator.RGArrow345(Input, periodD, periodK, smooth, periodBB, stdDev4, stdDev3, stdDev5, numberLow, numberHigh);
        }

        public Indicators.RGArrow345 RGArrow345(ISeries<double> input , int periodD, int periodK, int smooth, int periodBB, int stdDev4, int stdDev3, int stdDev5, int numberLow, int numberHigh)
        {
            return indicator.RGArrow345(input, periodD, periodK, smooth, periodBB, stdDev4, stdDev3, stdDev5, numberLow, numberHigh);
        }
    }
}

#endregion
 
S

snowboard06

New member
I have 3 different Bollinger Band deviations here, but the 4 standard deviation seems to work the best so I would like the others to be removed if possible.
 

Similar threads

Top