Announcement

Collapse
No announcement yet.

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 op1031, Today, 05:16 PM
          0 responses
          1 view
          0 likes
          Last Post op1031
          by op1031
           
          Started by fscabrera03, Today, 01:18 PM
          1 response
          11 views
          0 likes
          Last Post fscabrera03  
          Started by BottomShark77, Today, 12:20 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_ShawnB  
          Started by bowling, Today, 06:16 AM
          3 responses
          29 views
          0 likes
          Last Post NinjaTrader_ShawnB  
          Started by systemtrader4, Today, 01:54 AM
          2 responses
          88 views
          0 likes
          Last Post systemtrader4  
          Working...
          X