Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

TSSuperTrend Code For MA Needed!

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

    TSSuperTrend Code For MA Needed!

    Hi,

    I am in need of a line of code to create a filter condition in market analyzer.

    It is for the TSSuperTrend indicator, I need the code to tell me when the TSSupertrend plot has plotted the same price or value for at least 5 bars.

    the code perhaps would look something like this:

    If TSSuperTrend.Set = value or price for at least 5 bars

    or something? I just need to set the condition for this indicator when it plots the same price or value for at least 5 bars, not sure what the line of code would be,

    any help is greatly appreciated!

    #2
    Ok,

    here is what I got so far... will this work? it won't compile though because it has a "staement expected" error that I can't figure out:

    protected override void OnBarUpdate()
    {

    if(TSSuperTrend.UpTrend) (Close[4]=Close[3]=Close[1]=Close[0]);
    or;
    if(TSSuperTrend.DownTrend) (Close[4]=Close[3]=Close[2]=Close[1]=Close[0]);

    {
    Plot0.Set(1);
    } (here is the statement expected error)
     
    else
    {
    Plot0.Set(0);
    }
    }

    Comment


      #3
      Hello,


      This:

      if(TSSuperTrend.UpTrend) (Close[4]=Close[3]=Close[1]=Close[0]);
      or;
      if(TSSuperTrend.DownTrend) (Close[4]=Close[3]=Close[2]=Close[1]=Close[0]);

      Needs to have this structure:
      if( (...condition A ....) || (...condition B...))
      {
      //do something
      }

      "||" means or. "&&" means and.
      DenNinjaTrader Customer Service

      Comment


        #4
        Thanks Ben,

        Thanks for the help, still can't get it to compile with this:

        if((TSSuperTrend.UpTrend (Close[4]=Close[3]=Close[2]=Close[1]=Close[0])
        ||
        (TSSuperTrend.DownTrend (Close[4]=Close[3]=Close[2]=Close[1]=Close[0]))

        Or

        if((TSSuperTrend.UpTrend)(Close[4]=Close[3]=Close[2]=Close[1]=Close[0]) || (TSSuperTrend.DownTrend)(Close[4]=Close[3]=Close[2]=Close[1]=Close[0]))

        Thanks for any help, trying to learn this stuff and really need it!

        Comment


          #5
          Okay, this is the closet but it still has 2 "statements expected"

          do you see where?

          if((TSSuperTrend.UpTrend) Close[4]=Close[3]=Close[2]=Close[1]=Close[0])
          || (TSSuperTrend.DownTrend) Close[4]=Close[3]=Close[2]=Close[1]=Close[0]));

          {
          Plot0.Set(1);
          }

            else
          {
          Plot0.Set(0);
          }

          Comment


            #6
            Do I have to declare the entire indicator or is just declaring the plots of the indicator okay?

            Comment


              #7
              The way you call the SuperTrend indicator without any parameters looks strange to me, you can check for the expected overload to be used with Intellisense in the NinjaScript editor - also did you add the Plot in the Initialize section of the indicator?

              Code:
               
              Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));

              Comment


                #8
                Thanks Ben,

                I do have the Plot code in the script and it is named "Plot0"

                I am new at this and trying to figure it out, what would be the parameters for the indicator? would it be the way the original author wrote it or do I need to create parameters for it?

                Thanks again,

                Comment


                  #9
                  Parameters are available in mostly any indicator method you call, for example consider SMA(Close, 20)[0] for the latest double value of the SMA on closing price over 20 bars, the Close [series to calculate on] and the 20 [length over which to calculate] would be called paramters in the SMA method, so you could customize the call to your needs - the same should be available for your SuperTrend method, as you type in the code the NinjaScript editor would offer you it's help in finding the correct overload via the Intellisense feature build in -

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  576 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  334 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  101 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  553 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  551 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X