различные значения индикатора в логе и на графике

Created at 10 Mar 2020, 12:45
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!
TR

travkinsm1

Joined 05.04.2018

различные значения индикатора в логе и на графике
10 Mar 2020, 12:45


Hello! I downloaded the indicator. When displayed on the chart, it shows one value, and when this value is output to the log, another. Moreover, this behavior is not always. As a rule, the values coincide. The indicator parameters in the program and on the chart are the same. How can this be?


@travkinsm1
Replies

travkinsm1
10 Mar 2020, 12:52

RE: different indicator values in the log and on the chart

Sorry for the topic title. It should sound like: "different indicator values in the log and on the chart"


@travkinsm1

PanagiotisCharalampous
10 Mar 2020, 14:02

Hi travkinsm1,

Can we have the indicator and cBot code so that we can reproduce this?

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

travkinsm1
11 Mar 2020, 14:38

RE:

PanagiotisCharalampous said:

Hi travkinsm1,

Can we have the indicator and cBot code so that we can reproduce this?

Best Regards,

Panagiotis 

Join us on Telegram

 

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ATRStopbot : Robot
    {
        [Parameter("MA Method", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MaType { get; set; }

        [Parameter("True:High_Low False:Close", DefaultValue = true)]
        public bool UseHighAndLow { get; set; }

        [Parameter("Period1", DefaultValue = 15, MinValue = 2, MaxValue = 50000)]
        public int Period1 { get; set; }

        [Parameter("Weight1", DefaultValue = 3.0, MinValue = 0.1, MaxValue = 400.0)]
        public double Weight1 { get; set; }

        [Parameter("Period2", DefaultValue = 60, MinValue = 8, MaxValue = 50000)]
        public int Period2 { get; set; }

        [Parameter("Weight2", DefaultValue = 6.0, MinValue = 0.1, MaxValue = 400.0)]
        public double Weight2 { get; set; }

        private ATRStops atrS1 = new ATRStops();
        private ATRStops atrS2 = new ATRStops();
        protected override void OnStart()
        {
            var bars = MarketData.GetBars(TimeFrame.Minute, Bars.SymbolName);
            bars.BarOpened += NewBar;
            atrS1 = Indicators.GetIndicator<ATRStops>(MaType, Period1, Weight1, UseHighAndLow);
            atrS2 = Indicators.GetIndicator<ATRStops>(MaType, Period2, Weight2, UseHighAndLow);
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }
        private void NewBar(BarOpenedEventArgs obj)
        {
            Print("atrS1.Result.LastValue=", atrS1.Result.LastValue);
            Print("atrS2.Result.LastValue=", atrS2.Result.LastValue);
        }
                Positions[j].Close();
                protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}
using System;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator("ATR Trailing Stop", AutoRescale = false, IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class ATRStops : Indicator
    {

        [Parameter("MA Method", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MaType { get; set; }

        [Parameter("Period", DefaultValue = 15, MinValue = 2, MaxValue = 50000)]
        public int Period { get; set; }

        [Parameter("Weight", DefaultValue = 3.0, MinValue = 0.1, MaxValue = 400.0)]
        public double Weight { get; set; }

        [Parameter("True:High_Low False:Close", DefaultValue = true)]
        public bool UseHighAndLow { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        private AverageTrueRange _atr;
        private bool _isLong;

        protected override void Initialize()
        {
            _atr = Indicators.AverageTrueRange(Period, MaType);
        }

        public override void Calculate(int index)
        {
            var currentAtr = Weight * _atr.Result[index];

            if (double.IsNaN(currentAtr))
                return;

            if (double.IsNaN(Result[index - 1]) && !double.IsNaN(_atr.Result[index - 1]))
            {
                var previousATR = Weight * _atr.Result[index - 1];

                _isLong = MarketSeries.Close.IsRising();

                var previous = UseHighAndLow ? (_isLong ? MarketSeries.High[index - 1] : MarketSeries.Low[index - 1]) : MarketSeries.Close[index - 1];

                Result[index] = _isLong ? previous - previousATR : previous + previousATR;
            }
            else
            {
                var current = MarketSeries.Close[index];

                if (_isLong)
                {
                    if (current >= Result[index - 1])
                    {
                        if (UseHighAndLow)
                            current = MarketSeries.High[index];
                        Result[index] = Math.Max(Result[index - 1], current - currentAtr);
                    }
                    else
                    {
                        _isLong = false;
                        if (UseHighAndLow)
                            current = MarketSeries.Low[index];
                        Result[index] = current + currentAtr;
                    }
                }
                else
                {
                    if (current <= Result[index - 1])
                    {
                        if (UseHighAndLow)
                            current = MarketSeries.Low[index];
                        Result[index] = Math.Min(Result[index - 1], current + currentAtr);
                    }
                    else
                    {
                        _isLong = true;
                        if (UseHighAndLow)
                            current = MarketSeries.High[index];
                        Result[index] = current - currentAtr;
                    }
                }
            }
        }
    }
}

 


@travkinsm1

PanagiotisCharalampous
11 Mar 2020, 14:39

Hi travkinsm1,

Thanks, can you post the indicator as well?

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

travkinsm1
13 Mar 2020, 17:18

RE:

PanagiotisCharalampous said:

Hi travkinsm1,

Thanks, can you post the indicator as well?

Best Regards,

Panagiotis 

Join us on Telegram

Edited the message. Now it is with an indicator.


@travkinsm1

travkinsm1
19 Mar 2020, 17:52

Anyone have thoughts on my problem?


@travkinsm1

PanagiotisCharalampous
20 Mar 2020, 14:03

Hi travkinsm1,

This happens because you are printing the LastValue at the time of the bar creation. This value will change during the bar and will be finalized only when the bar closes. To make comparison with the chart you need to compare with the previously closed chart or check the value in OnTick() method.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

travkinsm1
21 Mar 2020, 12:52

tried so.

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ATRStopbot : Robot
    {
        public DateTime t;
        [Parameter("MA Method", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MaType { get; set; }

        [Parameter("True:High_Low False:Close", DefaultValue = true)]
        public bool UseHighAndLow { get; set; }

        [Parameter("Period1", DefaultValue = 15, MinValue = 2, MaxValue = 50000)]
        public int Period1 { get; set; }

        [Parameter("Weight1", DefaultValue = 3.0, MinValue = 0.1, MaxValue = 400.0)]
        public double Weight1 { get; set; }

        [Parameter("Period2", DefaultValue = 60, MinValue = 8, MaxValue = 50000)]
        public int Period2 { get; set; }

        [Parameter("Weight2", DefaultValue = 6.0, MinValue = 0.1, MaxValue = 400.0)]
        public double Weight2 { get; set; }

        [Parameter("Period3", DefaultValue = 240, MinValue = 7, MaxValue = 50000)]
        public int Period3 { get; set; }

        [Parameter("Weight3", DefaultValue = 12.0, MinValue = 0.1, MaxValue = 400.0)]
        public double Weight3 { get; set; }

        private ATRStops atrS1 = new ATRStops();
        private ATRStops atrS2 = new ATRStops();
        protected override void OnStart()
        {
            t = Bars.LastBar.OpenTime;
            atrS1 = Indicators.GetIndicator<ATRStops>(MaType, Period1, Weight1, UseHighAndLow);
            atrS2 = Indicators.GetIndicator<ATRStops>(MaType, Period2, Weight2, UseHighAndLow);

        }

        protected override void OnTick()
        {
            if (Bars.LastBar.OpenTime > t)
            {
                t = Bars.LastBar.OpenTime;
                Print("atrS1.Result.LastValue=", atrS1.Result[atrS1.Result.Count - 2]);
                Print("atrS2.Result.LastValue=", atrS2.Result[atrS2.Result.Count - 2]);
            }
                                            }
        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

but this did not solve the problem


@travkinsm1

PanagiotisCharalampous
23 Mar 2020, 08:40 ( Updated at: 21 Dec 2023, 09:21 )

Hi travkinsm1,

It seems ok to me

Can you provide more information regarding what do you think is the problem?

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

travkinsm1
23 Mar 2020, 19:10

As I already said, in places the indicator shows the correct values, and in some places, like 04/03/2020 02:02:00 it lies. 1.1184, while the graph is about 1.117. (This is an indicator with parameters period = 60 weight = 6 and a minute chart)


@travkinsm1

PanagiotisCharalampous
24 Mar 2020, 08:32 ( Updated at: 21 Dec 2023, 09:21 )

Hi travkinsm1,

It seems ok to me

 

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

travkinsm1
24 Mar 2020, 11:48

Sorry, I forgot to say that I am talking about Moscow time, i.e. UTC+3.


@travkinsm1

travkinsm1
31 Mar 2020, 14:51

What do you think?


@travkinsm1

PanagiotisCharalampous
31 Mar 2020, 15:05

Hi travkinsm1,

It seems to be an issue with the indicator but I am not sure what exactly is causing this. 

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

travkinsm1
10 Apr 2020, 19:35

RE:

Then, to whom you can apply for help.

 


@travkinsm1

PanagiotisCharalampous
13 Apr 2020, 08:35

Hi travkinsm1,

You need to reach out to the indicator developer. He knows better than anybody else how his indicator should work and how to fix this behavior.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

travkinsm1
02 May 2020, 14:23

RE:

Thanks

 


@travkinsm1