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

Boolean SuperTrend

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

    Boolean SuperTrend

    Hello, I'm trying to create a simple indicator to display 1 or 0 on the Market Analyzer according to the SuperTrend indicator. The idea is simple: return 1 if trend is up and return 0 if trend is down. However, my code is somehow not working. Can you please help me ?

    The code is:

    protected override void OnBarUpdate()
    {
    if (Close[0] > SuperTrend(14, 2.618, true).UpTrend[0])

    Plot0.Set(1);

    else if (Close[0] < SuperTrend(14, 2.618, true).DownTrend[0])

    Plot0.Set(0);

    }

    #2
    Hello rodlm,
    Welcome to the forum and I am happy to assist you.

    Please check for a valid plot before accessing the values from the indicator. Please try the below code and see if it works or not
    Code:
    if (this.SuperTrend(14,2.618, false).UpTrend.IsValidPlot(0) && this.SuperTrend(14,2.618, false).UpTrend[0] < Close[0])
    {
          Plot0.Set(1);
    }
    else if (this.SuperTrend(14,2.618, false).DownTrend.IsValidPlot(0) && this.SuperTrend(14,2.618, false).DownTrend[0] > Close[0])
    {
    	Plot0.Set(0);
    }
    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Hello Joydeep,

      I've changed the code and I always get the number 1 in my Market Analyzer. The indicator is working perfectly on charts... but its not working in the Market Analyzer...

      I'm sending you the complete code:

      namespace NinjaTrader.Indicator
      {
      /// <summary>
      /// Market Analyzer indicator. Returns 1 if trend is up and 0 if trend is down.
      /// </summary>
      [Description("Market Analyzer indicator. Returns 1 if trend is up and 0 if trend is down.")]
      public class BooleanSuperTrend : Indicator
      {
      #region Variables
      // Wizard generated variables
      private int myInput0 = 1; // Default setting for MyInput0
      // User defined variables (add any user defined variables below)
      #endregion

      /// <summary>
      /// This method is used to configure the indicator and is called once before any bar data is loaded.
      /// </summary>
      protected override void Initialize()
      {
      Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
      Overlay = false;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {

      if (this.SuperTrend(14,2.618, false).UpTrend.IsValidPlot(0) && this.SuperTrend(14,2.618, false).UpTrend[0] < Close[0])
      {
      Plot0.Set(1);
      }
      else if (this.SuperTrend(14,2.618, false).DownTrend.IsValidPlot(0) && this.SuperTrend(14,2.618, false).DownTrend[0] > Close[0])
      {
      Plot0.Set(0);
      }

      }

      Comment


        #4
        Hello,
        It might be the case that the SuperTrend indicator is returning a wrong values in realtime mode. If I use the below code to print out the realtime values with CalculateOnBarClose set to false then it is only returning 0's (zero's).

        Code:
        if (!Historical) Print(SuperTrend(14,2.618, false).UpTrend[0].ToString() + "         " + SuperTrend(14,2.618, false).DownTrend[0].ToString());
        Please debug your code using the Print function and make sure you are getting the correct values. Please refer to get an idea on how to debug a NinjaScript code efficiently
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Humm... it's gonna be hard... and actually I don't understand, because the indicator works perfectly on charts in real time and in historical data...

          The problem occurs only when trying to use it on Market Analyzer...

          Anyway, thank you for your attention.

          Comment


            #6
            rodlm,

            If you have you code available, please post and we could possibly see if we can identify the issue. I see you have code below. Did you change any of the custom plot series, or the properties section of the code?
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Hello AdamP,

              I'm sending the code attached. Thank you for the reply.
              Rodlm
              Attached Files

              Comment


                #8
                rod,

                Please try adding the following and reporting any error messages.

                try
                {

                // code I want to try

                }
                catch(Exception e)
                {

                Print(e.ToString());

                }


                This will print out if there are any errors at run time.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  If I add the code I get the error message "Statement expected."

                  Comment


                    #10
                    rodlm,

                    You most likely are missing a bracket somewhere or some other needed syntax item.

                    { or } or ;
                    Adam P.NinjaTrader Customer Service

                    Comment


                      #11
                      Could you then post the complete code in the forum?

                      Comment


                        #12
                        rod,

                        Using the indicator attached, I get market analyzer 0's and 1's and it works correctly on my charts.
                        Attached Files
                        Adam P.NinjaTrader Customer Service

                        Comment


                          #13
                          Thank you very much for the code, AdamP...

                          I think there is any problem with my SuperTrend indicator, because I'm still getting only 1's in the Market Analyzer.

                          Its really funny, because it works perfectly on Charts...

                          :-(

                          Any suggestions? Reinstall SuperTrend indicator, maybe?

                          Comment


                            #14
                            rod,

                            You may want to try using the supertrend that is included in that file.

                            Who is your data provider?
                            Adam P.NinjaTrader Customer Service

                            Comment


                              #15
                              I use eSignal and PFG Best.

                              Usually I'm connected with both services.

                              I usually connect first to PFG and second to eSignal.

                              And by the way, I reinstalled the SuperTrend indicator and now I'm using the one you provided.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by PaulMohn, Today, 05:00 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post PaulMohn  
                              Started by ZenCortexAuCost, Today, 04:24 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post ZenCortexAuCost  
                              Started by ZenCortexAuCost, Today, 04:22 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post ZenCortexAuCost  
                              Started by SantoshXX, Today, 03:09 AM
                              0 responses
                              17 views
                              0 likes
                              Last Post SantoshXX  
                              Started by DanielTynera, Today, 01:14 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post DanielTynera  
                              Working...
                              X