Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Object lifecycle issue (I think)

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

    Object lifecycle issue (I think)

    i have created an indicator (MyPositionActionIndicator) that iterates through all the indicators on a chart and only executes operations on indicators that implement an interface that i have defined, IPositionAction. i am getting weird behavior that i think is related to the indicator lifecycle but i am not sure. i have written indicators that generate trading signals and each implements the IPositionAction interface which defines a GetPosition() function that returns an enum of PositionDirection { Long, Short, Flat}. the MyPositionIndicator "watches" for when all trading signals are equal i.e. each indicator that implements the interface returns an identical enum value for short or long and acts accordingly. the indicators that implement the interface have logic in the OnBarUpdate method which assigns class level variables that get referenced in the GetPosition() function (it is at this point where the breakdown occurs, i think). below is my code for the MyPositionActionIndicator. Any ideas, thanks?

    public class MyPositionActionIndicator : Indicator {
    protected override void OnStateChange() {
    if (State == State.SetDefaults) {
    Description = @"Tracks all indicators that implement the IPositionAction interface to execute common operations";
    Name = "MyPositionActionIndicator";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    }
    else if (State == State.Configure) {
    ClearOutputWindow();
    }
    }
    protected override void OnBarUpdate() {
    var positions = new LimitedList<PositionDirection>(DefaultLimitedListS ize);
    foreach (var i in ChartControl.Indicators) {
    if (i != null && i is IPositionAction ipa)
    positions.Add(ipa.GetPosition()); // breakdown occurs here.
    }
    if (positions.Count > 0 && positions.AreItemsEqual()) {
    var pos = positions.Last();
    if (pos == PositionDirection.Long)
    Draw.TriangleUp(this, "EnterLong" + CurrentBar, true, 0, 1, Brushes.LimeGreen, false);
    else if (pos == PositionDirection.Short)
    Draw.TriangleDown(this, "EnterShort" + CurrentBar, true, 0, 1, Brushes.Red, false);
    else
    Draw.Dot(this, "Range" + CurrentBar, true, 0, 1, Brushes.Black, false);

    }
    }
    }​

Latest Posts

Collapse

Topics Statistics Last Post
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
0 responses
558 views
0 likes
Last Post Geovanny Suaza  
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
0 responses
324 views
1 like
Last Post Geovanny Suaza  
Started by Mindset, 02-09-2026, 11:44 AM
0 responses
101 views
0 likes
Last Post Mindset
by Mindset
 
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
0 responses
545 views
1 like
Last Post Geovanny Suaza  
Started by RFrosty, 01-28-2026, 06:49 PM
0 responses
547 views
1 like
Last Post RFrosty
by RFrosty
 
Working...
X