Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Converting an EasyLanguage Indicator to NinjaScript

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

    Converting an EasyLanguage Indicator to NinjaScript

    Hi all I have an indicator in EasyLanguage that I am trying to convert to NinjaScript. In it, one of the things that I want to do is create a price series based on the (High + Low) / 2

    In EasyLanguage it looks like this -
    Inputs: Price((H+L)/2);

    If I want to look at Price for the previous bar then (of course) it would be Price[1]

    Please tell me that there is an easy way to do this in NinjaScript?

    #2
    previous bar : close[1], or open[1] or High[1] or Low[1] which could be c1, o1, h1, l1 ..... so on

    Comment


      #3
      Yes and thank you Emma1,

      I understand that you get the previous bar that way but how do I do what I am trying to do, i.e. return a Series<double> by adding two Series<double> and dividing by two. In EasyLanguage Price((High + Low) / 2) yields a Series<double> and High and Low are Series variables just as in NinjaTrader.

      I tried the following...
      private IEnumerable<double> Price(int len)
      {
      int i = 0;
      while (i < len)
      {
      i++;
      yield return (High[i] + Low[i]) / 2;
      }
      }

      But this seems a bit convoluted and I would need to cast it to get it to work correctly. It also seems a bit error prone.

      Comment


        #4
        Hello NeverDownMoney,

        Emma1 is correct in to use the Close, High, Open, etc series.

        Below is a link to the help guide.


        If you want to create your own series, there is already a type created for this and it is Series<Type> which must be initiated in OnStateChange when State is State.DataLoaded. (The IEnumerable for general C# collections is not the the correct type)
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you NinjaTrader_ChelseaB,

          Emma1 misunderstood my question which is easy to do if you have no familiarity with EasyLanguage, I understand. I was not wanting to reference the Series<T>[n] but the Series<T>. I wanted to add the two Series<T> together (think operator overloading - if you are familiar with this concept).

          // so then - here would be the code if indeed Series<T> supported addition which I know it does not and division which it does not
          Series<double> price = (High + Low) /2;

          Since then I discovered that it is possible for me to do this by (as you say above) by creating my own Series<T> thanks. Don't you mean instantiated not initiated?

          Basically what I want to do is a similar thing as Typical does...
          // Summary:
          // A collection of historical bar typical prices. Typical price = (High + Low +
          // Close) / 3.
          [Browsable(false)]
          [XmlIgnore]
          public ISeries<double> Typical { get; }

          Instead my value if it were coded would be...
          // Summary:
          // A collection of historical bar prices. Price price = (High + Low) / 2.
          [Browsable(false)]
          [XmlIgnore]
          public ISeries<double> Price { get; }

          This is what I am trying to do.

          Does that make sense?

          Comment


            #6
            Sorry if I sound like a pompous a$$. I think I have this figured out with your help, thanks. I need to remember that this is an event driven system and that price[0] will get updated at every OnBarUpdate() call.

            Here is the code for the price -

            namespace NinjaTrader.NinjaScript.Indicators
            {
            public class CustomIndicator : Indicator
            {
            private Series<double> price;

            protected override void OnStateChange()
            {
            if (State == State.SetDefaults)
            {
            ...
            }
            else if (State == State.DataLoaded)
            {
            price = new Series<double>(this, MaximumBarsLookBack.Infinite); // price variable instantiated here
            }
            else if (State == State.Configure)
            {
            }
            }

            protected override void OnBarUpdate()
            {
            price[0] = (High[0] + Low[0]) / 2; // initialized here
            ...
            // Ensures we have enough bars loaded for our indicator
            if (CurrentBar < Len)
            return;

            double maxHigh = HighestBar(price, Len); // used here
            }
            }
            }

            Comment


              #7
              Hello NeverDownMoney,

              I'm glad you were able to get the custom series declared and values set.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              557 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              324 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
              545 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              547 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X