Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

modify NT 6.5 indicator to NT 7

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

    modify NT 6.5 indicator to NT 7

    There is an indicator in the NT 6.5 library called, "BuySellPressure Colored Bars". It will no longer work since I have upgraded to NT7. Can anyone tell me if there is an easy way to modify this to work on NT7, and if so how I could do this?

    Thanks very much,

    Safetrading

    #2
    Safetrading, can you perhaps attach the code here so we could take a look at it?

    Generally spoken NT7 introduced those code breaking changes, so you would need to review the 6.5 code and adapt as needed :

    Contains critical information including but not limited to migration, installation, connections and changes.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Reply

      The code is too long to post in the box, so I will break it up into 2 boxes. Below is the majority of the code, please let me know if there are small changes that could be made to get this working.
      Thanks again.


      protectedoverridevoid OnBarUpdate()
      {
      if (Historical)
      return;

      if (CurrentBar != activeBar)
      {
      previousVol = 0;
      activeBar = CurrentBar;
      }

      // Calculate buy/sell trades if indicator running in real-time
      if (!CalculateOnBarClose && startTime.Ticks <= Time[0].Ticks)
      {
      double tradeVol = previousVol == 0 ? Volume[0] : Volume[0] - previousVol;
      if (Close[0] >= GetCurrentAsk() && tradeVol >= MinTradeSize)
      buys.Set(buys[0] + tradeVol);
      elseif (Close[0] <= GetCurrentBid() && tradeVol >= MinTradeSize)
      sells.Set(sells[0] + tradeVol);
      elseif (buys[0] == 0 && sells[0] == 0)
      {
      buys.Set(1);
      sells.Set(1);
      }

      previousVol = Volume[0];

      }
      else
      {
      buys.Set(1);
      sells.Set(1);
      }

      int hexpcnt = (int) ((buys[0] - sells[0]) / (buys[0] + sells[0]) * 255);

      int colval = 255 - Math.Abs(hexpcnt);

      if (colval > 255) // Ensure color value <= 255
      colval = 255;

      if (hexpcnt > 0)
      BarColor = Color.FromArgb(colval, colval, 255);
      else
      BarColor = Color.FromArgb(255, colval, colval);

      }

      Comment


        #4
        Reply 2

        Here is the rest of the code;

        Thanks again for any assistance.

        #region Variables
        privateint minTradeSize = 1;
        // Wizard generated variables
        // User defined variables (add any user defined variables below)
        privateint activeBar = int.MaxValue;
        private DataSeries buys;
        privatedouble previousVol = 0;
        private DataSeries sells;
        private DateTime startTime;

        #endregion

        #region Properties

        [Description(
        "")]
        [Category(
        "Parameters")]
        [Gui.Design.DisplayNameAttribute(
        "Min Trade Size")]
        publicint MinTradeSize
        {
        get { return minTradeSize; }
        set { minTradeSize = Math.Max(0, value); }
        }
        #endregion

        Comment


          #5
          Hi safetrading, are there any errors in the logs (right-most tab of Control Center) when you try to run this indicator?
          AustinNinjaTrader Customer Service

          Comment


            #6
            reply

            Thanks for your interest, it is now working, I'm not quite sure why. I tried it on several charts yesterday and it did not work. This morning I edited a few lines to try to fix it, but my editing had no efect, so I changed it back to its original form and now it works.

            The only thing I can think of is this is the first time this indicator has been compiled since I upgraded from NT 6.5 to 7, maybe that had some effect?

            Thanks again,

            Safetrading

            Comment


              #7
              Yes, that's probably it. Indicators and strategies must be compiled before they can be used.
              AustinNinjaTrader Customer Service

              Comment


                #8
                reply

                Hi there

                Im a new member of NT forum and I want to thank all the contributors to this wonderful forum: learning so much!!! thank u again.

                I dont know if this is the right place to ask but I have this question: once I build an indicator in the chart, am I able to export that indicator as a .cs script and modify it at will?? I wouldnt possibly know how to code it.

                Thank u for your time

                Regards

                Comment


                  #9
                  Hi Michael, welcome to the forum!

                  Can you please clarify your question? You can export indicators from the File -> Utilities -> Export NinjaScript dialog, but once you export it you can't edit the .zip. You can still edit the .cs though, but that would be coding it.
                  AustinNinjaTrader Customer Service

                  Comment


                    #10
                    reply

                    Sorry if I wasnt clear. U see, what I mean is the following. Lets take an RSI, then I use as data input a MA, and that will trace a line on the chart or on a different panel. Now, I want to export THAT indicator I just build into a .cs file. Is it possible? Sorry if it sound silly, Im really new at this.

                    Comment


                      #11
                      I see, thanks for the clarification. This is not currently possible with NinjaTrader. You can, however, save this indicator-on-indicator as a chart template by right-clicking the chart -> templates -> save as -> save the template. You'll then be able to load the template whenever you want.
                      AustinNinjaTrader Customer Service

                      Comment


                        #12
                        Hi Michael, that custom indicator would unfortunately not be possible to create this way by 'exporting'. You would need to custom code it if you wish to further tweak and enhance it. A great way to start with NinjaScript are our tutorials here :



                        As a snippet to get started, an 20 bar SMA running on 7 bar WMA might look like this :

                        Code:
                        double myMaValue = SMA(WMA(Close, 7), 20)[0];
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          reply

                          Thank you Austin and Bertrand. yeah, was just wondering, something like "decompile" and translate into that language what u build. I will have a look at the coding session.
                          Thank u again

                          Regards

                          Comment


                            #14
                            You're welcome Michael, we do have a point and click interface as well that would offer script creation without programming and is a great way to get started learning the syntax, however it would be for strategies only :

                            BertrandNinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Shansen, 08-30-2019, 10:18 PM
                            24 responses
                            942 views
                            0 likes
                            Last Post spwizard  
                            Started by Max238, Today, 01:28 AM
                            0 responses
                            9 views
                            0 likes
                            Last Post Max238
                            by Max238
                             
                            Started by rocketman7, Today, 01:00 AM
                            0 responses
                            4 views
                            0 likes
                            Last Post rocketman7  
                            Started by wzgy0920, 04-20-2024, 06:09 PM
                            2 responses
                            28 views
                            0 likes
                            Last Post wzgy0920  
                            Started by wzgy0920, 02-22-2024, 01:11 AM
                            5 responses
                            33 views
                            0 likes
                            Last Post wzgy0920  
                            Working...
                            X