is it a bug with plottype

Created at 28 Jul 2021, 14:15
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!
IR

IRCtrader

Joined 17.06.2021

is it a bug with plottype
28 Jul 2021, 14:15


in this below code when i change plottype to histogram is ok but when i change it in plottype line it'w wrong and make 2 line .

i try with plottyp. point and it works. but i dont know why i have two line when i use plottype.line

in this code i try to have histogram line with 2 color. i need histgram line not histogram.

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

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

        public MacdHistogram MacdHistogram;

        [Parameter()]

        public DataSeries Source { get; set; }

        [Parameter("Long Cycle", DefaultValue = 26)]
        public int LongCycle { get; set; }

        [Parameter("Short Cycle", DefaultValue = 12)]
        public int ShortCycle { get; set; }



        [Output("Histogram Up", PlotType = PlotType.Line, Color = Colors.DodgerBlue)]
        public IndicatorDataSeries HistogramPositive { get; set; }

        [Output("Histogram Down", PlotType = PlotType.Line, Color = Colors.Red)]
        public IndicatorDataSeries HistogramNegative { get; set; }



        protected override void Initialize()
        {

            MacdHistogram = Indicators.MacdHistogram(Source, LongCycle, ShortCycle, 9);

        }

        public override void Calculate(int index)
        {



            if (MacdHistogram.Histogram[index] > 0)
            {
                HistogramPositive[index] = MacdHistogram.Histogram[index];
            }

            else if (MacdHistogram.Histogram[index] < 0)
            {
                HistogramNegative[index] = MacdHistogram.Histogram[index];
            }



        }
    }
}

 


@IRCtrader
Replies

amusleh
28 Jul 2021, 14:41

Hi,

Your indicator has two outputs, and it should display two lines, not one, it's not a bug.

Even if you don't provide a value for the line it will connect the line by using previous and next values on the output series.

To solve this use DiscontinuousLine or Histogram PlotType:

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

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

        public MacdHistogram MacdHistogram;

        [Parameter()]

        public DataSeries Source { get; set; }

        [Parameter("Long Cycle", DefaultValue = 26)]
        public int LongCycle { get; set; }

        [Parameter("Short Cycle", DefaultValue = 12)]
        public int ShortCycle { get; set; }



        [Output("Histogram Up", PlotType = PlotType.DiscontinuousLine, Color = Colors.DodgerBlue)]
        public IndicatorDataSeries HistogramPositive { get; set; }

        [Output("Histogram Down", PlotType = PlotType.DiscontinuousLine, Color = Colors.Red)]
        public IndicatorDataSeries HistogramNegative { get; set; }



        protected override void Initialize()
        {

            MacdHistogram = Indicators.MacdHistogram(Source, LongCycle, ShortCycle, 9);

        }

        public override void Calculate(int index)
        {
            HistogramPositive[index] = double.NaN;
            HistogramNegative[index] = double.NaN;


            if (MacdHistogram.Histogram[index] > 0)
            {
                HistogramPositive[index] = MacdHistogram.Histogram[index];
            }

            else if (MacdHistogram.Histogram[index] < 0)
            {
                HistogramNegative[index] = MacdHistogram.Histogram[index];
            }

        }
    }
}

 


@amusleh

IRCtrader
28 Jul 2021, 14:49 ( Updated at: 28 Jul 2021, 15:59 )

RE:

amusleh said:

Hi,

Your indicator has two outputs, and it should display two lines, not one, it's not a bug.

Even if you don't provide a value for the line it will connect the line by using previous and next values on the output series.

