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 NullPointStrategies, Today, 05:17 AM
      0 responses
      52 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      43 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      48 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X