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

Is it possible to stop Indicators with code?

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

    Is it possible to stop Indicators with code?

    Hi,

    Is it possible to stop working Indicators with code?

    Ex:- When time > User Defined Input
    {Stop Indicator}


    ThankYou,

    #2
    Hello paruchuriphani,

    Thanks for your note.

    I am happy to assist and have a few questions.

    How are you referencing the indicators from this strategy? (Do you have a plot that you set to the value of the indicator?)

    What would you like to prevent by stopping the indicator?

    If you are using plots you can set the condition to return at a certain time. This will prevent any other code from executing.

    For example:
    if (ToTime(Time[0]) > ToTime(UserInput))
    return;


    I look forward to your reply.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Thanks for your reply,

      I don't want to stop my complete Indicator. i just want to stop my OnBarUpdate() code.

      Because in low volatile condition my indicator giving wrong calls that's why in that time i want to stop my OnBarUpdate() code. everyday i know that my market low valatile condition time approximately.


      Thankyou,
      Last edited by paruchuriphani; 03-05-2013, 02:15 PM.

      Comment


        #4
        Hello paruchuriphani,

        Placing a condition with a return as the action at the beginning of OnBarUpdate will have the desired affect.
        You will need to supply the hour and minute and second of the stop time.

        For example:
        Code:
        int stopHour = 14;
        int stopMinute = 13;
        
        if (ToTime(Time[0]) > ToTime(stopHour, stopMinute, 0))
        return;
        Any code within OnBarUpdate after these lines will not execute.

        Let me know if I can be of further assistance.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi,

          ThankYou so much,

          I put that code in beginning of OnBarUpdate() is this correct?.

          protected override void OnBarUpdate()
          {
          int stopHour = 14;
          int stopMinute = 13;

          if (ToTime(Time[0]) > ToTime(stopHour, stopMinute, 0))
          return;


          bbMacd.Set(MACD(Input, fast, slow, smooth)[0]);

          double Avg = EMA(bbMacd,length)[0];
          double SDev = StdDev(bbMacd,length)[0];
          double upperBand=Avg+(stDv*SDev);
          double lowerBand=Avg-(stDv*SDev);

          BB_UpperBand.Set(upperBand);
          BB_LowerBand.Set(lowerBand);
          dotSeries.Set(bbMacd[0]);
          currentBar=CurrentBar;


          if(CrossAbove(dotSeries, BB_UpperBand,1)&&up)
          {
          {
          DrawDiamond("MyDot"+ CurrentBar, true, 0, dotSeries[0] , Color.Blue);
          }
          up=false;
          down=true;
          }

          if(CrossBelow(dotSeries, BB_LowerBand,1)&&down)
          {
          {
          DrawDiamond("MyDot"+ CurrentBar, true, 0,dotSeries[0] , Color.White);
          }
          up=true;
          down=false;
          }
          }
          Last edited by paruchuriphani; 03-05-2013, 02:32 PM.

          Comment


            #6
            Hi paruchuriphani,

            Yes, the placement of the code in your example is correct.

            Just as a tip, the hour and minute are hard coded but could easily be made to be public user variables.


            Let me know if I can be of any other assistance for you.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi Chelsea,

              Thank you so much for your quick reply

              this question is just for a knowledge

              how to add days in that code.after some dates i just want to stop my OnBarUpdate() code.
              is it possible?

              Thankyou,

              Comment


                #8
                Hi paruchuriphani,

                You can use the DateTime.Parse method to parse a string to a DateTime object.

                For example to prevent the code from executing tomorrow at 4:30 PM:
                Code:
                DateTime stopDate = [B]DateTime.Parse("2013-03-06 16:30:00")[/B].AddDays(1);
                if (ToTime(Time[0]) > stopDate)
                return;

                Let me know if I can still be of assistance.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Chelsea,

                  Thank you so much for your reply,

                  that code has some error.this is the error message (ERROR ON GENARETION INDICATOR) when i try to compile that code

                  Thank you,
                  Attached Files

                  Comment


                    #10
                    Hi paruchuriphani,

                    I apologize for that.. I left out ToTime() on the variable.

                    Proper code looks like:
                    Code:
                    DateTime stopDate = DateTime.Parse("2013-03-06 16:30:00").AddDays(1);
                    if (ToTime(Time[0]) > ToTime(stopDate))
                    	return;
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Chelsea,

                      Thank you so much for your quick reply,

                      your apology is accepted.

                      please tell me about AddDays(1);

                      Comment


                        #12
                        Hi paruchuriphani,

                        AddDays() is a method of the DateTime class. This adds 24 hours to a datetime object.

                        I added this to my example to show how to add a day or remove a day from a datetime object. However, I said this would stop today (3/6 at 4:30) but this is incorrect. With the AddDays(1) this would be 3/7 at 4:30.

                        It is also possible to use AddDays(-1) to remove a day from a datetime object.

                        Below is a link to the Microsoft C# Reference on AddDays.
                        http://msdn.microsoft.com/en-us/libr...e.adddays.aspx


                        Please let me know if I can still be of assistance.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Chelsea,

                          Code is Compileing. but date is not working look at this code i gave (2013-03-07 12:30:00) it means to prevent the code from executing tomorrow at 12:30 PM but my indicator onBarUpdate() code is allready prevented.our code is not recognising date..

                          protected override void OnBarUpdate()

                          {
                          DateTime stopDate = DateTime.Parse("2013-03-07 12:30:00").AddDays(0);
                          if (ToTime(Time[0]) > ToTime(stopDate))
                          return;


                          bbMacd.Set(MACD(Input, fast, slow, smooth)[0]);

                          double Avg = EMA(bbMacd,length)[0];
                          double SDev = StdDev(bbMacd,length)[0];
                          double upperBand=Avg+(stDv*SDev);
                          double lowerBand=Avg-(stDv*SDev);

                          BB_UpperBand.Set(upperBand);
                          BB_LowerBand.Set(lowerBand);
                          dotSeries.Set(bbMacd[0]);
                          currentBar=CurrentBar;
                          Attached Files

                          Comment


                            #14
                            Hi paruchuriphani,

                            The ToTime is actually removing the date portion of both of those DateTime objects.
                            Simply removing the ToTime compares the full dates of these objects.

                            Code:
                            DateTime stopDate = DateTime.Parse("2013-03-07 12:30:00");
                            if (Time[0]) > stopDate)
                            return;
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi Chelsea,

                              Thakyou so much for your reply

                              our code is working great.

                              i have a small doubt. is it possible to remove all my historical Buy&sell calls when code prevent OnBarUpdate() code.

                              thankyou,

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by rdtdale, Today, 01:02 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post rdtdale
                              by rdtdale
                               
                              Started by alifarahani, Today, 09:40 AM
                              3 responses
                              15 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by RookieTrader, Today, 09:37 AM
                              4 responses
                              18 views
                              0 likes
                              Last Post RookieTrader  
                              Started by PaulMohn, Today, 12:36 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post PaulMohn  
                              Started by love2code2trade, 04-17-2024, 01:45 PM
                              4 responses
                              40 views
                              0 likes
                              Last Post love2code2trade  
                              Working...
                              X