Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding/plotting an indicator with harcoded period into/from strategy

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

    Adding/plotting an indicator with harcoded period into/from strategy

    I need an indicator in strategy with hard coded period..

    The below strategy code
    -----------------------
    protected override void Initialize()
    {
    Add(PeriodType.Day, 1);
    MyIndicator(BarsArray[1], Period).Plots[0].Pen.Color = Color.Blue;
    Add(MyIndicator(BarsArray[1], Period));
    }
    ---------------------
    Throws exception: Failed to call method 'Initialize' for strategy 'MyStrategy': 'BarsArray' property can not be accessed from within 'Initialize' method

    Questions:
    - Is there a way to add an indicator into strategy with specific Period?
    - How to plot such an indicator (with hardcoded period) from a strategy?

    Thanks for help,
    Alex.

    #2
    Alex, please move the parts accessing BarsArray to the OnBarUpdate().

    To add a hardcoded indicator just do something like this -

    Add(CCI(20));

    For customizing plots, color and panels, please see this -

    Comment


      #3
      Hi Bertrand,

      How to plot an indicator for additional bars object that I add in initialize() method.

      Code:
      protected override void Initialize()
      {
         Add(PeriodType.Day, 1);
      }
      Now I can use the new bars objects with my custom indicator
      Code:
      protected override void OnBarUpdate()
      {
         MyIndicator(BarsArray[1], 10)
      }
      But how to plot it?? Following does not work:

      Code:
      MyIndicator(BarsArray[1], Period).Plots[0].Pen.Color = Color.Blue;

      Comment


        #4
        ma5ter, on NinjaTrader 6.5 multiseries indicators are unfortunately not supported - this is only possible for strategies - the same concept will be available for indicators in NinjaTrader 7 -

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by sjsj2732, Yesterday, 04:31 AM
        0 responses
        31 views
        0 likes
        Last Post sjsj2732  
        Started by NullPointStrategies, 03-13-2026, 05:17 AM
        0 responses
        286 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        283 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        133 views
        1 like
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        91 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Working...
        X