Fisher producing diffrent results

Created at 21 May 2013, 16:12
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
ER

ErikD

Joined 22.04.2013

Fisher producing diffrent results
21 May 2013, 16:12


Hi!

I really like the Fiher that the user atrade did, problem is thou that it produces diffrent results depending on how long it has been attached to the chart

http://spotware.ctrader.com/c/tSM5n

A
nyone got a solution?

 

Code:

using System;
using cAlgo.API;

namespace cAlgo.Indicators
{
    [Indicator("Fisher")]
    public class Fisher : Indicator
    {
        private double _maxH;
        private double _minL;
        private bool _up = true;
        private double _current;
        private double _prev;
        private double _price;
        private double _value1;
        private double _fish1;

        [Output("Buffer0", PlotType = PlotType.Histogram, Color = Colors.Red)]
        public IndicatorDataSeries Buffer0 { get; set; }

        [Output("Buffer1", PlotType = PlotType.Histogram, Color = Colors.Green)]
        public IndicatorDataSeries Buffer1 { get; set; }

        [Output("Buffer2", PlotType = PlotType.Histogram, Color = Colors.Red)]
        public IndicatorDataSeries Buffer2 { get; set; }

        [Parameter("Period", DefaultValue = 10)]
        public int Period { get; set; }

        public override void Calculate(int index)
        {                      
            if(index < Period)
            {
                Buffer0[index] = 0;
                Buffer1[index] = 0;
                Buffer2[index] = 0;

                return;
            }

            //High[Highest(NULL, 0, MODE_HIGH, period, i)];
            _maxH = MarketSeries.High.Maximum(Period);
            //Low[Lowest(NULL, 0, MODE_LOW, period, i)];
            _minL = MarketSeries.Low.Minimum(Period);
            _price = (MarketSeries.High[index] + MarketSeries.Low[index]) / 2;
            
            double value = 0.33*2*((_price - _minL)/(_maxH - _minL) - 0.5) + 0.67*_value1;
            value = Math.Min(Math.Max(value, -0.999), 0.999);
            
            Buffer0[index] = 0.5 * Math.Log((1 + value) / (1 - value)) + 0.5 * _fish1;
            _value1 = value;
            _fish1 = Buffer0[index];

            _current = Buffer0[index];
            _prev = Buffer0[index-1];

            if (((_current < 0) && (_prev > 0)) || (_current < 0)) _up = false;
            if (((_current > 0) && (_prev < 0)) || (_current > 0)) _up = true;

            if (!_up)
            {
                Buffer2[index] = _current;
                Buffer1[index] = 0.0;
            }
            else
            {
                Buffer1[index] = _current;
                Buffer2[index] = 0.0;
            }
        }
    }
}




@ErikD
Replies

atrader
22 May 2013, 17:29

Hi, I posted a new code file. Download it again. The problem were the variables fish1 and value1. I modified it to use IndicatorDataSeries instead of double, because the method is called on each Tick so there are different values for those for the same Bar. Anyway, now it produces the correct results. 


@atrader

ErikD
22 May 2013, 19:55

RE:
atrader said:

Hi, I posted a new code file. Download it again. The problem were the variables fish1 and value1. I modified it to use IndicatorDataSeries instead of double, because the method is called on each Tick so there are different values for those for the same Bar. Anyway, now it produces the correct results. 

Big thanks both for the support and for the development of the indicators!


@ErikD