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

Duplicating and then Modifying an Indicator

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

    Duplicating and then Modifying an Indicator

    I'm trying to duplicate an indicator so that I can keep the original and then make some modifications to the new one. I opened the existing indicator in the ninjascript editor and then did "Save As" saved as new name. Tried to compile and got some errors regarding duplicate public enum. I commented those out. It compiled ok but when trying to apply to the chart I get this error "Unhandled exception: Unable to cast object of type NinjaTrader.NinjaScript.Indicators.NewIndicatorNam e to type NinjaTrader.NinjaScript.Indicators.OldIndicatorNam e.

    Any ideas or perhaps my duplication method was bad. The indicator I'm attempted to modify is https://ninjatraderecosystem.com/use...indicator-nt8/
    I like how it's made but just am altering the pivot calculations.

    #2
    Hello synthhokie,

    Thanks for your post.

    This error indicates that it is likely that a TypeConverter in the script is causing the error to occur.

    I have created a copy of the NTSvePivots indicator named NTSvePivotsMod, commented out the enums that thew a duplicate enum error, and renamed the TypeConverter around line 33 to use the name of the script copy instead of the original script name. See below.

    The TypeConverter was as follows:
    [TypeConverter("NinjaTrader.NinjaScript.Indicators.NTSvePivotsTypeConverter")]

    We must change this to use the same name as our copy.
    [TypeConverter("NinjaTrader.NinjaScript.Indicators.NTSvePivotsModTypeConverter")]

    See the attached script, NTSvePivotsMod which is a copy of the NTSvePivots indicator.

    Let us know if we may assist further.
    Attached Files
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      This worked perfect. Thank you! Only strange thing is the values for the pivots are slightly off. When example yesterdays (9-14-21) ES 12-21 high = 4479.50 low = 4425.25 close = 4434.75. When I input these in to the "user defined" HLC it works but when using the daily or intraday calculations it doesn't work. I realize this is not your script. Any help would be greatly appreciated. I can also open a new thread.

      Comment


        #4
        Hello synthhokie,

        Thanks for your note.

        When testing the NTSvePivots indicator, I am able to see the indicator working using any HLCCalculation Mode (intraday data, daily bars, and user-defined values). I have attached the indicator to an ES 12-21 Daily chart.

        See the attached screenshot of the indicator working and the settings used.

        Are you able to see the indicator working when using the same settings?

        Let us know if we may assist further.
        Attached Files
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Yeah it's working fine however after I edited the pivot values they just aren't aligning to calculator math unless I input them as user defined. Here are my pivots. Unless I input C = 4434.75 H = 4479.50 and L = 4425.25. These are the values I see on the daily chart from yesterday. With any calculation mode but user defined they are slightly shifted. Example would be BURH should be 4420.

          Code:
          r = currentHigh - currentLow;
          but2 = currentHigh / currentLow * currentClose;
          bels = currentClose + (r * (1.1 / 2));
          berl = currentClose + (r * (1.1 / 4));
          but1 = bels + (1.168 * (bels - berl));
          berh = bels - (bels - berl) / 2;
          burh = currentClose - (r * (1.1 / 4));
          buls = currentClose - (r * (1.1 / 2));
          bet2 = currentClose - (but2 - currentClose);
          burl = burh - (burh - buls) / 2;
          bet1 = buls - (1.168 * (burh - buls));

          Comment


            #6
            Hello synthhokie,

            Thanks for your note.

            If you are wanting to modify pivot levels, you could try modifying the current pivot levels in the indicator.

            These pivot levels can be found around line 204 in the script and are seen below.

            Also, I am attaching an example script that demonstrates modifying these pivot levels

            Code:
            pp = (currentHigh + currentLow + currentClose) / 3;
            s1 = 2 * pp - currentHigh;
            r1 = 2 * pp - currentLow;
            s2 = pp - (currentHigh - currentLow);
            r2 = pp + (currentHigh - currentLow);
            s3 = pp - 2 * (currentHigh - currentLow);
            r3 = pp + 2 * (currentHigh - currentLow);
            pl = currentLow;
            s1m = (pp - s1) / 2 + s1;
            r1m = (r1 - pp) / 2 + pp;
            s2m = (s1 - s2) / 2 + s2;
            r2m = (r2 - r1) / 2 + r1;
            s3m = (s2 - s3) / 2 + s3;
            r3m = (r3 - r2) / 2 + r2;
            ph = currentHigh;
            If you are wanting to add additional pivot levels to the script, you could use a DiffChecker to compare the NTSvePivots indicator code to the original Pivots indicator code to see how additional pivot levels are added.

            Here is a publicly available line to a DiffChecker: https://www.diffchecker.com/diff

            Let us know if we may assist further.
            Attached Files
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              I was able to modify them and it works other than calculation difference between when using the intraday/daily calc vs the user defined calculation. It's as if it's not getting the previous day data correctly. They are close but off buy a few ticks/points. Have to wonder if the indicator is maybe using the settlement as the close or something. I don't know enough about the code to really say.

              Comment


                #8
                Hello synthhokie,

                Thanks for your note.

                Are you using the PriorDayOHLC indicator to visually get the high, low, and close from the previous day to type in the correct UserDefinedHigh, UserDefinedLow, and UserDefinedClose values?

                The currentHigh, currentLow, and currentClose calculations in the NTSvePivots script can be seen around line 227 and use the prior day high, low, and close values when UserDefined values are not specified.

                Something you could do is add prints to your script to print out UserDefinedHigh, high, UserDefinedLow, low, UserDefinedClose, and close. These values could then be compared to see if the same values are being used for calculations.

                Let us know if we may assist further.
                Brandon H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Ousher, Yesterday, 11:12 PM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by You4Life, Yesterday, 08:20 PM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by focus333, Yesterday, 05:56 PM
                3 responses
                16 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by itsthefriz, Yesterday, 04:19 PM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_ShawnB  
                Started by johnMoss, Yesterday, 04:06 PM
                0 responses
                8 views
                0 likes
                Last Post johnMoss  
                Working...
                X