To solve this use DiscontinuousLine or Histogram PlotType:

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

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

        public MacdHistogram MacdHistogram;

        [Parameter()]

        public DataSeries Source { get; set; }

        [Parameter("Long Cycle", DefaultValue = 26)]
        public int LongCycle { get; set; }

        [Parameter("Short Cycle", DefaultValue = 12)]
        public int ShortCycle { get; set; }



        [Output("Histogram Up", PlotType = PlotType.DiscontinuousLine, Color = Colors.DodgerBlue)]
        public IndicatorDataSeries HistogramPositive { get; set; }

        [Output("Histogram Down", PlotType = PlotType.DiscontinuousLine, Color = Colors.Red)]
        public IndicatorDataSeries HistogramNegative { get; set; }



        protected override void Initialize()
        {

            MacdHistogram = Indicators.MacdHistogram(Source, LongCycle, ShortCycle, 9);

        }

        public override void Calculate(int index)
        {
            HistogramPositive[index] = double.NaN;
            HistogramNegative[index] = double.NaN;


            if (MacdHistogram.Histogram[index] > 0)
            {
                HistogramPositive[index] = MacdHistogram.Histogram[index];
            }

            else if (MacdHistogram.Histogram[index] < 0)
            {
                HistogramNegative[index] = MacdHistogram.Histogram[index];
            }

        }
    }
}

 

for my goal i have to use line. because my orginal indicator have multiple macd line and i need to see theri cross, so if output should be line i could see better that  crosses. is it possible to have one line with 2 output? in metatrader we have this.

is it possible we have 1 line and set 2 color with if for that ???

i can't understand why we have 1 histogram or 1 point line or 1 dicuntinue but we have 2 line.


@IRCtrader

amusleh
29 Jul 2021, 09:32

Hi,

You can have one line and two outputs, that's exactly what my posted code does.


@amusleh

IRCtrader
29 Jul 2021, 10:42

RE:

amusleh said:

Hi,

You can have one line and two outputs, that's exactly what my posted code does.

 i mean 1 output line with two color by condition.

could you please explain me why in plottype.point or dicontinueline or histogram, it's fine but plottype.line we have 2 line.

i couldn't underatnd it.


@IRCtrader

amusleh
29 Jul 2021, 11:02

RE: RE:

khoshroomahdi said:

amusleh said:

Hi,

You can have one line and two outputs, that's exactly what my posted code does.

 i mean 1 output line with two color by condition.

could you please explain me why in plottype.point or dicontinueline or histogram, it's fine but plottype.line we have 2 line.

i couldn't underatnd it.

Hi,

You can't have one output with two-color, the solution is to use two outputs and show only one based on some condition like I did on my code.

The PlotType.Line is continuous, it will always be shown even if you set some values in between to NAN.


@amusleh

IRCtrader
02 Aug 2021, 14:25 ( Updated at: 02 Aug 2021, 14:26 )

finally i solve it
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class MACDLine : Indicator
    {
        public MacdHistogram MacdHistogram;

        [Parameter()]
        public DataSeries Source { get; set; }

        [Parameter("Long Cycle", DefaultValue = 26)]
        public int LongCycle { get; set; }

        [Parameter("Short Cycle", DefaultValue = 12)]
        public int ShortCycle { get; set; }

        [Parameter("Signal Periods", DefaultValue = 9)]
        public int Periods { get; set; }




        [Output("Macd Line Up", PlotType = PlotType.DiscontinuousLine, LineColor = "Green", Thickness = 2)]
        public IndicatorDataSeries MacdLineUp { get; set; }

        [Output("Macd Line Dn", PlotType = PlotType.DiscontinuousLine, LineColor = "Red", Thickness = 2)]
        public IndicatorDataSeries MacdLineDn { get; set; }



        bool Mode;


        protected override void Initialize()
        {
            MacdHistogram = Indicators.MacdHistogram(Source, LongCycle, ShortCycle, Periods);
        }

        public override void Calculate(int index)
        {
            if (MacdHistogram.Histogram[index] >= MacdHistogram.Signal[index])
            {

                MacdLineUp[index] = MacdHistogram.Histogram[index];
                if (Mode == true)
                {
                    MacdLineUp[index - 1] = MacdHistogram.Histogram[index - 1];
                    Mode = false;
                }
            }

            else
            {
                MacdLineDn[index] = MacdHistogram.Histogram[index];
                if (Mode == false)
                {
                    MacdLineDn[index - 1] = MacdHistogram.Histogram[index - 1];
                    Mode = true;
                }

            }


        }
    }
}

 


@IRCtrader