Topics
28 May 2024, 14:07
 293
 1
28 May 2024, 13:43
 2
 307
 0
25 Apr 2024, 17:29
 329
 2
25 Apr 2024, 14:39
 0
 297
 0
27 Mar 2024, 17:18
 302
 1
15 Jan 2024, 14:36
 2
 345
 0
15 Jan 2024, 14:34
 1
 571
 4
15 Jan 2024, 14:31
 3
 428
 1
15 Jan 2024, 14:26
 1
 412
 0
15 Jan 2024, 14:26
 1
 340
 0
17 Feb 2023, 01:24
 638
 2
Replies

caputojr
31 Jan 2022, 14:34

RE:

PanagiotisCharalampous said:

Hi caputojr,

If you google it, you will find many.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Hi Panagiotis,

Thank you for your prompt reply. In fact I did a google search but i could only find paid indicators and so I came here looking for some enlightment.

I hope I can find someone willing to help.

 

Thanks


@caputojr

caputojr
05 Apr 2021, 07:06

RE:

PanagiotisCharalampous said:

Hi firemyst,

I am not sure what are you trying to do with your source code but I tried the below and seems ok

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

namespace cAlgo
{
    [Indicator("OBV x MA Crossover", IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class OnBalanceVolumexMACrossover : Indicator
    {
        [Parameter("MA Short Period", Group = "Moving Averages", DefaultValue = 13, MinValue = 1)]
        public int MAXOverShortPeriod { get; set; }
        [Parameter("MA SP Type", Group = "Moving Averages", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType MAXOverShortPeriodType { get; set; }
        [Parameter("MA Long Period", Group = "Moving Averages", DefaultValue = 48, MinValue = 2)]
        public int MAXOverLongPeriod { get; set; }
        [Parameter("MA LP Type", Group = "Moving Averages", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType MAXOverLongPeriodType { get; set; }

        [Output("MA OBV Short", LineColor = "Green", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries ResultMaObvShort { get; set; }
        [Output("MA OBV Long", LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries ResultMaObvLong { get; set; }
        [Output("OBV", LineColor = "Cyan", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 2)]
        public IndicatorDataSeries ResultObv { get; set; }

        private OnBalanceVolume _onBalanceVolume;
        private OnBalanceVolume _onBalanceVolumeMaLong;
        private OnBalanceVolume _onBalanceVolumeMaShort;
        private MovingAverage _maLong;
        private MovingAverage _maShort;

        private IndicatorDataSeries _longIDS;
        private IndicatorDataSeries _shortIDS;

        private Bars _marketSeries;

        protected override void Initialize()
        {
            // Initialize and create nested indicators
            _marketSeries = MarketData.GetBars(Bars.TimeFrame, SymbolName);
            _maLong = Indicators.MovingAverage(_marketSeries.ClosePrices, MAXOverLongPeriod, MAXOverLongPeriodType);
            _maShort = Indicators.MovingAverage(_marketSeries.ClosePrices, MAXOverShortPeriod, MAXOverShortPeriodType);

            _onBalanceVolumeMaLong = Indicators.OnBalanceVolume(_maLong.Result);
            _onBalanceVolumeMaShort = Indicators.OnBalanceVolume(_maShort.Result);

        }

        public override void Calculate(int index)
        {
            ResultMaObvLong[index] = _onBalanceVolumeMaLong.Result[index];
            ResultMaObvShort[index] = _onBalanceVolumeMaShort.Result[index];
        }
    }
}

Best Regards,

Panagiotis 

Join us on Telegram

 

 

Hi Panagiotis,

I have tried to impement (copy and paste the code) to a new indicator and it is showing only the MAs, not the OBV. Is there somethng I can do to fix it?

 

Thank you in advance.


@caputojr

caputojr
05 Apr 2021, 00:47

RE:

amusleh said:

Hi,

There is already several very good free session indicators, you can use those instead of building a new one.

Regarding your code, for adding multiple time zone function you have to use the "Application.UserTimeOffset" and "Application.UserTimeOffsetChanged" for getting user current time zone offset, and then you can convert your indicator Server.Time or bar open times to the user time zone offset by adding the time offset value.

And yes its possible to show a vertical text, you have to use StringBuilder and add each latter as a new line on it.

Getting user time offset example:

using cAlgo.API;

namespace cAlgo
{
    /// <summary>
    /// This sample indicator shows how to use the API Application object nad display its properties data inside a chart control
    /// </summary>
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ApplicationSample : Indicator
    {
        private TextBlock _userTimeOffsetTextBlock, _themeTextBlock;

        [Parameter("Horizontal Alignment", DefaultValue = HorizontalAlignment.Center)]
        public HorizontalAlignment HorizontalAlignment { get; set; }

        [Parameter("Vertical Alignment", DefaultValue = VerticalAlignment.Center)]
        public VerticalAlignment VerticalAlignment { get; set; }

        protected override void Initialize()
        {
            Application.ColorThemeChanged += Application_ColorThemeChanged;
            Application.UserTimeOffsetChanged += Application_UserTimeOffsetChanged;

            DrawApplicationInfo();
        }

        private void Application_UserTimeOffsetChanged(UserTimeOffsetChangedEventArgs obj)
        {
            _userTimeOffsetTextBlock.Text = obj.UserTimeOffset.ToString();
        }

        private void Application_ColorThemeChanged(ColorThemeChangeEventArgs obj)
        {
            _themeTextBlock.Text = obj.ColorTheme.ToString();
        }

        private void DrawApplicationInfo()
        {
            var grid = new Grid(3, 2) 
            {
                BackgroundColor = Color.Goldenrod,
                HorizontalAlignment = HorizontalAlignment,
                VerticalAlignment = VerticalAlignment
            };

            grid.AddChild(new TextBlock 
            {
                Text = "Version",
                Margin = 5
            }, 0, 0);
            grid.AddChild(new TextBlock 
            {
                Text = Application.Version.ToString(),
                Margin = 5
            }, 0, 1);

            grid.AddChild(new TextBlock 
            {
                Text = "Theme",
                Margin = 5
            }, 1, 0);

            _themeTextBlock = new TextBlock 
            {
                Text = Application.ColorTheme.ToString(),
                Margin = 5
            };

            grid.AddChild(_themeTextBlock, 1, 1);

            grid.AddChild(new TextBlock 
            {
                Text = "User Time Offset",
                Margin = 5
            }, 2, 0);

            _userTimeOffsetTextBlock = new TextBlock 
            {
                Text = Application.UserTimeOffset.ToString(),
                Margin = 5
            };

            grid.AddChild(_userTimeOffsetTextBlock, 2, 1);

            Chart.AddControl(grid);
        }

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

 

Using StringBuilder:

using cAlgo.API;
using System.Text;

namespace cAlgo
{
    /// <summary>
    /// This sample shows how to use Chart.DrawStaticText method to draw static locked text on chart
    /// </summary>
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ChartStaticTextSample : Indicator
    {
        protected override void Initialize()
        {
            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Symbol: " + SymbolName);
            stringBuilder.AppendLine("TimeFrame: " + TimeFrame);
            stringBuilder.AppendLine("Chart Type: " + Chart.ChartType);

            Chart.DrawStaticText("Static_Sample", stringBuilder.ToString(), VerticalAlignment.Bottom, HorizontalAlignment.Left, Color.Red);
        }

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

 

Hi,

 

Thank you very much for taking the time to help me. I see what you say and I will work around the codes you've shared in order to get what I am expecting.

 

Appreciate it.


@caputojr