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

UnDead indicator

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

    UnDead indicator

    This morning I decided to add some color to one of my indicators when certain thresholds where reached. Nothing complicated. I changed:
    Code:
    protected override void Initialize()
           {
                Add(new Plot(Color.FromKnownColor(KnownColor.Transparent), PlotStyle.Line, "K"));
                Add(new Plot(Color.FromKnownColor(KnownColor.Plum), PlotStyle.Hash, "D"));
    
                Add(new Line(Color.FromKnownColor(KnownColor.Maroon), 75, "Above"));
                Add(new Line(Color.FromKnownColor(KnownColor.Black), 50, "Middle"));
                Add(new Line(Color.FromKnownColor(KnownColor.Maroon), 25, "Below"));
            }
    protected override void OnBarUpdate()
            {
    
                K.Set(stoch.K[0]);
                D.Set(stoch.D[0]);
             }
    #region Properties
            [Browsable(false)]    
            [XmlIgnore()]        
            public DataSeries K
            {
                get { return Values[0]; }
            }
            [Browsable(false)]    
            [XmlIgnore()]        
            public DataSeries D
            {
                get { return Values[1]; }
            }
    to
    Code:
     protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Line, "K_Above75"));
                Add(new Plot(Color.FromKnownColor(KnownColor.DarkViolet), PlotStyle.Line, "K_Middle"));
                Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Line, "K_Below25"));
                Add(new Plot(Color.FromKnownColor(KnownColor.Transparent), PlotStyle.Line, "K"));
                Add(new Plot(Color.FromKnownColor(KnownColor.Plum), PlotStyle.Hash, "D"));
    
                Add(new Line(Color.FromKnownColor(KnownColor.Maroon), 75, "Above"));
                Add(new Line(Color.FromKnownColor(KnownColor.Black), 50, "Middle"));
                Add(new Line(Color.FromKnownColor(KnownColor.Maroon), 25, "Below"));
    
                Plots[0].Min = 75;
                Plots[1].Max = 75;
                Plots[1].Min = 25;
                Plots[2].Max = 25;
          }
    protected override void OnBarUpdate()
            {
                if(CurrentBar < 20) return;
    
                K_Above75.Set(stoch.K[0]);
                K_Middle.Set(stoch.K[0]);
                K_Below25.Set(stoch.K[0]);
                K.Set(stoch.K[0]);
                D.Set(stoch.D[0]);
            }
     #region Properties
            [Browsable(false)]    
            [XmlIgnore()]        
            public DataSeries K_Above75
            {
                get { return Values[0]; }
            }
    
            [Browsable(false)]    
            [XmlIgnore()]        
            public DataSeries K_Middle
            {
                get { return Values[1]; }
            }
    
            [Browsable(false)]    
            [XmlIgnore()]        
            public DataSeries K_Below25
            {
                get { return Values[2]; }
            }
    
            [Browsable(false)]    
            [XmlIgnore()]        
            public DataSeries K
            {
                get { return Values[3]; }
            }
            [Browsable(false)]    
            [XmlIgnore()]        
            public DataSeries D
            {
                get { return Values[4]; }
            }
    When I added the indicator to a chart nothing was plotting correctly. In the Plots window the listed Plots were D, D, K, K, and K_Below25.
    I removed the indicator from the chart and added it again. This time the Plots window showed Plots D and K which was all the indicator had before.
    After scrutinizing the code for 30 mins and not finding anything wrong I decided to just rewrite the indicator. I did with copied/pasted data from the first indicator. I simply relabeled it. This indicator worked just fine.
    I then attempted to delete the first indicator. I got an error message that it couldn't delete because of the .cs. I thought this was strange as I've deleted indicators before without issue. So I went into my Documents\NinjaTrader7\bin\Custom\Indicator and deleted that file.
    So now the indicator is deleted right? Wrong! I could still add the indicator to a chart! It wasn't listed in the ControlCenter\Tools\EditNinjaScript window, but I could pull it up on a chart.
    Two other indicators I created are dependent on this indicator so I thought maybe I needed to comment out the references to the first indicator. I did that and FINALLY the first indicator was no longer available to be added to a chart. Great.
    So now I had a copy of the first indicator. Since I have 2 indicators that are dependent on the first I decided to do a Save As on the second indicator and rename it as the first. Before this point the first indicator was no longer on my machine and the references in the other indicators we commented out and recompiled. Then I saved the second indicator with the name of the first. The Saved As indicator file was back at Documents\NinjaTrader7\bin\Custom\Indicator as expected and was in the ControlCenter\Tools\EditNinjaScript window, but was not available to add to a chart! When I uncommented the references in the other indicators and recompiled suddenly the Saved As indicator was available to add to a chart. But it was added with only two plots D and K!
    That indicator, as far as I know is no longer on my machine! How is it still being added to my chart? It's Undead! Please help.

    #2
    Hello CaptainAmericaXX,

    Manually changing, or manually deleting files from the file system does not change what is compiled in NinjaTrader.
    No changes will take affect until all scripts are successfully compiled.

    If you manually delete an open source script, it will still be available in the Indicator list until the next successful compile.
    If an indicator is in memory, it will continue to be on the chart until the chart is reloaded (even after a successful compile).

    Is not advised to manually remove files as this may cause compile errors.

    If you getting an error that a script cannot be deleted, it is best to address the error and not just delete the script manually.

    Last, anything changed in Initialize() only affects the default properties and will not take affect until a new instance of the script is added and the defaults are pulled.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      ChelseaB,
      Thank you for your help. Your explanation on the first 4 issues has broadened my understanding. Can I restate to check my understanding?
      Manually changing, or manually deleting files from the file system does not change what is compiled in NinjaTrader.
      No changes will take affect until all scripts are successfully compiled.
      I had scripts that were dependent on the first script that was changed. Are you saying that if I make changes on one indicator that I will have to compile all dependent scripts before the change is seen on the first indicator?
      f you manually delete an open source script, it will still be available in the Indicator list until the next successful compile.
      If an indicator is in memory, it will continue to be on the chart until the chart is reloaded (even after a successful compile).
      Again, the script will still remain on the Indicator list until all my dependent scripts are compiled.
      Is not advised to manually remove files as this may cause compile errors.

      If you getting an error that a script cannot be deleted, it is best to address the error and not just delete the script manually.
      Understood.
      Last, anything changed in Initialize() only affects the default properties and will not take affect until a new instance of the script is added and the defaults are pulled.
      I removed the indicator and added it back to the chart, created a new indicator, deleted the old one. Heck I even deleted the entire workspace and template, shut Ninja and my computer off several times. Obviously there's something about your last statement I don't understand. Would you mind clarifying.

      Comment


        #4
        Hello CaptainAmericaXX,

        Yes, where you have mentioned:
        "I had scripts that were dependent on the first script that was changed. Are you saying that if I make changes on one indicator that I will have to compile all dependent scripts before the change is seen on the first indicator?"

        In C# everything has to compile. One error in one script prevents all other code from compiling.
        (But to clarify compiling one script compiles all of the scripts and the entire system. So you don't have to compile each one..)

        Where you have mentioned:
        "I removed the indicator and added it back to the chart, created a new indicator, deleted the old one. Heck I even deleted the entire workspace and template, shut Ninja and my computer off several times. Obviously there's something about your last statement I don't understand. Would you mind clarifying"

        Can I confirm you've had a successful compile?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Actually, as I think about it. I did a Save As but I believe never actually compiled that Saved As script. Yes I'm sure that's what I did. It all makes sense now. Thank you for your help!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by algospoke, Yesterday, 06:40 PM
          2 responses
          19 views
          0 likes
          Last Post algospoke  
          Started by ghoul, Today, 06:02 PM
          3 responses
          14 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          45 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          20 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          181 views
          0 likes
          Last Post jeronymite  
          Working...
          X