On Balance Volume With MA free

Description

For any problem or bug, write on the telegram group

Join on t.me/cTraderCommunity

 

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
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 OBVCandle : Indicator
    {
        MovingAverage MA;

        [Parameter("Active", Group = "Candle Mode", DefaultValue = false)]
        public bool ShowCandles { get; set; }
        [Parameter("N° Candles", Group = "Candle Mode", DefaultValue = 300)]
        public int Candles { get; set; }
        [Parameter("Candles Thickness", Group = "Candle Mode", DefaultValue = 5)]
        public int Thickness { get; set; }
        [Parameter("Bull Candle Color", Group = "Candle Mode", DefaultValue = "MediumSeaGreen")]
        public string BullColorName { get; set; }
        [Parameter("Bear Candle Color", Group = "Candle Mode", DefaultValue = "OrangeRed")]
        public string BearColorName { get; set; }
        private Color BullColor, BearColor;
        [Parameter("MA Period", Group = "Moving Average", DefaultValue = 50)]
        public int MAPeriod { get; set; }
        [Parameter("MA Type", Group = "Moving Average", DefaultValue = 0)]
        public MovingAverageType MAType { get; set; }

        [Output("Main", LineColor = "White")]
        public IndicatorDataSeries Result { get; set; }
        [Output("Highs", PlotType = PlotType.Points, LineColor = "Black", Thickness = 0)]
        public IndicatorDataSeries Highs { get; set; }
        [Output("Lows", PlotType = PlotType.Points, LineColor = "Black", Thickness = 0)]
        public IndicatorDataSeries Lows { get; set; }

        [Output("MA", LineColor = "Orange")]
        public IndicatorDataSeries MaObv { get; set; }


        protected override void Initialize()
        {
            BullColor = Color.FromName(BullColorName);
            BearColor = Color.FromName(BearColorName);
            BarsTotal = Chart.BarsTotal;

            MA = Indicators.MovingAverage(Result, MAPeriod, MAType);
        }

        int BarsTotal;
        public override void Calculate(int index)
        {


            if (double.IsNaN(Result[index - 1]))
                Result[index - 1] = 0;

            int dir = Math.Sign(Bars[index].Close - Bars[index].Open);
            Result[index] = Result[index - 1] + dir * Bars[index].TickVolume;
            MaObv[index] = MA.Result[index];

            if (ShowCandles && BarsTotal - Candles < index)
                IndicatorArea.DrawTrendLine("Body" + index, index, Result[index], index, Result[index - 1], Result[index] > Result[index - 1] ? BullColor : BearColor, Thickness);
        }
    }
}
Comments
0