Information

Username: mfejza
Member since: 25 Jan 2022
Last login: 08 Jul 2024
Status: Active

Activity

Where Created Comments
Algorithms 181 42
Forum Topics 0 0
Jobs 0 0

Last Algorithm Comments

mfejza's avatar
mfejza · 7 months ago

To whom it may concern

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class mSMMA : Indicator
    {
        [Parameter("Period (10)", DefaultValue = 10, MinValue = 2)]
        public int inpPeriod { get; set; }
        [Parameter("Data Source (close)", DefaultValue = enumPriceTypes.Close)]
        public enumPriceTypes inpPriceType { get; set; }

        [Output("SMMA", LineColor = "Black", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outSMMA { get; set; }

        private IndicatorDataSeries _price, _smma;
        private MovingAverage _pricesmooth;


        protected override void Initialize()
        {
            _price = CreateDataSeries();
            _smma = CreateDataSeries();
            _pricesmooth = Indicators.MovingAverage(_price, inpPeriod, MovingAverageType.Simple);
        }

        public override void Calculate(int i)
        {
            switch (inpPriceType)
            {
                case enumPriceTypes.Open:
                    _price[i] = Bars.OpenPrices[i];
                    break;
                case enumPriceTypes.Close:
                    _price[i] = Bars.ClosePrices[i];
                    break;
                case enumPriceTypes.High:
                    _price[i] = Bars.HighPrices[i];
                    break;
                case enumPriceTypes.Low:
                    _price[i] = Bars.LowPrices[i];
                    break;
                case enumPriceTypes.Median:
                    _price[i] = Bars.MedianPrices[i];
                    break;
                case enumPriceTypes.Typical:
                    _price[i] = Bars.TypicalPrices[i];
                    break;
                case enumPriceTypes.Weighted:
                    _price[i] = Bars.WeightedPrices[i];
                    break;
                default:
                    _price[i] = Bars.ClosePrices[i];
                    break;
            }
            _smma[i] = (((i>1 ? _smma[i-1] : _price[i]) * (inpPeriod - 1)) + _price[i]) / inpPeriod;
            
            outSMMA[i] = _smma[i];
        }
    }

    public enum enumPriceTypes
    {
        Open,
        Close,
        High,
        Low,
        Median,
        Typical,
        Weighted
    }
}
mfejza's avatar
mfejza · 7 months ago

The FVG indicator you're inquiring about is just one element of your trading strategy. There are numerous variations in trading strategies, each influenced by the unique properties of financial instruments. The initial step involves identifying price movements characterized by FVG attributes, encompassing both positive and negative price sentiment.
Here is a FVG indicator to identify FVG sentiment, maybe is useful for your project.

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

namespace cAlgo
{
    [Cloud("FVGBullishHigh", "FVGBullishLow", FirstColor = "Green", SecondColor = "Transparent", Opacity = 0.1)]
    [Cloud("FVGBearishHigh", "FVGBearishLow", FirstColor = "Red", SecondColor = "Transparent", Opacity = 0.1)]
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None, AutoRescale = true)]
    public class mFVG : Indicator
    {
        [Output("FVGBullishHigh", LineColor = "Green", PlotType = PlotType.Points, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outFVGBullishHigh { get; set; }
        [Output("FVGBullishLow", LineColor = "Green", PlotType = PlotType.Points, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outFVGBullishLow { get; set; }
        [Output("FVGBearishHigh", LineColor = "Red", PlotType = PlotType.Points, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outFVGBearishHigh { get; set; }
        [Output("FVGBearishLow", LineColor = "Red", PlotType = PlotType.Points, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outFVGBearishLow { get; set; }
        
        private IndicatorDataSeries _fvgbullishhigh, _fvgbullishlow, _fvgbearishhigh, _fvgbearishlow;
        

        protected override void Initialize()
        {
            _fvgbullishhigh = CreateDataSeries();
            _fvgbullishlow = CreateDataSeries();
            _fvgbearishhigh = CreateDataSeries();
            _fvgbearishlow = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            _fvgbullishhigh[i] = i>4 ? _fvgbullishhigh[i-1] : Bars.ClosePrices[i];
            _fvgbullishlow[i] = i>4 ? _fvgbullishlow[i-1] : Bars.ClosePrices[i];
            _fvgbearishhigh[i] = i>4 ? _fvgbearishhigh[i-1] : Bars.ClosePrices[i];
            _fvgbearishlow[i] = i>4 ? _fvgbearishlow[i-1] : Bars.ClosePrices[i];
            
            if(Bars.ClosePrices[i-3] > Bars.OpenPrices[i-3] && Bars.ClosePrices[i-2] > Bars.OpenPrices[i-2] && Bars.ClosePrices[i-1] > Bars.OpenPrices[i-1] && Bars.LowPrices[i-1] > Bars.HighPrices[i-3])
            {
                _fvgbullishhigh[i] = Math.Max(Bars.LowPrices[i-1], Bars.HighPrices[i-3]); // Bars.LowPrices[i-1];
                _fvgbullishlow[i] = Math.Min(Bars.LowPrices[i-1], Bars.HighPrices[i-3]); // Bars.HighPrices[i-3];
            }
                
            if(Bars.ClosePrices[i-3] < Bars.OpenPrices[i-3] && Bars.ClosePrices[i-2] < Bars.OpenPrices[i-2] && Bars.ClosePrices[i-1] < Bars.OpenPrices[i-1] && Bars.HighPrices[i-1] < Bars.LowPrices[i-3])
            {
                _fvgbearishhigh[i] = Math.Max(Bars.LowPrices[i-3], Bars.HighPrices[i-1]); // Bars.LowPrices[i-3];
                _fvgbearishlow[i] = Math.Min(Bars.LowPrices[i-3], Bars.HighPrices[i-1]); // Bars.HighPrices[i-1];
            }
                
            outFVGBullishHigh[i] = _fvgbullishhigh[i];
            outFVGBullishLow[i] = _fvgbullishlow[i];
            outFVGBearishHigh[i] = _fvgbearishhigh[i];
            outFVGBearishLow[i] = _fvgbearishlow[i];
        }
    }
}
mfejza's avatar
mfejza · 7 months ago

try this

using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class RectangleHorizontalLine : Indicator
    {
        [Parameter("Period (10)", DefaultValue = 10)]
        public int inpPeriod { get; set; }
    
        private ChartRectangle _rectangle;
        private ChartTrendLine _trendLine;
        

        protected override void Initialize()
        {
        }

        public override void Calculate(int index)
        {
            //help.ctrader.com/ctrader-automate/references/Chart/Drawings/Shapes/ChartRectangle/#namespace
            _rectangle = Chart.DrawRectangle("rectangle"
                                            , Chart.LastVisibleBarIndex - inpPeriod
                                            , Bars.LowPrices.Minimum(inpPeriod)
                                            , Chart.LastVisibleBarIndex - 1
                                            , Bars.HighPrices.Maximum(inpPeriod)
                                            , Color.Black);
            _rectangle.IsFilled = false;
            _rectangle.IsInteractive = true;

            //help.ctrader.com/ctrader-automate/references/Chart/Drawings/ChartTrendLine/#summary
            _trendLine = Chart.DrawTrendLine("trendLine"
                                            , Chart.LastVisibleBarIndex - inpPeriod
                                            , (Bars.LowPrices.Minimum(inpPeriod) + Bars.HighPrices.Maximum(inpPeriod)) / 2
                                            , Chart.LastVisibleBarIndex - 1
                                            , (Bars.LowPrices.Minimum(inpPeriod) + Bars.HighPrices.Maximum(inpPeriod)) / 2
                                            , Color.Red
                                            , 1
                                            , LineStyle.Solid);
             _trendLine.IsInteractive = true;
        }
    }
}
mfejza's avatar
mfejza · 7 months ago

try this

using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class RectangleHorizontalLine : Indicator
    {
        [Parameter("Period (10)", DefaultValue = 10)]
        public int inpPeriod { get; set; }
    
        private ChartRectangle _rectangle;
        private ChartTrendLine _trendLine;
        

        protected override void Initialize()
        {
        }

        public override void Calculate(int index)
        {
            //https://help.ctrader.com/ctrader-automate/references/Chart/Drawings/Shapes/ChartRectangle/#namespace
            _rectangle = Chart.DrawRectangle("rectangle"
                                            , Chart.LastVisibleBarIndex - inpPeriod
                                            , Bars.LowPrices.Minimum(inpPeriod)
                                            , Chart.LastVisibleBarIndex - 1
                                            , Bars.HighPrices.Maximum(inpPeriod)
                                            , Color.Black);
            _rectangle.IsFilled = false;
            _rectangle.IsInteractive = true;

            //https://help.ctrader.com/ctrader-automate/references/Chart/Drawings/ChartTrendLine/#summary
            _trendLine = Chart.DrawTrendLine("trendLine"
                                            , Chart.LastVisibleBarIndex - inpPeriod
                                            , (Bars.LowPrices.Minimum(inpPeriod) + Bars.HighPrices.Maximum(inpPeriod)) / 2
                                            , Chart.LastVisibleBarIndex - 1
                                            , (Bars.LowPrices.Minimum(inpPeriod) + Bars.HighPrices.Maximum(inpPeriod)) / 2
                                            , Color.Red
                                            , 1
                                            , LineStyle.Solid);
             _trendLine.IsInteractive = true;
        }
    }
}
mfejza's avatar
mfejza · 8 months ago

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

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class DemoDisparityIndex : Robot
    {
        [Parameter("Periods (10)", DefaultValue = 10, Group = "DisparityIndex")]
        public int inpPeriods { get; set; }
        [Parameter("Levels Coefficients (2.618)", DefaultValue = 2.618, Group = "DisparityIndex")]
        public double inpLevelsCoefficients { get; set; }
        [Parameter("Smooth Type (sma)", DefaultValue = MovingAverageType.Simple, Group = "DisparityIndex")]
        public MovingAverageType inpSmoothType { get; set; }
        
        private mDisparityIndex _di;
        

        protected override void OnStart()
        {
            _di = Indicators.GetIndicator<mDisparityIndex>(inpPeriods, inpLevelsCoefficients, inpSmoothType);
        }

        protected override void OnTick()
        {
            if(_di.outDisparityIndex.LastValue > _di.outDisparityIndexUp.LastValue)
            {
                //Long zone
            }
            
            if(_di.outDisparityIndex.LastValue < _di.outDisparityIndexDown.LastValue)
            {
                //Short zone
            }
        }

        protected override void OnStop()
        {
            _di = null;
        }
    }
}

mfejza's avatar
mfejza · 9 months ago

bbukur

mfejza's avatar
mfejza · 10 months ago

Se apprezzi l'algoritmo logico dell'indice di smorzamento, puoi anche utilizzare l'indicatore personalizzato fornito dopo il commento. Public ProAction ha una logica simile e, come proprietà aggiuntiva, mostra esattamente i Pips for Action.

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

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

        [Output("PublicPro Action", LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outPublicProAction { get; set; }

        private IndicatorDataSeries _public, _pro, _firpublic, _firpro, _result;
        

        protected override void Initialize()
        {
            _public = CreateDataSeries();
            _pro = CreateDataSeries();
            _firpublic = CreateDataSeries();
            _firpro = CreateDataSeries();
            _result = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            _public[i] = i>1 ? Bars.ClosePrices[i-1] : Bars.TypicalPrices[i] - Bars.OpenPrices[i];
            _pro[i] = Bars.ClosePrices[i] - Bars.OpenPrices[i];
            _firpublic[i] = i>4 ? (_public[i] + 2.0 * _public[i-1] + 2.0 * _public[i-2] + _public[i-3]) / 6.0 : Bars.ClosePrices[i] - Bars.TypicalPrices[i];
            _firpro[i] = i>4 ? (_pro[i] + 2.0 * _pro[i-1] + 2.0 * _pro[i-2] + _pro[i-3]) / 6.0 : Bars.ClosePrices[i] - Bars.MedianPrices[i];
            _result[i] = _firpro[i] - _firpublic[i];
            
            //outPublicProAction[i] = Bars.ClosePrices[i] + _result[i];
            outPublicProAction[i] = (Bars.ClosePrices[i] + _result[i]) / Symbol.PipSize;
        }
    }
}
mfejza's avatar
mfejza · 11 months ago

This custom indicator is a lag indicator. To use it properly, you should consider the lagging information for further decision-making as a price action confirmation. 

This indicator is also considered a price correction zone when the price is opposite to the indicator signal. 

Implementing a cBot for this indicator is easy, but the most significant problem is the method of managing positions.

Here you have idea how to use it, inside cBot.

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

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class NewcBotCA : Robot
    {
        [Parameter("Period (14)", DefaultValue = 14, MinValue = 1)]
        public int inpPeriod { get; set; }
        [Parameter("Data Source (close)", DefaultValue = enumPriceTypes.Close)]
        public enumPriceTypes inpPriceType { get; set; }
        [Parameter("Smooth Type (sma)", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType inpSmoothType { get; set; }
        
        private mCorrectedAverage _iCA;

        protected override void OnStart()
        {
            _iCA = Indicators.GetIndicator<mCorrectedAverage>(inpPeriod, inpPriceType, inpSmoothType);
        }

        protected override void OnTick()
        {
            if(_iCA.outCorrectedAverage.LastValue > _iCA.outCorrectedAverageSignal.LastValue)
            {
                //Long zone
            }
            
            if(_iCA.outCorrectedAverage.LastValue < _iCA.outCorrectedAverageSignal.LastValue)
            {
                //Short zone
            }
        }

        protected override void OnStop()
        {
            _iCA = null;
        }
    }
}
mfejza's avatar
mfejza · 11 months ago

@kevinssendawula

send me a email account where to send it?

mfejza's avatar
mfejza · 1 year ago

Very interesting logic, I like it.

mfejza's avatar
mfejza · 1 year ago

I kindly request the administrators to remove materials like this one, which lack substance with blank content and have a negative impact on the information available to users of the cTrade platform.

The content published on this page is not related to cTrade indicators or anything else related to cTrade.

Thank you in advance.

mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TCF : Indicator
    {
        [Parameter("ROC Period (1)", DefaultValue = 1)]
        public int inpPeriodsROC { get; set; }
        [Parameter("Smooth Period (20)", DefaultValue = 20)]
        public int inpPeriodsSmooth { get; set; }
        [Parameter("Data Source (close)", DefaultValue = enumPriceTypes.Close)]
        public enumPriceTypes inpPriceType { get; set; } 

        [Output("TCF Bulls", LineColor = "Green", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outTCFbulls { get; set; }
        [Output("TCF Bears", LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outTCFbears { get; set; }
        
        private IndicatorDataSeries _price, _cp, _roc, _PC, _NC, _PCF, _NCF, _bulls, _bears;
        private MovingAverage _smoothpc, _smoothnc, _smoothpcf, _smoothncf;
        

        protected override void Initialize()
        {
            _price = CreateDataSeries();
            _cp = CreateDataSeries();
            _roc = CreateDataSeries();
            _PC = CreateDataSeries();
            _NC = CreateDataSeries();
            _PCF = CreateDataSeries();
            _NCF = CreateDataSeries();
            _bulls = CreateDataSeries();
            _bears = CreateDataSeries();
            _smoothpc = Indicators.MovingAverage(_PC, inpPeriodsSmooth, MovingAverageType.Simple);
            _smoothnc = Indicators.MovingAverage(_NC, inpPeriodsSmooth, MovingAverageType.Simple);
            _smoothpcf = Indicators.MovingAverage(_PCF, inpPeriodsSmooth, MovingAverageType.Simple);
            _smoothncf = Indicators.MovingAverage(_NCF, inpPeriodsSmooth, MovingAverageType.Simple);
        }

        public override void Calculate(int i)
        {
            switch(inpPriceType)
            {
                case enumPriceTypes.Open:
                    _price[i] = Bars.OpenPrices[i];
                    break;
                case enumPriceTypes.Close:
                    _price[i] = Bars.ClosePrices[i];
                    break;
                case enumPriceTypes.High:
                    _price[i] = Bars.HighPrices[i];
                    break;
                case enumPriceTypes.Low:
                    _price[i] = Bars.LowPrices[i];
                    break;
                case enumPriceTypes.Median:
                    _price[i] = Bars.MedianPrices[i];
                    break;
                case enumPriceTypes.Typical:
                    _price[i] = Bars.TypicalPrices[i];
                    break;
                case enumPriceTypes.Weighted:
                    _price[i] = Bars.WeightedPrices[i];
                    break;
                default:
                    _price[i] = Bars.ClosePrices[i];
                    break;
            }
            _cp[i] = i>inpPeriodsROC ? _price[i-inpPeriodsROC] : (Bars.TypicalPrices[i] + Bars.WeightedPrices[i]) / 2;
            _roc[i] = _cp[i] != 0 ? 100.0 * (_price[i] - _cp[i]) / _cp[i] : 0;
            _PC[i] = _roc[i] > 0 ? _roc[i] : 0;
            _NC[i] = _roc[i] > 0 ? 0 : -_roc[i];
            _PCF[i] = _roc[i] > 0 ? (i>1 ? _PCF[i-1] : 0) + _roc[i] : 0;
            _NCF[i] = _roc[i] > 0 ? 0 : (i>1 ? _NCF[i-1] : 0) - _roc[i];
            _bulls[i] = (_smoothpc.Result[i] + inpPeriodsSmooth) - (_smoothncf.Result[i] + inpPeriodsSmooth);
            _bears[i] = (_smoothnc.Result[i] + inpPeriodsSmooth) - (_smoothpcf.Result[i] + inpPeriodsSmooth);

            outTCFbulls[i] = _bulls[i];
            outTCFbears[i] = _bears[i];
        }
    }
    
    public enum enumPriceTypes
    {
        Open,
        Close,
        High,
        Low,
        Median,
        Typical,
        Weighted
    }
}
mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class mEhlersReflex : Indicator
    {
        [Parameter("Period (20)", DefaultValue = 20)]
        public int inpPeriod { get; set; }
        [Parameter("Data Source (close)", DefaultValue = enumPriceTypes.Close)]
        public enumPriceTypes inpPriceType { get; set; }  

        [Output("Reflex", LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outReflex { get; set; }
        
        private double _a1, _b1, _c1, _c2, _c3;
        private IndicatorDataSeries _price, _filt, _slope, _sum, _raw, _ms, _reflex;

        protected override void Initialize()
        {
            _a1 = Math.Exp(-1.414 * 3.14159 / (0.5 * inpPeriod));
            _b1 = 2 * _a1 * Math.Cos(1.414 * 180 / (0.5 * inpPeriod));
            _c3 = -_a1 * _a1 ;
            _c2 = _b1 ;
            _c1 = 1 - _c2 - _c3 ;
            _price = CreateDataSeries();
            _filt = CreateDataSeries();
            _slope = CreateDataSeries();
            _sum = CreateDataSeries();
            _raw = CreateDataSeries();
            _ms = CreateDataSeries();
            _reflex = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            switch(inpPriceType)
            {
                case enumPriceTypes.Open:
                    _price[i] = Bars.OpenPrices[i];
                    break;
                case enumPriceTypes.Close:
                    _price[i] = Bars.ClosePrices[i];
                    break;
                case enumPriceTypes.High:
                    _price[i] = Bars.HighPrices[i];
                    break;
                case enumPriceTypes.Low:
                    _price[i] = Bars.LowPrices[i];
                    break;
                case enumPriceTypes.Median:
                    _price[i] = Bars.MedianPrices[i];
                    break;
                case enumPriceTypes.Typical:
                    _price[i] = Bars.TypicalPrices[i];
                    break;
                case enumPriceTypes.Weighted:
                    _price[i] = Bars.WeightedPrices[i];
                    break;
                default:
                    _price[i] = Bars.ClosePrices[i];
                    break;
            }
            
            _filt[i] = _c1 * (_price[i] + _price[i-1]) / 2 + _c2 * (i>1 ? _filt[i-1] : 0) + _c3 * (i>2 ? _filt[i-2] : 0);
            _slope[i] = (_filt[i-inpPeriod] - _filt[i] ) / inpPeriod;
            _sum[i] = 0;
            for (int j=1; j<inpPeriod; j++)
                _sum[i] += (_filt[i] + j * _slope[i]) - (i>inpPeriod ? _filt[i-j] : 0);
            _raw[i] = _sum[i] / inpPeriod;
            _ms[i] = 0.04 * _raw[i] * _raw[i] + (i>1 ? 0.96 * (!double.IsNaN(_ms[i-1]) ? _ms[i-1] : 1) : 0);
            _reflex[i] = _ms[i] != 0 ? _raw[i] / Math.Sqrt(_ms[i]) : 0;

            outReflex[i] = _reflex[i];
        }
    }
    
    public enum enumPriceTypes
    {
        Open,
        Close,
        High,
        Low,
        Median,
        Typical,
        Weighted
    }
}
mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class mEhlersTrendflex : Indicator
    {
        [Parameter("Period (20)", DefaultValue = 20)]
        public int inpPeriod { get; set; }
        [Parameter("Data Source (close)", DefaultValue = enumPriceTypes.Close)]
        public enumPriceTypes inpPriceType { get; set; }  

        [Output("TrendFlex", LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outTrendflex { get; set; }
        
        private double _a1, _b1, _c1, _c2, _c3;
        private IndicatorDataSeries _price, _filt, _sum, _raw, _ms, _trendflex;

        protected override void Initialize()
        {
            _a1 = Math.Exp(-1.414 * 3.14159 / (0.5 * inpPeriod));
            _b1 = 2 * _a1 * Math.Cos(1.414 * 180 / (0.5 * inpPeriod));
            _c3 = -_a1 * _a1 ;
            _c2 = _b1 ;
            _c1 = 1 - _c2 - _c3 ;
            _price = CreateDataSeries();
            _filt = CreateDataSeries();
            _sum = CreateDataSeries();
            _raw = CreateDataSeries();
            _ms = CreateDataSeries();
            _trendflex = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            switch(inpPriceType)
            {
                case enumPriceTypes.Open:
                    _price[i] = Bars.OpenPrices[i];
                    break;
                case enumPriceTypes.Close:
                    _price[i] = Bars.ClosePrices[i];
                    break;
                case enumPriceTypes.High:
                    _price[i] = Bars.HighPrices[i];
                    break;
                case enumPriceTypes.Low:
                    _price[i] = Bars.LowPrices[i];
                    break;
                case enumPriceTypes.Median:
                    _price[i] = Bars.MedianPrices[i];
                    break;
                case enumPriceTypes.Typical:
                    _price[i] = Bars.TypicalPrices[i];
                    break;
                case enumPriceTypes.Weighted:
                    _price[i] = Bars.WeightedPrices[i];
                    break;
                default:
                    _price[i] = Bars.ClosePrices[i];
                    break;
            }
            
            _filt[i] = _c1 * (_price[i] + _price[i-1]) / 2 + _c2 * (i>1 ? _filt[i-1] : 0) + _c3 * (i>2 ? _filt[i-2] : 0);
            _sum[i] = 0;
            for (int j=1; j<inpPeriod; j++)
                _sum[i] += _filt[i] - (i>inpPeriod ? _filt[i-j] : 0);
            _raw[i] = _sum[i] / inpPeriod;
            _ms[i] = 0.04 * _raw[i] * _raw[i] + (i>1 ? 0.96 * (!double.IsNaN(_ms[i-1]) ? _ms[i-1] : 1) : 0);
            _trendflex[i] = _ms[i] != 0 ? _raw[i] / Math.Sqrt(_ms[i]) : 0;

            outTrendflex[i] = _trendflex[i];
        }
    }
    
    public enum enumPriceTypes
    {
        Open,
        Close,
        High,
        Low,
        Median,
        Typical,
        Weighted
    }
}
mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class mROCbands : Indicator
    {
        [Parameter("Main Period (12)", DefaultValue = 12)]
        public int inpPeriod { get; set; }
        [Parameter("Smooth Period (3)", DefaultValue = 3)]
        public int inpPeriodSmooth { get; set; }
        [Parameter("Data Source (close)", DefaultValue = enumPriceTypes.Close)]
        public enumPriceTypes inpPriceType { get; set; }

        [Output("ROC Bands", LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outOSC { get; set; } 
        [Output("ROC Band Up", LineColor = "Rec", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outOSCup { get; set; } 
        [Output("ROC Band Down", LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outOSCdn { get; set; } 
        
        private IndicatorDataSeries _price, _rocsquare, _deviation;
        private PriceROC _rocprice;
        private MovingAverage _rocsmooth, _smoothsquare;
        

        protected override void Initialize()
        {
            _price = CreateDataSeries();
            _rocsquare = CreateDataSeries();
            _deviation = CreateDataSeries();
            _rocprice = Indicators.PriceROC(_price, inpPeriod);
            _rocsmooth = Indicators.MovingAverage(_rocprice.Result, inpPeriodSmooth, MovingAverageType.Exponential);
            _smoothsquare = Indicators.MovingAverage(_rocsquare, inpPeriod, MovingAverageType.Simple);
        }

        public override void Calculate(int i)
        {
            switch (inpPriceType)
            {
                case enumPriceTypes.Open:
                    _price[i] = Bars.OpenPrices[i];
                    break;
                case enumPriceTypes.Close:
                    _price[i] = Bars.ClosePrices[i];
                    break;
                case enumPriceTypes.High:
                    _price[i] = Bars.HighPrices[i];
                    break;
                case enumPriceTypes.Low:
                    _price[i] = Bars.LowPrices[i];
                    break;
                case enumPriceTypes.Median:
                    _price[i] = Bars.MedianPrices[i];
                    break;
                case enumPriceTypes.Typical:
                    _price[i] = Bars.TypicalPrices[i];
                    break;
                case enumPriceTypes.Weighted:
                    _price[i] = Bars.WeightedPrices[i];
                    break;
                default:
                    _price[i] = Bars.ClosePrices[i];
                    break;
            }
            _rocsquare[i] = Math.Pow(_rocprice.Result[i], 2);
            _deviation[i] = Math.Sqrt(_smoothsquare.Result[i]);
            
            outOSC[i] = _rocsmooth.Result[i];
            outOSCup[i] = _deviation[i];
            outOSCdn[i] = -_deviation[i];
        }
    }
    
    public enum enumPriceTypes
    {
        Open,
        Close,
        High,
        Low,
        Median,
        Typical,
        Weighted
    }
}
mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class mROCbands : Indicator
    {
        [Parameter("Fast Period (12)", DefaultValue = 12)]
        public int inpPeriodFast { get; set; }
        [Parameter("Slow Period (3)", DefaultValue = 3)]
        public int inpPeriodSlow { get; set; }
        [Parameter("Signal Period (12)", DefaultValue = 12)]
        public int inpPeriodSignal { get; set; }
        [Parameter("Data Source (close)", DefaultValue = enumPriceTypes.Close)]
        public enumPriceTypes inpPriceType { get; set; }

        [Output("ROC Bands", LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outOSC { get; set; } 
        [Output("ROC Band Up", LineColor = "Rec", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outOSCup { get; set; } 
        [Output("ROC Band Down", LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outOSCdn { get; set; } 
        
        private IndicatorDataSeries _price, _rocsquare, _deviation;
        private PriceROC _rocprice;
        private MovingAverage _rocsmooth, _smoothsquare;
        

        protected override void Initialize()
        {
            _price = CreateDataSeries();
            _rocsquare = CreateDataSeries();
            _deviation = CreateDataSeries();
            _rocprice = Indicators.PriceROC(_price, inpPeriodFast);
            _rocsmooth = Indicators.MovingAverage(_rocprice.Result, inpPeriodSlow, MovingAverageType.Exponential);
            _smoothsquare = Indicators.MovingAverage(_rocsquare, inpPeriodSignal, MovingAverageType.Simple);
        }

        public override void Calculate(int i)
        {
            switch (inpPriceType)
            {
                case enumPriceTypes.Open:
                    _price[i] = Bars.OpenPrices[i];
                    break;
                case enumPriceTypes.Close:
                    _price[i] = Bars.ClosePrices[i];
                    break;
                case enumPriceTypes.High:
                    _price[i] = Bars.HighPrices[i];
                    break;
                case enumPriceTypes.Low:
                    _price[i] = Bars.LowPrices[i];
                    break;
                case enumPriceTypes.Median:
                    _price[i] = Bars.MedianPrices[i];
                    break;
                case enumPriceTypes.Typical:
                    _price[i] = Bars.TypicalPrices[i];
                    break;
                case enumPriceTypes.Weighted:
                    _price[i] = Bars.WeightedPrices[i];
                    break;
                default:
                    _price[i] = Bars.ClosePrices[i];
                    break;
            }
            _rocsquare[i] = Math.Pow(_rocprice.Result[i], 2);
            _deviation[i] = Math.Sqrt(_smoothsquare.Result[i]);
            
            outOSC[i] = _rocsmooth.Result[i];
            outOSCup[i] = _deviation[i];
            outOSCdn[i] = -_deviation[i];
        }
    }
    
    public enum enumPriceTypes
    {
        Open,
        Close,
        High,
        Low,
        Median,
        Typical,
        Weighted
    }
}
mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class mHanningFilter : Indicator
    {
        [Parameter("Period (10)", DefaultValue = 10, MinValue = 3)]
        public int inpPeriod { get; set; }
        [Parameter("Data Source (close)", DefaultValue = enumPriceTypes.Close)]
        public enumPriceTypes inpPriceType { get; set; }    

        [Output("Hanning Filter", LineColor = "FFAA83C6", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 2)]
        public IndicatorDataSeries outHanningFilter { get; set; }
        
        private IndicatorDataSeries _price, _filt, _hanningfilter;
        private double _coef;
        

        protected override void Initialize()
        {
            _price = CreateDataSeries();
            _filt = CreateDataSeries();
            _hanningfilter = CreateDataSeries();
            for (int j=1; j<inpPeriod; j++)
                _coef += (1 - Math.Cos(2.0 * 3.1415926 * j / (inpPeriod + 1)));
        }

        public override void Calculate(int i)
        {
            switch(inpPriceType)
            {
                case enumPriceTypes.Open:
                    _price[i] = Bars.OpenPrices[i];
                    break;
                case enumPriceTypes.Close:
                    _price[i] = Bars.ClosePrices[i];
                    break;
                case enumPriceTypes.High:
                    _price[i] = Bars.HighPrices[i];
                    break;
                case enumPriceTypes.Low:
                    _price[i] = Bars.LowPrices[i];
                    break;
                case enumPriceTypes.Median:
                    _price[i] = Bars.MedianPrices[i];
                    break;
                case enumPriceTypes.Typical:
                    _price[i] = Bars.TypicalPrices[i];
                    break;
                case enumPriceTypes.Weighted:
                    _price[i] = Bars.WeightedPrices[i];
                    break;
                default:
                    _price[i] = Bars.ClosePrices[i];
                    break;
            }
            
            _filt[i] = 0;
            for (int j=1; j<inpPeriod; j++)
                _filt[i] += (1 - Math.Cos(2.0 * 3.1415926 * j / (inpPeriod + 1))) * (i>inpPeriod ? _price[i-j-1] : _price[i]);
            _hanningfilter[i] = _coef!=0 ? (_filt[i] / _coef) : _filt[i];
            
            outHanningFilter[i] = _hanningfilter[i];
        }
    }
    
    public enum enumPriceTypes
    {
        Open,
        Close,
        High,
        Low,
        Median,
        Typical,
        Weighted
    }
}
mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class mComparePriceMomentumOscillator : Indicator
    {
        [Parameter("Fast Period (20)", DefaultValue = 20)]
        public int inpPeriodFast { get; set; }
        [Parameter("Slow Period (35)", DefaultValue = 35)]
        public int inpPeriodSlow { get; set; }
        [Parameter("Signal Period (10)", DefaultValue = 10)]
        public int inpPeriodSignal { get; set; }
        [Parameter("Data Source (close)", DefaultValue = enumPriceTypes.Close)]
        public enumPriceTypes inpPriceType { get; set; }
        [Parameter("Output Result (fast)", DefaultValue = enumOutputResult.Smooth)]
        public enumOutputResult inpOutputResult { get; set; }

        [Output("Price Momentum", LineColor = "Black", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outPMO { get; set; }
        [Output("Price Signal", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outSignal { get; set; }
        
        private IndicatorDataSeries _price, _pmo;
        private PriceROC _roc;
        private ExponentialMovingAverage _rocsmooth1, _rocsmooth2, _pmosignal;
        

        protected override void Initialize()
        {
            _price = CreateDataSeries();
            _roc = Indicators.PriceROC(_price, 1);
            _rocsmooth1 = Indicators.ExponentialMovingAverage(_roc.Result, inpPeriodSlow);
            _rocsmooth2 = Indicators.ExponentialMovingAverage(_rocsmooth1.Result, inpPeriodFast);
            _pmosignal = Indicators.ExponentialMovingAverage((inpOutputResult == enumOutputResult.Fast ? _rocsmooth1.Result : _rocsmooth2.Result), inpPeriodSignal);
            _pmo = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            switch (inpPriceType)
            {
                case enumPriceTypes.Open:
                    _price[i] = Bars.OpenPrices[i];
                    break;
                case enumPriceTypes.Close:
                    _price[i] = Bars.ClosePrices[i];
                    break;
                case enumPriceTypes.High:
                    _price[i] = Bars.HighPrices[i];
                    break;
                case enumPriceTypes.Low:
                    _price[i] = Bars.LowPrices[i];
                    break;
                case enumPriceTypes.Median:
                    _price[i] = Bars.MedianPrices[i];
                    break;
                case enumPriceTypes.Typical:
                    _price[i] = Bars.TypicalPrices[i];
                    break;
                case enumPriceTypes.Weighted:
                    _price[i] = Bars.WeightedPrices[i];
                    break;
                default:
                    _price[i] = Bars.ClosePrices[i];
                    break;
            }
            
            outPMO[i] = (inpOutputResult == enumOutputResult.Fast ? _rocsmooth1.Result[i] : _rocsmooth2.Result[i]) / Symbol.PipSize;
            outSignal[i] = _pmosignal.Result[i] / Symbol.PipSize;
        }
    }

    public enum enumPriceTypes
    {
        Open,
        Close,
        High,
        Low,
        Median,
        Typical,
        Weighted
    }
    
    public enum enumOutputResult
    {
        Fast,
        Smooth
    }
}
mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Cloud("Shade", "Shade0", FirstColor = "Green", SecondColor = "Red", Opacity = 0.1)]
    [Indicator(AccessRights = AccessRights.None)]
    public class mMomentumAverage : Indicator
    {
        [Parameter("Momentum Period (21)", DefaultValue = 21)]
        public int inpPeriodMomentum { get; set; }
        [Parameter("Average Period (10)", DefaultValue = 10)]
        public int inpPeriodAvgerage { get; set; }
        [Parameter("Average Smooth Type (sma)", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType inpAverageSmoothType { get; set; }
        [Parameter("Level Period (10)", DefaultValue = 10)]
        public int inpPeriodLevel { get; set; }

        [Output("Momentum", LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outMom { get; set; }
        [Output("LevelUp", LineColor = "Green", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outMomLevelUp { get; set; }
        [Output("LevelDown", LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outMomLevelDown { get; set; }
        [Output("Shade", LineColor = "Transparent", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outShade { get; set; }
        [Output("Shade0", LineColor = "Transparent", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outShade0 { get; set; }
        
        private double _alpha;
        private MovingAverage _average;
        private MomentumOscillator _momentum;
        private IndicatorDataSeries _mom, _levelup, _leveldn;
        
        
        protected override void Initialize()
        {
            _alpha = 2.0 / (1.0 + inpPeriodLevel);
            _average = Indicators.MovingAverage(Bars.ClosePrices, inpPeriodAvgerage, inpAverageSmoothType);
            _momentum = Indicators.MomentumOscillator(_average.Result, inpPeriodMomentum);
            _mom = CreateDataSeries();
            _levelup = CreateDataSeries();
            _leveldn = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            _mom[i] = i>inpPeriodMomentum ? _momentum.Result[i] : 100;
            _levelup[i]  = i>inpPeriodMomentum ? (_mom[i] < _leveldn[i-1]) ? _levelup[i-1] : _levelup[i-1] + _alpha * (_mom[i] - _levelup[i-1]) : _mom[i];
            _leveldn[i]  = i>inpPeriodMomentum ? (_mom[i] > _levelup[i-1]) ? _leveldn[i-1] : _leveldn[i-1] + _alpha * (_mom[i] - _leveldn[i-1]) : _mom[i];
        
            outMom[i] = _mom[i];
            outMomLevelUp[i] = _levelup[i];
            outMomLevelDown[i] = _leveldn[i];
            outShade[i] = _mom[i] > _levelup[i] || _mom[i] < _leveldn[i] ? _mom[i] : 100.0;
            outShade0[i] = _mom[i] > _levelup[i] ? _levelup[i] : _mom[i] < _leveldn[i] ? _leveldn[i] : 100.0;
        }
    }
}
mfejza's avatar
mfejza · 1 year ago

Hi privateam000,

Thank you for your review and code revision. The LineBreak custom indicator is designed to track changes in price pressure. 

The trigger for a new bar level occurs when the price reaches a certain distance in pips from the last level, with the size of each brick defined as BrickSize (inpBlockSize). Essentially, this indicator employs a method to smooth price movements in terms of pips.

In this version, you have the flexibility to set BrickSize in pips as a custom number. This is a feature that is not permitted in RenkoBars. For example, you can use values like inpBrickSize: 7, 15, 30, 60, or 120.

I'm confident that there are no bugs within the code. However, if you're encountering a situation where the indicator results aren't being displayed due to processing resource constraints, I recommend freeing up memory.

In your previous versions of RenkoBars, a similar solution was employed, albeit with a distinct perspective and slight variations in the results.

The output value of the indicator, outRenkoNewLevel, represents the target level. For further information and cooperation, please don't hesitate to contact me on telegram.mfejza2

mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Cloud("Price", "Dynamic Balance Point", FirstColor = "Green", SecondColor = "Red", Opacity = 0.05)]  
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class mDynamicBalancePoint : Indicator
    {
        [Parameter("Periods (26)", DefaultValue = 26)]
        public int inpPeriods { get; set; }

        [Output("Dynamic Balance Point", LineColor = "Black", Thickness = 2)]
        public IndicatorDataSeries outDBP { get; set; }
        [Output("Price", LineColor = "Transparent", Thickness = 0)]
        public IndicatorDataSeries outPrice { get; set; }
        
        private IndicatorDataSeries _hh, _ll, _close, _dbp;
        

        protected override void Initialize()
        {
            _hh = CreateDataSeries();
            _ll = CreateDataSeries();
            _close = CreateDataSeries();
            _dbp = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            _hh[i] = Bars.HighPrices.Maximum(inpPeriods);
            _ll[i] = Bars.LowPrices.Minimum(inpPeriods);
            _close[i] = Bars.ClosePrices[i>0 ? i-1 : i];
            _dbp[i] = (_hh[i] + _ll[i] + _close[i]) / 3.0;
            
            outDBP[i] = _dbp[i];
            outPrice[i] = Bars.ClosePrices[i];
        }
    }
}
mfejza's avatar
mfejza · 1 year ago

Hi privateam000

Thank you for your review and code revision. The LineBreak custom indicator is designed to track changes in price pressure. 

The trigger for a new bar level occurs when the price reaches a certain distance in pips from the last level, with the size of each brick defined as BrickSize (inpBlockSize). Essentially, this indicator employs a method to smooth price movements in terms of pips.

In this version, you have the flexibility to set BrickSize in pips as a custom number. This is a feature that is not permitted in RenkoBars. For example, you can use values like inpBrickSize: 7, 15, 30, 60, or 120.

I'm confident that there are no bugs within the code. However, if you're encountering a situation where the indicator results aren't being displayed due to processing resource constraints, I recommend freeing up memory.

In your previous versions of RenkoBars, a similar solution was employed, albeit with a distinct perspective and slight variations in the results.

The output value of the indicator, outRenkoNewLevel, represents the target level. For further information and cooperation, please don't hesitate to contact me on telegram.mfejza2

mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(100)]
    [Indicator(AccessRights = AccessRights.None)]
    public class mVolumeNormalised : Indicator
    {
        [Parameter("Periods (14)", DefaultValue = 14)]
        public int inpPeriods { get; set; }
        [Parameter("Threshold (100)", DefaultValue = 100)]
        public double inpThreshold { get; set; }

        [Output("normalised volume",LineColor = "Gray", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outVolumeNorm { get; set; }
        [Output("normalised volume into volatility", LineColor = "#008000", PlotType = PlotType.Histogram, LineStyle = LineStyle.Solid, Thickness = 3)]
        public IndicatorDataSeries outVolumeNormVolatil { get; set; }
        [Output("normalised volume into range", LineColor = "#ff0000", PlotType = PlotType.Histogram, LineStyle = LineStyle.Solid, Thickness = 3)]
        public IndicatorDataSeries outVolumeNormRange { get; set; }  
        
        private MovingAverage _vsmooth;        
        private IndicatorDataSeries _volnorm;
        

        protected override void Initialize()
        {
            _vsmooth = Indicators.MovingAverage(Bars.TickVolumes, inpPeriods, MovingAverageType.Simple);
            _volnorm = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            _volnorm[i] = Bars.TickVolumes[i] / _vsmooth.Result[i] * 100;
            
            outVolumeNorm[i] = _volnorm[i];
            outVolumeNormVolatil[i] = _volnorm[i]>=100 ? _volnorm[i] : 0;
            outVolumeNormRange[i] = _volnorm[i]<100 ? _volnorm[i] : 0;
        }
    }
}
mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class mVolumePriceMomentum : Indicator
    {
        [Parameter("Periods (2)", DefaultValue = 2)]
        public int inpPeriods { get; set; }
        [Parameter("BB Period (200)", DefaultValue = 200, Group = "Bands")]
        public int inpPeriodBB { get; set; }
        [Parameter("BB Deviation (0.618)", DefaultValue = 0.618, Group = "Bands")]
        public double inpStddevBB { get; set; }
        [Parameter("BB Smooth Type (sma)", DefaultValue = MovingAverageType.Simple, Group = "Bands")]
        public MovingAverageType inpSmoothTypeBB { get; set; }

        [Output("Volume Price Momentum Oscillator", IsHistogram = false, LineColor = "Black", LineStyle = LineStyle.Solid, PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outVPMo { get; set; }
        [Output("Bands Up", LineColor = "LightBlue", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outBBup { get; set; }
        [Output("Bands Down", LineColor = "LightBlue", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outBBdn { get; set; }
        [Output("Bands Middle", LineColor = "LightBlue", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outBBmid { get; set; }
        
        private IndicatorDataSeries _vpm, _vpmo;
        private MovingAverage _vpmsmooth;
        private BollingerBands _bands;
        

        protected override void Initialize()
        {
            _vpmo = CreateDataSeries();
            _vpm = CreateDataSeries();
            _vpmsmooth = Indicators.MovingAverage(_vpm, inpPeriods, MovingAverageType.Exponential);
            _bands = Indicators.BollingerBands(_vpmsmooth.Result, inpPeriodBB, inpStddevBB, inpSmoothTypeBB);
        }

        public override void Calculate(int i)
        {
            _vpm[i] = Bars.TickVolumes[i] * (i>1 ? Bars.ClosePrices[i] - Bars.ClosePrices[i-1] : Bars.ClosePrices[i] - Bars.TypicalPrices[i]);
            _vpmo[i] = _vpmsmooth.Result[i];
            
            outVPMo[i] = _vpmo[i];
            outBBup[i] = _bands.Top[i];
            outBBdn[i] = _bands.Bottom[i];
            outBBmid[i] = _bands.Main[i];
        }
    }
}
mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Cloud("SenkouSpanA", "SenkouSpanB", FirstColor = "Green", SecondColor = "Red", Opacity = 0.1)]  
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class mVolumeIchimoku : Indicator
    {
        [Parameter("Period Fast (9)", DefaultValue = 9)]
        public int inpPeriodFast { get; set; }
        [Parameter("Period Medium (26)", DefaultValue = 26)]
        public int inpPeriodMedium { get; set; }
        [Parameter("Period Slow (26)", DefaultValue = 52)]
        public int inpPeriodSlow { get; set; }
        [Parameter("DisplacementChikou (26)", DefaultValue = 26)]
        public int inpDisplacementChikou { get; set; }
        [Parameter("DisplacementCloud (26)", DefaultValue = 26)]
        public int inpDisplacementCloud { get; set; }

        [Output("Volume", LineColor = "Black", Thickness = 2)]
        public IndicatorDataSeries outVolume { get; set; }
        [Output("TenkanSen", LineColor = "Red")]
        public IndicatorDataSeries outTenkanSen { get; set; }
        [Output("Kijunsen", LineColor = "Blue")]
        public IndicatorDataSeries outKijunSen { get; set; }
        [Output("ChikouSpan", LineColor = "DarkViolet")]
        public IndicatorDataSeries outChikouSpan { get; set; }
        [Output("SenkouSpanA", LineColor = "Green", LineStyle = LineStyle.Dots)]
        public IndicatorDataSeries outSenkouSpanA { get; set; }
        [Output("SenkouSpanB", LineColor = "Red", LineStyle = LineStyle.Dots)]
        public IndicatorDataSeries outSenkouSpanB { get; set; }

        private IndicatorDataSeries _tenkansen, _kijunsen, _senku;
        

        protected override void Initialize()
        {
            _tenkansen = CreateDataSeries();
            _kijunsen = CreateDataSeries();
            _senku = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            _tenkansen[i] = i>inpPeriodFast ? (Bars.TickVolumes.Maximum(inpPeriodFast) + Bars.TickVolumes.Minimum(inpPeriodFast)) / 2 : Bars.TickVolumes[i];
            _kijunsen[i] = i>inpPeriodMedium ? (Bars.TickVolumes.Maximum(inpPeriodMedium) + Bars.TickVolumes.Minimum(inpPeriodMedium)) / 2 : Bars.TickVolumes[i];
            _senku[i] = i>inpPeriodSlow ? (Bars.TickVolumes.Maximum(inpPeriodSlow) + Bars.TickVolumes.Minimum(inpPeriodSlow)) / 2 : Bars.TickVolumes[i];
            
            outVolume[i] = Bars.TickVolumes[i];
            outTenkanSen[i] = _tenkansen[i];
            outKijunSen[i] = _kijunsen[i];
            outChikouSpan[i-inpDisplacementChikou] = Bars.TickVolumes[i];
            outSenkouSpanA[i+inpDisplacementCloud] = (_tenkansen[i] + _kijunsen[i]) / 2;
            outSenkouSpanB[i+inpDisplacementCloud] = _senku[i] / 2;
        }
    }
}
mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None, TimeZone = TimeZones.UTC)]
    public class mMeanPrice : Indicator
    {
        [Output("Mean", LineColor = "Black", PlotType = PlotType.Points, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outMean { get; set; }
        [Output("Positive Mean", LineColor = "Green", PlotType = PlotType.Points, LineStyle = LineStyle.Solid, Thickness = 2)]
        public IndicatorDataSeries outMeanPositive { get; set; }
        [Output("Negative Mean", LineColor = "Red", PlotType = PlotType.Points, LineStyle = LineStyle.Solid, Thickness = 2)]
        public IndicatorDataSeries outMeanNegative { get; set; }
        [Output("LastPrice", LineColor = "FF68D0F7", PlotType = PlotType.Points, LineStyle = LineStyle.Dots, Thickness = 4)]
        public IndicatorDataSeries outLastPrice { get; set; }
        
        private Bars _barD1;
        private IndicatorDataSeries _price, _cnt, _lastprice;
        

        protected override void Initialize()
        {
            _price = CreateDataSeries();
            _cnt = CreateDataSeries();
            _lastprice = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            _barD1 = MarketData.GetBars(TimeFrame.Daily);
            var iD1 = _barD1.OpenTimes.GetIndexByTime(Bars.OpenTimes[i]);
            DateTimeOffset tradingStartTime = _barD1[iD1].OpenTime;
            var indexStart = Bars.OpenTimes.GetIndexByExactTime(tradingStartTime.DateTime);
            
            _price[i] = i == indexStart ? Bars.ClosePrices[i] : _price[i-1] + Bars.ClosePrices[i];
            _cnt[i] = i == indexStart ? 1 : _cnt[i-1] + 1;
            _lastprice[i] = i>1 && i == indexStart ? _price[i-1] / _cnt[i-1] : i>1 ? _lastprice[i-1] : Bars.ClosePrices[i];
            
            outMean[i] = _price[i] / _cnt[i];
            outLastPrice[i] = _lastprice[i];
            outMeanPositive[i] = Bars.ClosePrices[i] > _price[i] / _cnt[i] ?  _price[i] / _cnt[i] : double.NaN;
            outMeanNegative[i] = Bars.ClosePrices[i] < _price[i] / _cnt[i] ?  _price[i] / _cnt[i] : double.NaN;
        }
    }
}
mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(0, -7, +7)]
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class mSZO : Indicator
    {
        [Parameter("Period SZO (14)", DefaultValue = 14)]
        public int inpPeriodSZO { get; set; }
        [Parameter("Show Levels (yes)", DefaultValue = true)]
        public bool inpShowDLev { get; set; }
        [Parameter("Show Mid Level (yes)", DefaultValue = true)]
        public bool inpShowMidLev { get; set; }
        [Parameter("Period Levels  (30)", DefaultValue = 30)]
        public int inpPeriodLevels { get; set; }
        [Parameter("Percent Level (95.0)", DefaultValue = 95.0)]
        public double inpPercentLevel { get; set; }

        [Output("SZO", IsHistogram = false, LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outSZO { get; set; }
        [Output("Top", IsHistogram = false, LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outTop { get; set; }
        [Output("Bottom", IsHistogram = false, LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outBottom { get; set; }
        [Output("Middle", IsHistogram = false, LineColor = "Gray", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outMiddle { get; set; }

        private IndicatorDataSeries _score, _szo, _hhlvl, _lllvl, _range, _rangeproc;
        private ExponentialMovingAverage _smooth1, _smooth2, _smooth3;


        protected override void Initialize()
        {
            _score = CreateDataSeries();
            _szo = CreateDataSeries();
            _hhlvl = CreateDataSeries();
            _lllvl = CreateDataSeries();
            _range = CreateDataSeries();
            _rangeproc = CreateDataSeries();
            _smooth1 = Indicators.ExponentialMovingAverage(_score, inpPeriodSZO);
            _smooth2 = Indicators.ExponentialMovingAverage(_smooth1.Result, inpPeriodSZO);
            _smooth3 = Indicators.ExponentialMovingAverage(_smooth2.Result, inpPeriodSZO);
        }

        public override void Calculate(int i)
        {
            _score[i] = (i>1 && Bars.ClosePrices[i] > Bars.ClosePrices[i-1] ? +1 : -1);
            _szo[i] = 100.0 * ((3 * _smooth1.Result[i] - 3 * _smooth2.Result[i] + _smooth3.Result[i]) / inpPeriodSZO);
            _hhlvl[i] = _szo.Maximum(inpPeriodLevels);
            _lllvl[i] = _szo.Minimum(inpPeriodLevels);
            _range[i] = _hhlvl[i] - _lllvl[i];
            _rangeproc[i] = _range[i] * (inpPercentLevel / 100.0);

            outSZO[i] = _szo[i];
            outTop[i] = inpShowDLev ? _lllvl[i] + _rangeproc[i] : double.NaN;
            outBottom[i] = inpShowDLev ? _hhlvl[i] - _rangeproc[i] : double.NaN;
            outMiddle[i] = inpShowDLev && inpShowMidLev ? (_lllvl[i] + _rangeproc[i] + _hhlvl[i] - _rangeproc[i]) / 2 : double.NaN;
        }
    }
}
mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class mPNVIpol : Indicator
    {
        [Parameter("Period (5)", DefaultValue = 5)]
        public int inpPeriod { get; set; }

        [Output("Close", LineColor = "Black", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outPolarity { get; set; }
        
        private PositiveVolumeIndex _pvi;
        private NegativeVolumeIndex _nvi;
        private IndicatorDataSeries _result, _pos, _neg;
        

        protected override void Initialize()
        {
            _pvi = Indicators.PositiveVolumeIndex(Bars.ClosePrices);
            _nvi = Indicators.NegativeVolumeIndex(Bars.ClosePrices);
            _result = CreateDataSeries();
            _pos = CreateDataSeries();
            _neg = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            _result[i] = i>1 && _pvi.Result[i] >= _pvi.Result[i-1] 
                        ? Bars.LowPrices.Minimum(inpPeriod) - (Bars.HighPrices[i] - Bars.LowPrices[i])
                        : Bars.HighPrices.Maximum(inpPeriod) + (Bars.HighPrices[i] - Bars.LowPrices[i]);
                        
            _pos[i] = i>1 && _nvi.Result[i] >= _nvi.Result[i-1] 
                        ? Bars.LowPrices.Minimum(inpPeriod) - (Bars.HighPrices[i] - Bars.LowPrices[i])
                        : Bars.HighPrices.Maximum(inpPeriod) + (Bars.HighPrices[i] - Bars.LowPrices[i]);
                        
            _neg[i] = i>1 && _nvi.Result[i] >= _nvi.Result[i-1] 
                        ? Bars.HighPrices.Maximum(inpPeriod) + (Bars.HighPrices[i] - Bars.LowPrices[i])
                        : Bars.LowPrices.Minimum(inpPeriod) - (Bars.HighPrices[i] - Bars.LowPrices[i]);
                        
            outPolarity[i] = 
                          Bars.ClosePrices[i] > _result[i] && Bars.ClosePrices[i] > _pos[i] ? +1
                        : Bars.ClosePrices[i] < _result[i] && Bars.ClosePrices[i] < _neg[i] ? -1
                        : 0;
        }
    }
}
mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class mDPOgann : Indicator
    {
        [Parameter("Period (12)", DefaultValue = 12)]
        public int inpPeriod { get; set; }
        [Parameter("Smooth Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType inpSmoothType { get; set; }
        [Parameter("GHLA Range Period (10)", DefaultValue = 10, MinValue = 1)]
        public int inpRangePeriod { get; set; }

        [Output("DPO/Gann HiLo Activator", LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outGHLA { get; set; }
        [Output("DPO/Gann HiLo Activator Bullish", LineColor = "Green", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 2)]
        public IndicatorDataSeries outGHLAbull { get; set; }
        [Output("DPO/Gann HiLo Activator Bearish", LineColor = "Red", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Solid, Thickness = 2)]
        public IndicatorDataSeries outGHLAbear { get; set; }

        private IndicatorDataSeries _firc, _firh, _firl;
        private DetrendedPriceOscillator _dpoc, _dpoh, _dpol;
        private MovingAverage _ragehigh, _ragelow;
        private IndicatorDataSeries _trend, _ghla, _bull, _bear;


        protected override void Initialize()
        {
            _firc = CreateDataSeries();
            _firh = CreateDataSeries();
            _firl = CreateDataSeries();
            _dpoc = Indicators.DetrendedPriceOscillator(_firc, inpPeriod, inpSmoothType);
            _dpoh = Indicators.DetrendedPriceOscillator(_firh, inpPeriod, inpSmoothType);
            _dpol = Indicators.DetrendedPriceOscillator(_firl, inpPeriod, inpSmoothType);
            _ragehigh = Indicators.MovingAverage(_dpoh.Result, inpRangePeriod, MovingAverageType.Simple);
            _ragelow = Indicators.MovingAverage(_dpol.Result, inpRangePeriod, MovingAverageType.Simple);
            _ghla = CreateDataSeries();
            _trend = CreateDataSeries();
            _bull = CreateDataSeries();
            _bear = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            _firc[i] = i>3 ? (Bars.ClosePrices[i] + 2.0 * Bars.ClosePrices[i-1] + 2.0 * Bars.ClosePrices[i-2] + Bars.ClosePrices[i-3]) / 6.0 : Bars.ClosePrices[i];
            _firh[i] = i>3 ? (Bars.HighPrices[i] + 2.0 * Bars.HighPrices[i-1] + 2.0 * Bars.HighPrices[i-2] + Bars.HighPrices[i-3]) / 6.0 : Bars.HighPrices[i];
            _firl[i] = i>3 ? (Bars.LowPrices[i] + 2.0 * Bars.LowPrices[i-1] + 2.0 * Bars.LowPrices[i-2] + Bars.LowPrices[i-3]) / 6.0 : Bars.LowPrices[i];
            _trend[i] = _dpoc.Result[i] > _ragehigh.Result[i] ? +1 : _dpoc.Result[i] < _ragelow.Result[i] ? -1 : (i>1 ? _trend[i-1] : +1);
            _ghla[i] = _trend[i] < 0 ? _ragehigh.Result[i] : _ragelow.Result[i];
            _bull[i] = _trend[i] < 0 ? double.NaN : _ragelow.Result[i];
            _bear[i] = _trend[i] < 0 ? _ragehigh.Result[i] : double.NaN; 
            
            outGHLA[i] = _ghla[i] / Symbol.PipSize;
            outGHLAbull[i] = _bull[i] / Symbol.PipSize;
            outGHLAbear[i] = _bear[i] / Symbol.PipSize;
        }
    }
}
mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class mPFEb : Indicator
    {
        [Parameter("Fast ROC Period (1)", DefaultValue = 1)]
        public int inpFastROCperiod { get; set; }
        [Parameter("Slow ROC Period (9)", DefaultValue = 9)]
        public int inpSlowROCperiod { get; set; }
        [Parameter("Smooth Period (5)", DefaultValue = 5)]
        public int inpSmoothPeriod { get; set; }
        [Parameter("PDS (10)", DefaultValue = 10)]
        public int inpPDS { get; set; }
        [Parameter("Bands Periods (20)", DefaultValue = 20)]
        public int inpBandsPeriods { get; set; }
        [Parameter("Bands Deviation (1.618)", DefaultValue = 1.618)]
        public double inpBandsDeviation { get; set; }

        [Output("PFE", LineColor = "Black", LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outPFE { get; set; }
        [Output("BB Up", LineColor = "Green", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outBBup { get; set; }
        [Output("BB Mid", LineColor = "Gray", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outBBmid { get; set; }
        [Output("BB Down", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outBBdown { get; set; }
        
        private IndicatorDataSeries _rocfast, _rocslow, _polarizedefficiency, _raw, _scale;
        private BollingerBands _bbands;
        private MovingAverage _pfe;
        

        protected override void Initialize()
        {
            _rocfast = CreateDataSeries();
            _rocslow = CreateDataSeries();
            _polarizedefficiency = CreateDataSeries();
            _raw = CreateDataSeries();
            _bbands = Indicators.BollingerBands(Bars.ClosePrices, inpBandsPeriods, inpBandsDeviation, MovingAverageType.Simple);
            _pfe = Indicators.MovingAverage(_raw, inpSmoothPeriod, MovingAverageType.Exponential);
            _scale = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            _rocfast[i] = i>inpFastROCperiod 
                        ? (Bars.ClosePrices[i-inpFastROCperiod] != 0 ? 100.0 * (Bars.ClosePrices[i] / Bars.ClosePrices[i-inpFastROCperiod] - 1) : 0)
                        : (Bars.TypicalPrices[i] != 0 ? 100.0 * (Bars.ClosePrices[i] / Bars.TypicalPrices[i] - 1) : 0);
            _rocslow[i] = i>inpSlowROCperiod 
                        ? (Bars.ClosePrices[i-inpSlowROCperiod] != 0 ? 100.0 * (Bars.ClosePrices[i] / Bars.ClosePrices[i-inpSlowROCperiod] - 1) : 0)
                        : (Bars.TypicalPrices[i] != 0 ? 100.0 * (Bars.ClosePrices[i] / Bars.TypicalPrices[i] - 1) : 0);
            _polarizedefficiency[i] = Math.Sqrt(_rocslow[i] * _rocslow[i] + 100.0) / ((Math.Sqrt(_rocfast[i] * _rocfast[i] + 1.0) + inpPDS)!=0 ? Math.Sqrt(_rocfast[i] * _rocfast[i] + 1.0) + inpPDS : 1);
            _raw[i] = (Bars.ClosePrices[i] > (i>inpSlowROCperiod ? Bars.ClosePrices[i-inpSlowROCperiod] : Bars.TypicalPrices[i]) ? 100.0 * _polarizedefficiency[i] : -100.0 * _polarizedefficiency[i]);
            _scale[i] = (_bbands.Top[i] != _bbands.Bottom[i] ? 200.0/(_bbands.Top[i]-_bbands.Bottom[i]) : 0);

            outPFE[i] = (_scale[i] != 0 ? _bbands.Bottom[i] +(100.0 + _pfe.Result[i]) / _scale[i] : double.NaN); // _pfe.Result[i];
            outBBup[i] = _bbands.Top[i];
            outBBmid[i] = _bbands.Main[i];
            outBBdown[i] = _bbands.Bottom[i];
        }
    }
}
mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class mTrendScore : Indicator
    {
        [Parameter("Period (10)", DefaultValue = 10)]
        public int inpPeriod { get; set; }
        [Parameter("OverboughtOversold value (5)", DefaultValue = 5)]
        public double inpOverboughtOversold { get; set; }
        [Parameter("Price Method (close)", DefaultValue = enumPriceMethods.OpenClose)]
        public enumPriceMethods inpPriceMethod { get; set; }
        [Parameter("Use Period (yes)", DefaultValue = true)]
        public bool inpUsePeriod { get; set; }

        [Output("TrendScore", LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outTrendScore { get; set; }
        [Output("Overbought", LineColor = "red", PlotType = PlotType.Line, LineStyle = LineStyle.Dots, Thickness = 1)]
        public IndicatorDataSeries outOverbought { get; set; }
        [Output("Oversold", LineColor = "red", PlotType = PlotType.Line, LineStyle = LineStyle.Dots, Thickness = 1)]
        public IndicatorDataSeries outOversold { get; set; }
        
        private IndicatorDataSeries _score, _sum, _trendscore, _prevprice;


        protected override void Initialize()
        {
            _score = CreateDataSeries();
            _sum = CreateDataSeries();
            _trendscore = CreateDataSeries();
            _prevprice = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            _prevprice[i] = inpPriceMethod == enumPriceMethods.OpenClose ? Bars.OpenPrices[i] : (i>1 ? Bars.ClosePrices[i-1] : Bars.TypicalPrices[i]);
            _score[i] = Bars.ClosePrices[i] > _prevprice[i] ? +1 : Bars.ClosePrices[i] < _prevprice[i] ? -1 : 0;
            if(inpUsePeriod == true)
                _trendscore[i] = _score.Sum(inpPeriod);
            else
            {
                if(Bars.ClosePrices[i] > _prevprice[i])
                    _trendscore[i] = (_trendscore[i-1] >= 0 && i>1 ? _trendscore[i-1] + 1 : 1);
                else 
                    if(Bars.ClosePrices[i] < _prevprice[i])
                        _trendscore[i] = (_trendscore[i-1] < 0 && i>1 ? _trendscore[i-1] - 1 : -1);
                    else
                        _trendscore[i] = i>1 ? _trendscore[i-1] : 0;
            }
            
            outTrendScore[i] = _trendscore[i];
            outOverbought[i+100] = inpOverboughtOversold;
            outOversold[i+100] = -inpOverboughtOversold;
        }
    }
    public enum enumPriceMethods
    {
        OpenClose,
        CloseClose
    }
}
mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class mWSI : Indicator
    {
        [Parameter("CCI Period (100)", DefaultValue = 100, MinValue = 2)]
        public int inpPeriodCCI { get; set; }
        [Parameter("DMS Period (100)", DefaultValue = 100, MinValue = 2)]
        public int inpPeriodDMS { get; set; }

        [Output("WSI - Wave Segregation Index", PlotType = PlotType.Line, LineColor = "Black", Thickness = 3)]
        public IndicatorDataSeries outWSI { get; set; }
        [Output("Up Bullish", PlotType = PlotType.Histogram, LineColor = "ForestGreen", Thickness = 3)]
        public IndicatorDataSeries outStrongBullish { get; set; }
        [Output("Down Bullish", PlotType = PlotType.Histogram, LineColor = "LawnGreen", Thickness = 3)]
        public IndicatorDataSeries outWeakBullish { get; set; }
        [Output("Down Bearish", PlotType = PlotType.Histogram, LineColor = "Red", Thickness = 3)]
        public IndicatorDataSeries outStrongBearish { get; set; }
        [Output("Up Bearish", PlotType = PlotType.Histogram, LineColor = "DarkSalmon", Thickness = 3)]
        public IndicatorDataSeries outWeakBearish { get; set; }
        
        private CommodityChannelIndex _cci;
        private DirectionalMovementSystem _dms;
        private IndicatorDataSeries _wsi;
        

        protected override void Initialize()
        {
            _cci = Indicators.CommodityChannelIndex(inpPeriodCCI);
            _dms = Indicators.DirectionalMovementSystem(20);
            _wsi = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            _wsi[i] = (_cci.Result[i] * _dms.ADX[i] * Bars.TypicalPrices[i]) * Symbol.PipSize;
            
            outWSI[i] = _wsi[i];
            outStrongBullish[i] = _wsi[i] > 0 && _wsi[i] > _wsi[i-1] ? _wsi[i] : double.NaN;
            outWeakBullish[i] = _wsi[i] > 0 && _wsi[i] <= _wsi[i-1] ? _wsi[i] : double.NaN;
            outStrongBearish[i] = _wsi[i] < 0 && _wsi[i] < _wsi[i-1] ? _wsi[i] : double.NaN;
            outWeakBearish[i] = _wsi[i] < 0 && _wsi[i] >= _wsi[i-1] ? _wsi[i] : double.NaN;
        }
    }
}
mfejza's avatar
mfejza · 1 year ago

for unknown some reasons I can not upload source code of indicator. please get it from comnet content

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class mJSmoothMA : Indicator
    {
        [Parameter("Periods (20)", DefaultValue = 20)]
        public int inpPeriod { get; set; }

        [Output("MarkJuric Smooth MovingAverage", LineColor = "Orange", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 2)]
        public IndicatorDataSeries outJSMA { get; set; }
        
        private double alpha, alpha1, alpha2;
        private IndicatorDataSeries _a1, _a2, _a3, _a4, _jsma;
        

        protected override void Initialize()
        {
            alpha = 0.45 * (inpPeriod - 1) / (0.45 * (inpPeriod - 1) + 2);
            alpha1 = alpha * alpha;
            alpha2 = (1 - alpha) * (1 - alpha);
            _a1 = CreateDataSeries();
            _a2 = CreateDataSeries();
            _a3 = CreateDataSeries();
            _a4 = CreateDataSeries();
            _jsma = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            _a1[i] = (1 - alpha) * Bars.ClosePrices[i] + alpha * (i>1 ? _a1[i-1] : 0);
            _a2[i] = (1 - alpha) * (Bars.ClosePrices[i] - _a1[i]) + alpha * (i>1 ? _a2[i-1] : 0);
            _a3[i] = _a1[i] + _a2[i];
            _a4[i] = (_a3[i] - (i>1 ? _jsma[i-1] : Bars.ClosePrices[i])) * alpha2 + alpha1 * (i>1 ? _a4[i-1] : 0);
            _jsma[i] = (i>1 ? _jsma[i-1] : Bars.ClosePrices[i]) + _a4[i];
            
            outJSMA[i] = _jsma[i];
        }
    }
}
mfejza's avatar
mfejza · 1 year ago

thanks to ctrader.guru and Jim Tollan for revision the indicator output results. 

we should create a close community to cooperate close for finding solutions together.

if any of you has any idea please let me know 

mfejza's avatar
mfejza · 1 year ago

anybody, please block this spawner, and delete his comments

https://ctrader.com/users/profile/84471

mfejza's avatar
mfejza · 1 year ago

Dear alexsanramon & nicolejohnston668

To show the difference between Continual VWAP and SMA you have the indicator as in link 
Hope this costum indicator complete your suspicion

https://ctrader.com/algos/indicators/show/3315

mfejza's avatar
mfejza · 1 year ago

please anybody block this account (nguyenphongotjtiqatabto43): https://ctrader.com/users/profile/82116

mfejza's avatar
mfejza · 1 year ago

@codefinger

mate, you are trying to replace smoothing ATR result, from MovingAverrage to CCI, and you can not, because CCI is calculated from 4 array components (bars data: open, high, low, close); ATR indicator return only a array of data

mfejza's avatar
mfejza · 1 year ago

you can download the expression converted to indicator: https://ctrader.com/algos/indicators/show/3260

mfejza's avatar
mfejza · 1 year ago

get SwingArm ATR Trend Indicator: https://ctrader.com/algos/indicators/show/3229

mfejza's avatar
mfejza · 2 years ago

change rows 38 and 40, for full functionality

            FastMa = Indicators.MovingAverage(Bars.ClosePrices, fastPeriod, MaType);
             
            SlowMa = Indicators.MovingAverage(Bars.ClosePrices, slowPeriod, MaType);