How to set BarColor programmatically

Created at 21 Apr 2022, 01:18
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!
Capt.Z-Fort.Builder's avatar

Capt.Z-Fort.Builder

Joined 03.06.2020

How to set BarColor programmatically
21 Apr 2022, 01:18


Hello,

I know SetBarColor() can change a specific index bar's color.

What I want to do, is to set all bar's color in my indicator (the same effect as of right click chart area and choose 'Color Option' then change the color items), according to some conditions, like symbol name or moving speed, so the chart can easily catch my eyesight?

Thanks.


@Capt.Z-Fort.Builder
Replies

amusleh
21 Apr 2022, 10:45

Hi,

Try this:

using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class SampleSMA : Indicator
    {
        protected override void Initialize()
        {
            // Bullish bars
            Chart.ColorSettings.BullFillColor = Color.Blue;
            Chart.ColorSettings.BullOutlineColor = Color.Blue;
            // Bearish bars
            Chart.ColorSettings.BearFillColor = Color.Gold;
            Chart.ColorSettings.BearOutlineColor = Color.Gold;
        }

        public override void Calculate(int index)
        {
        }
    }
}

 


@amusleh

Capt.Z-Fort.Builder
21 Apr 2022, 15:23

RE:

Thank you very much. It works very well.

BTW, I checked the BearOutlineColor but I didn't get the correct syntax until you put your sample code above.

Thanks again. :)

amusleh said:

Hi,

Try this:

using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class SampleSMA : Indicator
    {
        protected override void Initialize()
        {
            // Bullish bars
            Chart.ColorSettings.BullFillColor = Color.Blue;
            Chart.ColorSettings.BullOutlineColor = Color.Blue;
            // Bearish bars
            Chart.ColorSettings.BearFillColor = Color.Gold;
            Chart.ColorSettings.BearOutlineColor = Color.Gold;
        }

        public override void Calculate(int index)
        {
        }
    }
}

 

 


@Capt.Z-Fort.Builder