Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with modifying Indicator

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

    Help with modifying Indicator

    Hi,
    I copied the SMA indicator and was modifying it to make a new indicator as below and on compiling get following errors. I think I replicated the required definitions - can you please tell me where I went wrong. TIA suraj.

    Ps is there an easier way for me to post the NinjaScript compiler text and error messages than I have done manually? thanks.
    ----
    Modified indicator snippet:

    public class DPO : Indicator
    {
    private double priorSum;
    private double sum;
    private double nPeriod;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    50Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionDPO;
    51 Name = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meDPO;
    IsOverlay = true;
    IsSuspendedWhileInactive = true;
    Period = 20;
    nPeriod = 0;

    57 AddPlot(Brushes.Goldenrod, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meDPO);
    AddLine(Brushes.DarkGray, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZe roLine);
    }
    else if (State == State.Configure)​ ....
    .........
    -----------
    errors flagged on compiling:
    for lines 50 and 51 I get error CS0117 (per Google– 'type' does not contain a definition for 'identifier' This occurs when you are trying to call a method or use a property on an instance of an object, but there is no method or property with that name​}
    and the column flagged is after Custom.Resource. NinjaScriptIndicatorDescriptionDPO and NinjaScriptIndicatorNameDPO

    of course line 57 gets flagged because compiler did not recognize NinjaScriptIndicatorName in line 51


    #2
    Hello suraj,

    When making copies of system indicators you should open the original indicator and then right click -> save as. That will make sure the naming in the file is correct and all of the custom resources that are being used are removed. Your scripts name should be Name = "DPO";

    To correct all of the errors at once it would be best to remove the script you made and do a save as and then make the modifications.

    Comment


      #3
      Hi Jesse,
      thanks for the pointer. I had opened the indicator and had saved as file name DPO. So to check and start with a clean slate I first opened and compiled the SMA indicator just tomake sure the original indicator is ok and it gave error message saying DPO name undefined. To clear this I then deleted the DPO file in indicators list by right click> delete. Then I closed Ninja Trader and restarted. On opening SMA indicator and compiling - now compile was OK - so I thought I am starting with a clean slate.
      I then right clicked and saved SMA indicator as DPO.
      At this point I saw that on line 43 Name = "DPO"; had been already changed by Ninjatrader, but line 33 still showed public class SMA : Indicator and compiling gave the error message that namespace for ninjascript Indicator already conmtains SMA. Also line 42 Description still had Ninjascript.Custom.Resource.NinjaScriptIndicator.d escriptionSMA;
      And also line 48 had AddPlot(brushes.Goldenrod, NinjaTrader.custom.Resource.NinjaScriptIndicatorNa meSMA); so I am assuming these other lines I need to change manually
      Also I am wondering that if I try to separately open SMA indicator and compile I will see the error that resource DPO is not defined?

      So I should probably first change all references to SMA to DPO save the DPO indicator (or should I use save as DPO?) close this DPO file and then open SMA indicator and recompile to make sure The other saved indicator is clear of all references to SMA that could interfere?

      I think the real problem I am finding is that after saving SMA as DPO - the name on top of the script editor is still showing "NinjaScript Indicators SMA" on the script editor heading on closing this one and opening SMA indicator and trying to compile it complains DPO.cs the namespace 'NinjaTrader NinjascriptIndicators' already contains a definition for SMA

      So I am a little unsure of the sequence I need to use when making a copy of the SMA indicator.

      can you please tell em the sequence to use in making this conversion.
      thanks,
      suraj

      Comment


        #4
        Hello suraj,

        Are you using the current release of the platform? The filename, class name and Name = "" string all get changed in the new file when you do a right click > save as from a stock indicator. That does not replace the other strings in the file that were custom resources like the description or plot names, those are left for you to edit manually after you create the script. If you are having a problem with it not saving the filename/classname/name= strings with the SMA then something is preventing that from happening such as using an old release or there was a problem with your installation.

        To make a new indicator you need to make sure the filename, classname and Name="" strings are correct. The filename should generally match the classname and the Name = string is what shows up in the platforms menus.






        Comment


          #5
          Hi Jesse,

          thanks for the pointers - I am using version 8.0.28.0 64-bit - I installed this recently when I was having problems linking to my data feeds and was told to update to this version ( it cleared the data feed access problem).

          since my post above I used the wizard to create the template for the indicator and it correctly filled in the name etc but I am having problems with two other aspects: (1) I am incorrectly using data types with logic to calculate my indicator - my understanding of even how the SMA indicator is calculated is wanting. (2) the wizard creates the indicator plot definitions but even when I substitute the standard SMA calculations for my indicator with name DPO - it does not plot the "DPO" indicator - which should show the SMA values - I am trying to go through parts of the Ninjascript to figure out how the SMA indicator is being calculated and how the plots are specified and actually presented.

          any pointers would be welcome.
          thanks,
          Suraj

          Comment


            #6
            Hello suraj,

            That explains the problem with renaming, that version has some issues with the NinjaScript editor and is an older version. The current release corrects those issues, the current release is 8.1.2.0.

            In regard to the other items, to learn how the SMA calculates it would be best to review the original SMA and its code. It uses special logic for series with remove last bar such as renko so if you are not using a bars type that has remove last bar you can ignore the logic inside the following condition:

            Code:
            if (BarsArray[0].BarsType.IsRemoveLastBarSupported)
            {​
            }
            The else part of that condition is the code that is used for all other bars types like Minute bars.

            If you make a copy of the SMA indicator you can add prints into the logic to output bar times and prices to get a better idea of how the calculation works.

            Regarding the following statement:

            (2) the wizard creates the indicator plot definitions but even when I substitute the standard SMA calculations for my indicator with name DPO - it does not plot the "DPO" indicator - which should show the SMA values
            Your custom indicator named DPO is what would need to do the calculation and plot the value, the original SMA would remain unchanged and would be a completely separate indicator. If you make a copy of the original SMA indicator you would be editing that new copies code to do a new calculation inside the OnBarUpdate override. Your new calculation is what would plot the value you want the DPO to produce. Your DPO indicator would not call the DPO indicator but would instead just use math with the available data and then plot the result.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            636 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            366 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            107 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            568 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            571 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X