Category Oscilators  Published on 04/07/2023

RVI Neural Network indicator

Description

This custom indicator is a part of project NeuroRVI .

This is a custom indicator created by/for NeuroRVI cBot that generates results using the Relative Vigor Index (RVI) indicator and customized input parameters specific to a particular financial instrument and timeframe. It leverages neural network weights to optimize its functionality.

It is essential to customize this indicator further by adjusting the weights as input parameters to generate reliable trade signals.

The indicator produces bullish sentiment when the results are above zero and bearish sentiment when they are below zero.

Please note that this indicator is part of an experimental project called NeuroRVI.

To compile and utilize this indicator, you will need to acquire the RVI indicator from the provided link.


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

namespace cAlgo
{
    [Levels(0)]
    [Indicator(AccessRights = AccessRights.None)]
    public class mNeuroRVI : Indicator
    {
        [Parameter("RVI Period (10)", DefaultValue = 10)]
        public int inpPeriodsRVI { get; set; }
        [Parameter("Weight 0", DefaultValue = 1.0)] 
        public double inpWeight0 { get; set; }
        [Parameter("Weight 1", DefaultValue = 0.1)] 
        public double inpWeight1 { get; set; }
        [Parameter("Weight 2", DefaultValue = -0.8)] 
        public double inpWeight2 { get; set; }
        [Parameter("Weight 3", DefaultValue = -0.5)] 
        public double inpWeight3 { get; set; }
        [Parameter("Weight 4", DefaultValue = -0.7)] 
        public double inpWeight4 { get; set; }
        [Parameter("Weight 5", DefaultValue = -0.4)] 
        public double inpWeight5 { get; set; }
        [Parameter("Weight 6", DefaultValue = -0.6)] 
        public double inpWeight6 { get; set; }
        [Parameter("Weight 7", DefaultValue = -0.4)] 
        public double inpWeight7 { get; set; }
        [Parameter("Weight 8", DefaultValue = 0.9)] 
        public double inpWeight8 { get; set; }
        [Parameter("Weight 9", DefaultValue = 0.5)] 
        public double inpWeight9 { get; set; }
        [Parameter("Weight 10", DefaultValue = 1.0)] 
        public double inpWeight10 { get; set; }
        [Parameter("Weight 11", DefaultValue = 0.1)] 
        public double inpWeight11 { get; set; }
        [Parameter("Weight 12", DefaultValue = -0.8)] 
        public double inpWeight12 { get; set; }
        [Parameter("Weight 13", DefaultValue = -0.5)] 
        public double inpWeight13 { get; set; }
        [Parameter("Weight 14", DefaultValue = -0.7)] 
        public double inpWeight14 { get; set; }
        [Parameter("Weight 15", DefaultValue = -0.4)] 
        public double inpWeight15 { get; set; }
        [Parameter("Weight 16", DefaultValue = -0.6)] 
        public double inpWeight16 { get; set; }
        [Parameter("Weight 17", DefaultValue = -0.4)] 
        public double inpWeight17 { get; set; }
        [Parameter("Weight 18", DefaultValue = 0.9)] 
        public double inpWeight18 { get; set; }
        [Parameter("Weight 19", DefaultValue = 0.5)] 
        public double inpWeight19 { get; set; }

        [Output("outTrade", LineColor = "Black", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outTrade { get; set; }
        
        private mRVI _rvi;
        private strNeuroInputs[] _neuroinputs = new strNeuroInputs[20];
        private double _d1, _d2, _rvimin, _rvimax, _outneuron;
        
        protected override void Initialize()
        {
            _neuroinputs[0].weight = inpWeight0;
            _neuroinputs[1].weight = inpWeight1;
            _neuroinputs[2].weight = inpWeight2;
            _neuroinputs[3].weight = inpWeight3;
            _neuroinputs[4].weight = inpWeight4;
            _neuroinputs[5].weight = inpWeight5;
            _neuroinputs[6].weight = inpWeight6;
            _neuroinputs[7].weight = inpWeight7;
            _neuroinputs[8].weight = inpWeight8;
            _neuroinputs[9].weight = inpWeight9;
            _neuroinputs[10].weight = inpWeight10;
            _neuroinputs[11].weight = inpWeight11;
            _neuroinputs[12].weight = inpWeight12;
            _neuroinputs[13].weight = inpWeight13;
            _neuroinputs[14].weight = inpWeight14;
            _neuroinputs[15].weight = inpWeight15;
            _neuroinputs[16].weight = inpWeight16;
            _neuroinputs[17].weight = inpWeight17;
            _neuroinputs[18].weight = inpWeight18;
            _neuroinputs[19].weight = inpWeight19;
            _rvi = Indicators.GetIndicator<mRVI>(inpPeriodsRVI);
        }

        public override void Calculate(int i)
        {
            _d1 = -1.0; //lower limit of the normalization range
            _d2 = +1.0; //upper limit of the normalization range
            _rvimin = Math.Min(_rvi.outRVIMain.Minimum(20), _rvi.outRVISignal.Minimum(20));
            _rvimax = Math.Max(_rvi.outRVIMain.Maximum(20), _rvi.outRVISignal.Maximum(20));

            if (_rvi.outRVIMain.Count < 10)
                return;

            for (int j = 0; j < 20 / 2; j++)
            {
                _neuroinputs[j * 2].inputs = (((_rvi.outRVIMain.Last(j) - _rvimin) * (_d2 - _d1)) / (_rvimax - _rvimin)) + _d1;
                _neuroinputs[j * 2 + 1].inputs = (((_rvi.outRVISignal.Last(j) - _rvimin) * (_d2 - _d1)) / (_rvimax - _rvimin)) + _d1;
            }

            _outneuron = CalculateNeuron(); //neural network logic
            bool _rvibullishlogic = _rvi.outRVIMain.LastValue > 0 && _rvi.outRVIMain.LastValue > _rvi.outRVISignal.LastValue;
            bool _rvibearishlogic = _rvi.outRVIMain.LastValue < 0 && _rvi.outRVIMain.LastValue < _rvi.outRVISignal.LastValue;

            //if(_outneuron < -0 && _rvibullishlogic)
            //if(_outneuron > -0 && _rvibearishlogic)           
            outTrade[i] = _outneuron < 0 ? +1 : _outneuron >= 0 ? -1 : 0;
        }
        
        
        private double CalculateNeuron()
        {
            double neuron = 0.0;
            for (int n = 0; n < 20; n++)
                neuron += _neuroinputs[n].inputs * _neuroinputs[n].weight;
            neuron *= 0.1; //--- multiply the weighted sum of inputs by the additional coefficient
            return (ActivateNeuron(neuron));
        }

        private double ActivateNeuron(double x)
        {
            return (Math.Exp(x) - Math.Exp(-x)) / (Math.Exp(x) + Math.Exp(-x)); //--- return the activation function value
        }
        
        private struct strNeuroInputs
        {
            public double weight;
            public double inputs;
        }
    }
}

mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mNeuroRVI.algo
  • Rating: 0
  • Installs: 617
  • Modified: 03/07/2023 11:24
Comments
Log in to add a comment.
No comments found.