CT
    
        
            Calculate indicator value on close of bar (and not per tick)
            
                 28 Nov 2016, 11:52
            
                    
Hi guys
I am working on an indicator that draws points to indicate highs and lows.
When I add the indicator to a chart, all the historic points are drawn perfectly.
The newly drawn points, however, are a mess, as the indicator does not wait for the new bar to close before adding it.
Does anybody know hoe to get around this.
Regards
Replies
                     tazotodua
                     08 Aug 2019, 13:43
                                    
I use shorter approach:
.....
        [Parameter(DefaultValue = true)]
        public bool CalculateOnBarClose { get; set; }
        private int lastIndex = 0;
 
        public override void Calculate(int index)
        {
            if (CalculateOnBarClose) if (index == lastIndex) return;  lastIndex = index;
            
            // Put your logic here
        }
.....
@tazotodua

whis.gg
28 Nov 2016, 12:18
Hi, you need to write a method that's called on each new bar. See sample below.
using cAlgo.API; namespace cAlgo { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewIndicator : Indicator { private int lastIndex = 0; public override void Calculate(int index) { if (index > lastIndex) { OnBarClosed(lastIndex); lastIndex = index; } } private void OnBarClosed(int index) { // Put your logic here } } }@whis.gg