Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Use cursorBarIndex in OnBarUpdate()   

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

    Use cursorBarIndex in OnBarUpdate()   

    Hello,

    Trying to use a cursorBarIndex value in OnBarUpdate(), cant fixe this my Period wont be replace by cursorBarIndex.
    Any pointers?

    Code:
    public class GAPoffset : Indicator
    {
        private int cursorBarIndex = -1;
    
        protected override void OnBarUpdate()
        {
            if (Bars == null || CurrentBar < 1)
            {
                return;
            }
    
            // ... (other variable declarations remain the same)
    
            int startIndex = Math.Max(1, cursorBarIndex == -1 ? CurrentBar - 1 : cursorBarIndex);
            int startAgo = Math.Max(1, cursorBarIndex == -1 ? CurrentBar : cursorBarIndex);
    
            // ... (rest of the method remains largely the same)
        }
    
        public void UpdateCursorPosition(ChartControl chartControl, int cursorPointX)
        {
            cursorBarIndex = ChartBars.GetBarIdxByX(chartControl, cursorPointX);
            Calculate = Calculate.OnBarClose;
        }
    }
    ​

    TY

    #2
    Hello frankduc,

    What problem are you seeing when using that code?

    I also see you are trying to set Calculate from a cursor position event, Calculate can only be set in State.SetDefaults or Configure. That cannot be used in other events to on the fly change the mode.


    This property should ONLY be set from the OnStateChange() method during State.SetDefaults or State.Configure.

    Comment


      #3
      Period has been replace by cursorBarIndex. It plot a moving average code from OnBarUpdate(). I would like to use ChartBars.GetBarIdxByX(chartControl, cursorPointX) or any method that can return the specific barIndex when i click on the chart and send it back to OnBarUpdate() to replace the Period.

      Any suggestions?

      Comment


        #4
        Hello frankduc,

        I am still not clear on what the problem or question is.

        GetBarIdxByX can be used to get the bar by an X position, are you having some kind of problem with that method?

        Comment


          #5
          Hello,

          In OnBarUpdate() i created a moving average. To set the period i use the indicator parameters and enter the barIndex to draw the MA.

          GetBarIdxByX is used to get the bar by an X position, once a click on the chart it return the barIndex of that specific postion.

          I want X position barIndex to become my period in my MA in OnBarUpdate() to avoid having to open the indicators parameters to set the period.

          That way everytime i will touch the screen anywhere on the chart it will draw the MA according to its position.

          TY

          Comment


            #6
            Hello frankduc,

            For that type of used you would have to know the BarsAgo from now if you are trying to use it as a period with any of the stock indicators. That would be CurrentBar minus the index you found.

            Comment

            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