Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

It is possible to know how the algorithm of an indicator works

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

    It is possible to know how the algorithm of an indicator works


    It is possible to know how the algorithm of an indicator works or how it calculates a breakout bands. The code is not long ... about 10 lines

    #2
    Of course.

    Usually, one has to understand the programming language the algorithm is
    expressed in. However, for quite a few experienced programmers, having
    access to a good reference manual for said programming language can be
    sufficient.

    Are you talking about NinjaScript code?
    If someone understands enough C# and enough NinjaScript, 10 lines of code
    should be relatively easy to digest.

    But ...
    The comprehension level of why the code is doing what it's doing, well,
    that's another story. It may take some additional learning -- for ex, if those
    10 lines of code represent the work of some author from some book, you
    might have to study portions of their book to truly understand what those
    10 lines of code are really doing. Or not. It just depends.
    Last edited by bltdavid; 07-17-2021, 06:10 PM.

    Comment


      #3
      //This namespace holds Indicators in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Indicators
      {
      public class ElliotOscillator : Indicator
      {
      private Series<double> fastEMA;
      private Series<double> slowEMA;

      private double elliot = 0;
      private double elliot3 = 0;

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"The Oscillator is a trend of prices.";
      Name = "Oscillator";
      Calculate = Calculate.OnBarClose;
      IsOverlay = false;
      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;
      Fast = 5;
      Slow = 35;
      AddPlot(new Stroke(Brushes.Black, 2), PlotStyle.Bar, "Neutral");
      AddPlot(new Stroke(Brushes.Blue, 2), PlotStyle.Bar, "UpTrend");
      AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.Bar, "DownTrend");
      AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.Line, "ULine");
      AddPlot(new Stroke(Brushes.Blue, 2), PlotStyle.Line, "DLine");
      }
      else if (State == State.Configure)
      {
      }
      else if (State == State.DataLoaded)
      {
      fastEMA = new Series<double>(this);
      slowEMA = new Series<double>(this);

      }
      }

      protected override void OnBarUpdate()
      {
      if (CurrentBar < 3)
      {
      fastEMA[0] = (Input[0]);
      slowEMA[0] = (Input[0]);
      Value[0] = (0);
      Elliott3[0] = (0);
      Elliott4[0] = (0);
      return;
      }
      else
      {



      fastEMA[0] = (SMA(Fast)[0]);
      slowEMA[0] = (SMA(Slow)[0]);
      elliot = ((fastEMA[0] - slowEMA[0]));
      Value[0] = elliot;


      ////////////////// //////////////////

      if (Value[0] >=0)
      {


      if (Value[0] > Value[1])
      UpTrend[0] = (elliot);
      else
      DownTrend[0] = (elliot);

      }
      }
      Last edited by ElonkTrader; 07-18-2021, 05:28 PM.

      Comment


        #4
        If it is ninja script, the last part is I put the almost complete code so that you can see more less ..

        Comment


          #5
          Try this:

          Code:
          IF Value[0] is greater than OR equal zero THEN
             setup Elliot3 with new value for this candle
             setup Elliot4 with same value as last candle
          ELSE
             setup Elliot4 with same value as last candle
             setup Elliot3 with new value for this candle
          ENDIF

          Comment


            #6
            Elliott3 [0] would be the current value while Elliott3 [1] would be the same calculation but before, right?

            when he talks about setup Elliot4 with the same value as last candle ... it would be while drawing the previous calculation, the other one is drawing from the current value = to the previous value
            but taking the value of else ... that's how I understood it .. if I'm wrong, correct me

            Comment


              #7
              Originally posted by ElonkTrader View Post
              Elliott3 [0] would be the current value
              Correct.

              The '[0]' index references the most recently closed bar.
              The '[1]' references the previous most recently closed bar.

              The actual bars being referencing are always relative to the most recently closed bar.
              So, they change, aka 'get adjusted forward', each time a new bar closes.

              When using a Series ...
              The notation '[n]' is read as 'n bars ago' and 'n' is called the 'bars ago index'.

              Originally posted by ElonkTrader View Post
              while Elliott3 [1] would be the same calculation but before, right?
              Yes, but there is something a bit subtle there.

              It's possible Value[0] could be >= 0 or < 0 for many bars in a row.

              If that's the case, note how the code keeps carrying the old value forward.
              For ex, that's exactly what 'Elliot3[0] = Elliot3[1]' is doing. Do you see that?

              When the next value of Elliot3 or Elliot4 is actually calculated, note how the
              formula uses the previous value at '[1]' ... which is not a problem, since that
              'previous value at [1]' has been repeatedly carried forward for each new bar,
              until it finally gets used in the formula for the calculation of a new value.

              Originally posted by ElonkTrader View Post
              when he talks about setup Elliot4 with the same value as last candle ... it would be while drawing the previous calculation, the other one is drawing from the current value = to the previous value
              but taking the value of else ... that's how I understood it .. if I'm wrong, correct me
              I think you got it!

              Btw, I see you're writing it like 'Elliot3 [0]' with a space -- get rid of the space.

              The Series name and the index are always bunched together, like this, 'Elliot3[0]'.
              With no spaces in between. Ever.


              Comment


                #8
                Originally posted by bltdavid View Post

                Correct.

                The '[0]' index references the most recently closed bar.
                The '[1]' references the previous most recently closed bar.

                The actual bars being referencing are always relative to the most recently closed bar.
                So, they change, aka 'get adjusted forward', each time a new bar closes.

                When using a Series ...
                The notation '[n]' is read as 'n bars ago' and 'n' is called the 'bars ago index'.



                Yes, but there is something a bit subtle there.

                It's possible Value[0] could be >= 0 or < 0 for many bars in a row.

                If that's the case, note how the code keeps carrying the old value forward.
                For ex, that's exactly what 'Elliot3[0] = Elliot3[1]' is doing. Do you see that?

                When the next value of Elliot3 or Elliot4 is actually calculated, note how the
                formula uses the previous value at '[1]' ... which is not a problem, since that
                'previous value at [1]' has been repeatedly carried forward for each new bar,
                until it finally gets used in the formula for the calculation of a new value.



                I think you got it!

                Btw, I see you're writing it like 'Elliot3 [0]' with a space -- get rid of the space.

                The Series name and the index are always bunched together, like this, 'Elliot3[0]'.
                With no spaces in between. Ever.

                perfect, I got it, I'm going to try how I'm doing .. thank you very much

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                574 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                332 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