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 Mindset, 04-21-2026, 06:46 AM
0 responses
57 views
0 likes
Last Post Mindset
by Mindset
 
Started by M4ndoo, 04-20-2026, 05:21 PM
0 responses
78 views
0 likes
Last Post M4ndoo
by M4ndoo
 
Started by M4ndoo, 04-19-2026, 05:54 PM
0 responses
39 views
0 likes
Last Post M4ndoo
by M4ndoo
 
Started by cmoran13, 04-16-2026, 01:02 PM
0 responses
101 views
0 likes
Last Post cmoran13  
Started by PaulMohn, 04-10-2026, 11:11 AM
0 responses
61 views
0 likes
Last Post PaulMohn  
Working...
X