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

Exposing a non DataSeries property in an indicator

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

    Exposing a non DataSeries property in an indicator

    Is there a way in an indicator to have a DataSeries which is made public but is not plotted?

    Example, HeikinAshi, I would like to assign a "bias" based on the body color, +1 for Close>Open, -1 for the opposite, which could be accessed from a strategy.

    If this is done using Add(new plot) it plots a line at +-1 which messes up the scale. Of course the AutoScale can be set to false. I was wondering if there was a more elegant approach.



    #2
    imported post

    Good question Tom, absolutely there is a more elegant approach. You will want to add a property to your strategy.

    Following is a partial sample code:
    // Under variables
    private bool bullish = false;

    //Within OnBarUpdate()
    bullish = Close[0] > Open[0] ? true : false;

    // Under properties, create the public property that can be accessed from the strategy
    public bool Bullish
    {
    get
    {
    Update();
    return bullish;
    }
    }
    Calling the Update() method is a key step. Indicators embedded in a strategy are optimized andonly call their OnBarUpdate() method when the indicator is called from the strategy, not every bar or tick. The indicator knows that when a DataSeries value is being accessed, it needs to call the OnBarUpdate() method. Since all you need is to know when a value is true or false, there is not need to store this data in a DataSeries object so we just create a basic property. To ensure this property has the most current value, we call the Update() method withing the property getter to force the indicator to call the OnBarUpdateI() method.


    Ray
    RayNinjaTrader Customer Service

    Comment


      #3
      imported post

      If I wanted a DataSeries with no plot then:

      // Under variables
      private DataSeries noPlotData;

      //Within Initialize()
      noPlotData = new DataSeries(this);

      //Within OnBarUpdate()
      NoPlotData = { expression}

      // Under properties, create the public property that can be accessed from the strategy
      public DataSeries NoPlotData
      {
      get
      {
      // Update(); // Not used for series ???
      return noPlotData;
      }
      }

      Comment


        #4
        imported post

        I assume this is need for backtesting?

        Comment


          #5
          imported post

          Yes, same principlesapply.
          RayNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by maybeimnotrader, Yesterday, 05:46 PM
          2 responses
          20 views
          0 likes
          Last Post maybeimnotrader  
          Started by adeelshahzad, Today, 03:54 AM
          5 responses
          32 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by stafe, 04-15-2024, 08:34 PM
          7 responses
          32 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by merzo, 06-25-2023, 02:19 AM
          10 responses
          823 views
          1 like
          Last Post NinjaTrader_ChristopherJ  
          Started by frankthearm, Today, 09:08 AM
          5 responses
          22 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Working...
          X