Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Instrument check code

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

    Instrument check code

    Hello,

    I am trying to make an INDICATOR to work only in the instrument that I set it for. However, it gives the error: "close strategy does not exist in the current context"

    I am usign this code:

    if (Instrument.MasterInstrument.Name != "MNQ")
    {
    Draw.TextFixed(this, "BR", "ALGORITHM NOT LICENSED FOR THIS INSTRUMENT", TextPosition.BottomRight);
    PlaySound(NinjaTrader.Core.Globals.InstallDir + @"\sounds\Announcement.wav");
    CloseStrategy("Not Licensed " + Time[0].ToString());
    return;
    }


    #2
    Hello Jorge.andres.o,

    Thank you for your post.

    There is not a concept of CloseStrategy() for an indicator - that will only work within a strategy. With an indicator, if you want it not to process if it's not the specific instrument, you would need to modify this to something like the following. I would suggest putting it inside OnStateChange when State == State.Historical and setting a bool to return in OnBarUpdate instead, like this:

    Code:
        public class TestDontProcessIndi : Indicator
        {
            private bool CanProcess;
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Indicator here.";
                    Name                                        = "TestDontProcessIndi";
                    Calculate                                    = Calculate.OnBarClose;
                    IsOverlay                                    = true;
                    DisplayInDataBox                            = true;
                    DrawOnPricePanel                            = true;
                    DrawHorizontalGridLines                        = true;
                    DrawVerticalGridLines                        = true;
                    PaintPriceMarkers                            = true;
                    ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive                    = true;
                    CanProcess = true;
                }
                else if (State == State.Historical)
                {
                    if (Instrument.MasterInstrument.Name != "MNQ")
                    {
                        Draw.TextFixed(this, "BR", "ALGORITHM NOT LICENSED FOR THIS INSTRUMENT", TextPosition.BottomRight);
                        PlaySound(NinjaTrader.Core.Globals.InstallDir + @"\sounds\Announcement.wav");
                        Print("Not Licensed " + DateTime.Now.ToString());
                        CanProcess = false;
    
                    }
                }
            }
    
            protected override void OnBarUpdate()
            {
                if(CanProcess != true)
                    return;
                Draw.TextFixed(this, "testText", "This should not print on anything but MNQ", TextPosition.BottomRight);
    
                // remainder of logic goes here;
    
            }
        }
    Thanks in advance; I look forward to assisting you further.
    Last edited by NinjaTrader_Kate; 06-18-2020, 08:37 AM. Reason: Thought of a better way

    Comment


      #3
      Thank you very much

      Comment


        #4
        Hello,

        I copied a code for an INDICATOR and made few changes in the logic (to make a new indicator). The indicator is working now but once I tried to compile it. It gave me the following error: The type namespace eTextPosition could not be found.

        I had to change it from eTextPosition to eTextPosition1 to avoid the conflict with the previous indicator. However, the last region that is generated by Ninjatrader does not change the namespace and I cannot compile it.
        How can I get around it?



        Comment


          #5
          Hello Jorge.andres.o,

          Thank you for your reply.

          This sounds like a typo, actually. Could you provide a screenshot of the compile errors you are receiving? We would also be interested in seeing a reduced version of your code - any code unrelated to the issue should be removed.

          Thanks in advance; I look forward to assisting you further.

          Comment


            #6
            BankingLockProfit.txt

            Hello,

            As stated in the question, I am not able to export the script. The screenshot is attached. I apologize in advance. The whole Error message says: "Error compiling export assembly: c:\Users\jorge\OneDrive\Documents\NinjaTrader 8\bin\Custom\Indicators\BankingLockProfit.cs(410,1 80) : error CS0246: The type or namespace name 'eTextPosition' could not be found (are you missing a using directive or an assembly reference?)"
            Attached Files
            Last edited by Jorge.andres.o; 06-19-2020, 07:03 AM.

            Comment


              #7
              Hello Jorge.andres.o,

              Thank you for your reply.

              In the version you've sent me, I noted that while you had changed the enum to eTextPosition3, that there were still a number of references to eTextPosition, likely from the original script. Once I corrected these, I was able to both compile and export the script. I've attached the corrected export to this post.

              Please let us know if we may be of further assistance to you.
              Attached Files

              Comment


                #8
                Kate,

                Any chance to see the code inside? I normally try to get it better working on the previous version.

                Thank you very much.
                Last edited by Jorge.andres.o; 06-19-2020, 04:04 PM.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                648 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                369 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                108 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                572 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                574 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X