having problem with indi using Chart.SetYRange after update

Created at 07 Feb 2020, 11:38
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
HY

Hyperion

Joined 12.09.2013

having problem with indi using Chart.SetYRange after update
07 Feb 2020, 11:38


I have on my charts some wide channels which bands are usually way above and below price bars visible on the chart (for the sake of the example, let's say Keltner Channel with periods 100 and band distance 20), and because cTrader automatically fits them inside the visible chart area (really wish it wasn't automatic), the price bars become unnecessarily compressed vertically (flattened). So some time ago I've written simple indi that stretches the chart vertically so that the current price bars fit the visible chart area. The indi uses Chart.SetYRange and after the last update it kinda stopped working properly. Yesterday I noticed that it works fine on a newly opened chart (but not on the "old" charts, which were already opened on the workspace), so I reopened all the charts I use, loaded my templates and it worked normally. I thought that it might be some one-time freeze because of the update, however, today when I opened cTrader, the problem returned - charts y dimension seems to be frozen to the default platform compressed view - i.e. fitting all the indicator lines inside visible space... and no action (like refreshing etc.) changes it. What's interesting even cbot with only one line of code:

protected override void OnStart()
        {
            Chart.SetYRange(135.0, 136.0);
        }

doesn't change the y range of such "frozen" chart, whereas it works on the newly opened one. Unfortunately the issue is difficult to replicate - when I close cTrader and reopen it a few seconds later, the indi is working on the chart I opened today, but not working on the charts I (re)opened yesterday.

Below is the indi code, it has some additional tweaks, but I don't think they got anything to do with the issue. And I checked - no other indicators used in the templates use the SetYRange function or got anything to do with resizing the chart.

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class OT_chart_zoom_dynamic_height : Indicator
    {

        private double min;
        private double max;
        private int bars_back;
        private double HL_min;
        private double HL_max;
        private int desired_chart_height;

        

        protected override void Initialize()
        {
            Timer.Start(1);
            
        }

        public override void Calculate(int index)
        {
            bars_back = Chart.MaxVisibleBars;
            


            HL_min = Bars.LowPrices.Minimum(bars_back);
            
            HL_max = Bars.HighPrices.Maximum(bars_back);
            

            var height = HL_max - HL_min;

            if (TimeFrame == TimeFrame.Minute15)
            {
                desired_chart_height = 180;
            }
            else if (TimeFrame == TimeFrame.Minute)
            {
                desired_chart_height = 75;
            }
            else if (TimeFrame == TimeFrame.Hour)
            {
                desired_chart_height = 200;
            }
            else if (TimeFrame == TimeFrame.Hour4)
            {
                desired_chart_height = 300;
            }
            else if (TimeFrame == TimeFrame.Daily)
            {
                desired_chart_height = 400;
            }
            else if (TimeFrame == TimeFrame.Weekly)
            {
                desired_chart_height = 500;
            }
            else
            {
                desired_chart_height = 75;
            }


            var margin = 0.1 * desired_chart_height;

            if (height / Symbol.PipSize < desired_chart_height)
            {

                min = HL_min - (desired_chart_height * Symbol.PipSize - height) / 2 - margin * Symbol.PipSize;
                max = HL_max + (desired_chart_height * Symbol.PipSize - height) / 2 + margin * Symbol.PipSize;
            }
            else
            {
                min = HL_min - margin * Symbol.PipSize;
                max = HL_max + margin * Symbol.PipSize;
            }


        }
        protected override void OnTimer()
        {
            if (Chart.LastVisibleBarIndex == Chart.BarsTotal - 1)
            {
                
                Chart.SetYRange(min, max);
                
            }
        }

    }

}

Any help with that issue will be appreciated. Also, I'm not proficient in coding, so if there is a better way to stretch the chart vertically, please let me know.

Btw, is there a way to code indi lines so that they are not treated as an object which must be considered in automatic scaling of the chart? I remember I couldn't get around it - only objects not produced with [Output], like e.g. horizontal lines generated inside the for{} loop could be all over the chart and it wouldn't compress because of them.


@Hyperion
Replies

PanagiotisCharalampous
07 Feb 2020, 12:01

Hi Tengu,

I tried to reproduce this behavior on Spotware Beta but I could not. Rescaling seems to work even after I close and open cTrader. Can you provide exact steps to reproduce this issue or record a video demonstrating this behavior?

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

Hyperion
14 Feb 2020, 09:25

RE:

Hi Panagiotis,

I've just installed Spotware Beta, logged in, it loaded my default workspace where I use that indicator, and it doesn't work properly, just as in my IC Markets cTrader. But when I opened a new chart and loaded template with this indi, it works ok. The same behavior on both platforms. Maybe the problem is with .NET Framework on my PC?

Here's a video demonstrating the behavior I'm talking about:

Best regards,

T

PanagiotisCharalampous said:

Hi Tengu,

I tried to reproduce this behavior on Spotware Beta but I could not. Rescaling seems to work even after I close and open cTrader. Can you provide exact steps to reproduce this issue or record a video demonstrating this behavior?

Best Regards,

Panagiotis 

Join us on Telegram

 

 


@Hyperion

Hyperion
20 Feb 2020, 13:37

RE: RE:

Hi,

after today's update, problem persists.

Anybody got any idea what could be done to fix it?


@Hyperion

PanagiotisCharalampous
20 Feb 2020, 14:22

Hi Tengu,

Unfortunately I could not reproduce this yet.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

srubtsov
21 Feb 2020, 14:42

Which other indicators do you have on the chart?


@srubtsov

Hyperion
23 Feb 2020, 14:32

RE:

srubtsov said:

Which other indicators do you have on the chart?

Normally I've got a few of my own custom indicators in the template/workspace I use, but there is nothing in them that would interfere with scaling chart by this one. Besides, I replicated the issue with only this indicator added on the chart (see the video I posted before).


@Hyperion

Hyperion
07 May 2020, 18:10

RE:

FYI, after last update (ca. two days ago) this zoom indi started working again. And that's interesting because earlier I've attempted many things to fix it and nothing worked (clean re-install of cTrader, fixing my .NET framework, and even upgrading Windows from 7 to 10).


@Hyperion

PanagiotisCharalampous
08 May 2020, 08:49

Hi Tengu,

We pushed some fixes in the latest update which probably fixed this issue as well.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous