Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Does anyone know how to script this

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Does anyone know how to script this

    Hi All,
    Can anyone help me script anaTraderDynamicIndex to trade ??? has anyone does this. What I like to know is how to place order when green is above Red and Yello for long and vice versa.

    Thanks
    Bill
    Attached Files

    #2
    Hello billsingh,

    Thank you for your post.

    You would need to call the plots of the indicator when calling it's method. For example, the syntax for the Bollinger to call it's upper plot is the following:
    Code:
    Bollinger(double numStdDev, int period).Upper[int barsAgo]
    I am not familiar with the indicator you are using but the call to the plots is the same.

    Comment


      #3
      Hi Pat,
      I don't understand. Can you give me the example from the following. Here is the code for the indicator. As I said all I want to do it check when the Green Cross the Red and Yellow and vice versa.

      #region Using declarations
      using System;
      using System.Diagnostics;
      using System.Drawing;
      using System.Drawing.Drawing2D;
      using System.ComponentModel;
      using System.Xml.Serialization;
      using NinjaTrader.Data;
      using NinjaTrader.Gui.Chart;
      #endregion

      // This namespace holds all indicators and is required. Do not change it.
      namespace NinjaTrader.Indicator
      {
      /// <summary>
      /// The Traders Dynamic Index (TDI) by Dean Malone is a trend following momentum indicator based on the RSI. /// </summary>
      [Description("The Traders Dynamic Index (TDI) by Dean Malone is a trend following momentum indicator based on the RSI.")]
      public class anaTradersDynamicIndex : Indicator
      {
      #region Variables

      private int rsiPeriod = 13;
      private int pricePeriod = 2;
      private int signalPeriod = 7;
      private int bandPeriod = 34;
      private double stdDevNumber = 1.62;
      private double stdDevValue = 0.0;
      private double avg = 0.0;
      private Color main = Color.Lime;
      private Color signal = Color.Red;
      private Color bbAverage = Color.Gold;
      private Color bbUpper = Color.MediumPurple;
      private Color bbLower = Color.MediumPurple;
      private Color baselineColor = Color.DarkGray;
      private Color upperlineColor = Color.DarkGray;
      private Color lowerlineColor = Color.DarkGray;
      private int plot0Width = 2;
      private PlotStyle plot0Style = PlotStyle.Line;
      private DashStyle dash0Style = DashStyle.Solid;
      private int plot1Width = 2;
      private PlotStyle plot1Style = PlotStyle.Line;
      private DashStyle dash1Style = DashStyle.Solid;
      private int plot2Width = 2;
      private PlotStyle plot2Style = PlotStyle.Line;
      private DashStyle dash2Style = DashStyle.Solid;
      private int plot3Width = 1;
      private PlotStyle plot3Style = PlotStyle.Line;
      private DashStyle dash3Style = DashStyle.Solid;
      private int plot4Width = 3;
      private PlotStyle plot4Style = PlotStyle.Square;
      private DashStyle dash4Style = DashStyle.Dash;
      private int valueUpperLine = 68;
      private int valueLowerLine = 32;
      private int baselineWidth = 1;
      private DashStyle baselineStyle = DashStyle.Dash;
      private int upperlineWidth = 1;
      private DashStyle upperlineStyle = DashStyle.Dash;
      private int lowerlineWidth = 1;
      private DashStyle lowerlineStyle = DashStyle.Dash;

      private RSI DYNRSI;
      private SMA DYNPrice;
      private SMA DYNSignal;
      private SMA DYNAverage;
      private StdDev SDBB;
      #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.Gray, 2), PlotStyle.Line, "PriceLine"));
      Add(new Plot(new Pen(Color.Gray, 2), PlotStyle.Line, "Signalline"));
      Add(new Plot(new Pen(Color.Gray, 2), PlotStyle.Line, "Average"));
      Add(new Plot(new Pen(Color.Gray, 1), PlotStyle.Line, "Upper"));
      Add(new Plot(new Pen(Color.Gray, 1), PlotStyle.Line, "Lower"));
      Add(new Line(Color.Gray, 50, "Baseline"));
      Add(new Line(Color.Gray, 68, "Upper"));
      Add(new Line(Color.Gray, 32, "Lower"));

      PlotsConfigurable = false;
      LinesConfigurable = false;
      }

      /// <summary>
      /// Calculates the indicator value(s) at the current index.
      /// </summary>
      protected override void OnStartUp()
      {
      DYNRSI = RSI(Input,RSIPeriod,1);
      DYNPrice = SMA(DYNRSI,PricePeriod);
      DYNSignal = SMA(DYNRSI,SignalPeriod);
      DYNAverage = SMA(DYNRSI, BandPeriod);
      SDBB = StdDev(DYNRSI,BandPeriod);
      Plots[0].Pen.Color = main;
      Plots[1].Pen.Color = signal;
      Plots[2].Pen.Color = bbAverage;
      Plots[3].Pen.Color = bbUpper;
      Plots[4].Pen.Color = bbLower;
      Plots[0].Pen.Width = plot0Width;
      Plots[0].PlotStyle = plot0Style;
      Plots[0].Pen.DashStyle = dash0Style;
      Plots[1].Pen.Width= plot1Width;
      Plots[1].PlotStyle = plot1Style;
      Plots[1].Pen.DashStyle = dash1Style;
      Plots[2].Pen.Width = plot2Width;
      Plots[2].PlotStyle = plot2Style;
      Plots[2].Pen.DashStyle = dash2Style;
      Plots[3].Pen.Width= plot3Width;
      Plots[3].PlotStyle = plot3Style;
      Plots[3].Pen.DashStyle = dash3Style;
      Plots[4].Pen.Width= plot3Width;
      Plots[4].PlotStyle = plot3Style;
      Plots[4].Pen.DashStyle = dash3Style;
      Lines[0].Pen.Color = baselineColor;
      Lines[1].Pen.Color = upperlineColor;
      Lines[2].Pen.Color = lowerlineColor;
      Lines[0].Pen.Width = baselineWidth;
      Lines[0].Pen.DashStyle = baselineStyle;
      Lines[1].Value = valueUpperLine;
      Lines[1].Pen.Width = upperlineWidth;
      Lines[1].Pen.DashStyle = upperlineStyle;
      Lines[2].Value = valueLowerLine;
      Lines[2].Pen.Width = lowerlineWidth;
      Lines[2].Pen.DashStyle = lowerlineStyle;
      }

      protected override void OnBarUpdate()
      {
      avg = DYNAverage[0];
      stdDevValue = SDBB[0];
      PriceLine.Set(DYNPrice[0]);
      SignalLine.Set(DYNSignal[0]);
      Average.Set(avg);
      Upper.Set(avg + stdDevNumber * stdDevValue);
      Lower.Set(avg - stdDevNumber * stdDevValue);

      Comment


        #4
        Hello Bill,

        If you are coding this in a strategy the code would reflect the following:
        Code:
        anaTradersDynamicIndex().Upper[0]
        You would need to figure out which plot is the color you are referring to and then check for the cross conditions. Information on CrossAbove can be found at the following link: http://www.ninjatrader.com/support/h...crossabove.htm

        Comment


          #5
          Got it thanks Pat.

          Comment


            #6
            Hi Pat,
            If I want trade TSSuperTrend when it shows green under bar go long and when it show red dash over bar go shot..what would be the best way to do it or simpler code ???

            Thanks
            Bill

            Comment


              #7
              Hi Pat,
              I saw your another post on this. But how do I check what trend we are in (up or down) ????

              You need to add the TSSuperTrend.Utility to your declarations (located at the top of the code):
              Code:
              using TSSuperTrend.Utility;
              The you can call the indicator in the following manner:
              Code:
              TSSuperTrend(14, MovingAverageType.SMA, 2.618, 14, SuperTrendMode.ATR).UpTrend[0]
              [/QUOTE]


              Thanks
              Bill

              Comment


                #8
                Same question I have on AdaptiveSuperTrendEW2. How do you check the trend. What is the code for that.
                Here is your thread for that

                Is this how we check ??? It doesn't seems right. I want to check when the trend changed

                if (AdaptiveSuperTrendEW2(1, true).UpTrend[0] < Close[0])
                {
                Print("It is long Signal);
                }

                // Condition set 2
                if (AdaptiveSuperTrendEW2(1, true).DownTrend[0] > Close[0])
                {
                Print("It is short Signal");
                }
                Last edited by billsingh; 11-15-2014, 02:08 AM.

                Comment


                  #9
                  Hello billsingh,

                  Thank you for your response.

                  Below is the code for the TSSuperTrend. Now the reason this works is the plot is not set to anything if we are not in that trend and therefore NinjaTrader assigns the plot the same value as the Close[0]. This means if it does not equal the Close[0] then we are in the respective trend.
                  Code:
                  			if(TSSuperTrend(14, MovingAverageType.SMA, 2.618, 14, SuperTrendMode.ATR).UpTrend[0] != Close[0])
                  				Print("Up");
                  			if(TSSuperTrend(14, MovingAverageType.SMA, 2.618, 14, SuperTrendMode.ATR).DownTrend[0] != Close[0])
                  				Print("Down");
                  The same idea is applied to the AdaptiveSuperTrendEW2.

                  Comment


                    #10
                    Thanks Pat... I have 2 more question.

                    There is lot of slippage...when it place the order, order is place 5 - 6 ticks up or down, how it can be minimized ???

                    I have stretegy that is placing 3 order...in in realtime it is placing 9 or more orders....how is this possible ??? Can I email you so you can look at it ??

                    Thanks
                    Bill

                    Comment


                      #11
                      Hi Pat,
                      Here is my code and it works offine but when the markets are open it does not work. May I know what I am doing wrong here and what should be the right code.

                      if (TSSuperTrendV2_4(10, MovingAverageType.HMA, 2, 3, SuperTrendMode.ATR).UpTrend[0] < Close[0])
                      {
                      if (Position.MarketPosition == MarketPosition.Flat)

                      {

                      EnterLong(1, "Entry1");
                      EnterLong(1, "Entry2");
                      EnterLong(1, "Entry3");

                      }

                      if (Position.MarketPosition == MarketPosition.Short)

                      {

                      ExitShort();
                      EnterLong(1, "Entry1");
                      EnterLong(1, "Entry2");
                      EnterLong(1, "Entry3");

                      }



                      if (TSSuperTrendV2_4(10, MovingAverageType.HMA, 2, 3, SuperTrendMode.ATR).DownTrend[0] > Close[0])
                      {

                      if (Position.MarketPosition == MarketPosition.Flat)

                      {

                      EnterShort(1, "Entry1");
                      EnterShort(1, "Entry2");
                      EnterShort(1, "Entry3");


                      }

                      if (Position.MarketPosition == MarketPosition.Long)

                      {

                      ExitLong();
                      EnterShort(1, "Entry1");
                      EnterShort(1, "Entry2");
                      EnterShort(1, "Entry3");

                      }
                      }

                      Comment


                        #12
                        Hi billsingh,

                        May I have an export of your script to test?

                        To export your script do the following:
                        1. Click File -> Utilities -> Export NinjaScript
                        2. Enter a unique name for the file in the value for 'File name:'
                        3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
                        4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


                        By default your exported file will be in the following location:
                        • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>


                        Below is a link to the help guide on Exporting NinjaScripts.
                        http://www.ninjatrader.com/support/h...nt7/export.htm



                        Just to confirm, I'm checking for the position to become long 9, is this correct?


                        Is is possible for these two conditions to be true at the same time?

                        if (TSSuperTrendV2_4(10, MovingAverageType.HMA, 2, 3, SuperTrendMode.ATR).UpTrend[0] < Close[0])

                        if (TSSuperTrendV2_4(10, MovingAverageType.HMA, 2, 3, SuperTrendMode.ATR).DownTrend[0] > Close[0])

                        Have you added prints to see if these are both true at the same time?
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Chelsea,
                          Thanks for you help yesterday. My strategy is dying after only few orders with the following errors.

                          **NT** A Set() method to submit an exit order at '11/17/2014 6:13:12 PM' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.
                          **NT** An over fill was detected on order 'Order='1b4ece91304345d4b76fa6dfe7203ea7/Sim101' Name='Entry1' State=Filled Instrument='GC 12-14' Action=SellShort Limit price=0 Stop price=0 Quantity=1 Strategy='TSSuperTrend' Type=Market Tif=Gtc Oco='' Filled=1 Fill price=1184.8 Token='1b4ece91304345d4b76fa6dfe7203ea7' Gtd='12/1/2099 12:00:00 AM'' generated by strategy 'TSSuperTrend/cfba6bd561bd4359ac6800666acc84c4' : This strategy will be disabled and NinjaTrader will attempt to cancel/close any strategy generated orders and positions. Please check your account orders and positions and take any appropriate action.
                          **NT** Disabling NinjaScript strategy 'TSSuperTrend/cfba6bd561bd4359ac6800666acc84c4'

                          Comment


                            #14
                            Hi billsingh,

                            From the help guide:
                            An overfill is categorized as when an order returns a "Filled" or "PartFilled" state after the order was already marked for cancellation. The cancel request could have been induced by an explicit CancelOrder() call, from more implicit cancellations like those that occur when another order sharing the same OCO ID is filled, or from things like order expirations.
                            http://www.ninjatrader.com/support/h...reoverfill.htm

                            When calling an entry method in the opposite direction of your position this will cause your position to be reversed. NinjaTrader will automatically submit an order to close your existing position and then enter an order to enter you into the opposite position.

                            If you exit and then call an entry method in the same run of OnBarUpdate, the Position.MarketPosition will not have known that your position is closed and will combine your orders and end up sending 3 orders. The first order is the exit position from your exit method, the second order is to close the position from NinjaTrader automatically reversing your position, the third order is to enter you into the opposite position.

                            Since an exit order is cancelled if the entry it is exiting no longer exists, this cancellation attempt of the exit order can cause an overfill since it has already filled.

                            This is not elaborated on in the help guide but the help guide does say "Entry methods are used to submit orders that create a market position if none exists or to reverse an existing position.". This is in the Entry Methods section in the link below.



                            In your script you have:

                            ExitShort();
                            EnterLong(1, "Entry1");
                            EnterLong(1, "Entry2");
                            EnterLong(1, "Entry3");

                            This is going to cause undesired behavior. Never call an exit on the same bar as an entry. Either exit and then wait for the new bar or don't submit the exit.
                            Chelsea B.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            599 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            344 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            103 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            558 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            557 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X