Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator.IsCreatedByStrategy

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

    Indicator.IsCreatedByStrategy

    I would like to know if an indicator is being called from within a strategy or not but it doesn't seem to be working.


    From within the indicator I am checking like so below and it prints when I add the indicator to the chart independently but doesn't recognize when added via a Strategy.

    from within a Strategy within State. Dataloaded

    Code:
    if(this.IsCreatedByStrategy)
    Print("Created by strategy");
    else
    Print("Independently added");
    I also tried from within the Strategy within State. Dataloaded and it also doesn't recognize that it was loaded by a strategy

    AddChartIndicator(indi);
    if(indi.IsCreatedByStrategy)
    Print("indi Created by strategy");
    else
    Print("indi NOT Created by by strategy");

    #2
    You might try:

    Print (Parent.GetType()) to find out the caller. then you can compare : `if (Parent == Strategy...)`

    I have been searching a lot for this in the past, and this was my solution for similar cases.
    Last edited by ttodua; 10-15-2020, 02:41 PM.

    Comment


      #3
      Hello cutzpr, thanks for your post.

      IsCreatedByStrategy is not documented, so there is no guarantee it will work or was meant to be used in NinjaScript. How is the indicator being used in the strategy? You can make the indicator call Update() to force its OnBarUpdate function to be called e.g. from the strategies OnBarUpdate:

      Code:
      private TestIndicator TI;
      ...
      else if (State == State.DataLoaded)
      {
      TI = TestIndicator();
      }
      ...
      protected override void OnBarUpdate()
      {
      TI.Update();
      }
      Please let me know if this does not resolve your inquiry.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      79 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      54 views
      0 likes
      Last Post CarlTrading  
      Working...
      X