Help with Fisher Indicator

Created at 01 Aug 2013, 22:54
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!
GA

Garcho

Joined 24.07.2013

Help with Fisher Indicator
01 Aug 2013, 22:54


Hello, 

I don´t understand why the results form the Fisher cAlgo indicator are so different from the MT4 Fisher indicator. As you can se in the pictures the result for the same period in the cAlgo indicator is 0.56 and in the MT4 indicator is 0.27. Can somebody help me in finding the difference? Please see attached a screenshot of the indicators and the cAlgo code (/algos/indicators/show/213) and MT4 code. 

FROM: /algos/indicators/show/213

using System;
using cAlgo.API;

namespace cAlgo.Indicators
{
    [Indicator("Fisher")]
    public class Fisher : Indicator
    {
        private IndicatorDataSeries _value1;
        private IndicatorDataSeries _buffer0;
        private IndicatorDataSeries _fisher1;

        [Parameter("Period", DefaultValue = 10)]
        public int Period { 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; }


        protected override void Initialize()
        {
            _fisher1 = CreateDataSeries();
            _value1 = CreateDataSeries();
            _buffer0 = CreateDataSeries();
        }

        public override void Calculate(int index)
        {
            if (index < Period)
            {
                _value1[index] = 0;
                _fisher1[index] = 0;

                return;
            }

            double maxH = MarketSeries.High.Maximum(Period);
            double minL = MarketSeries.Low.Minimum(Period);

            double price = (MarketSeries.High[index] + MarketSeries.Low[index])/2;

            double value = 0.33*2*((price - minL)/(maxH - minL) - 0.5) + 0.67*_value1[index - 1];
            value = Math.Min(Math.Max(value, -0.999), 0.999);

            _buffer0[index] = 0.5*Math.Log((1 + value)/(1 - value)) + 0.5*_fisher1[index - 1];

            _value1[index] = value;
            _fisher1[index] = _buffer0[index];

            bool up = _buffer0[index] > 0;

            if (!up)
            {
                Buffer2[index] = _buffer0[index];
                Buffer1[index] = 0.0;
            }
            else
            {
                Buffer1[index] = _buffer0[index];
                Buffer2[index] = 0.0;
            }
        }
    }
}
FROM MT4: 
#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  Blue
#property  indicator_color2  Lime
#property  indicator_color3  Red
#property indicator_level1 -0.30
#property indicator_level2 0.30

extern int period=10;
extern int bars_count=1000;

double         ExtBuffer0[];
double         ExtBuffer1[];
double         ExtBuffer2[];


int init()
  {
   
   
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   //IndicatorDigits(Digits+1);

   SetIndexBuffer(0,ExtBuffer0);
   SetIndexBuffer(1,ExtBuffer1);
   SetIndexBuffer(2,ExtBuffer2);

   IndicatorShortName("Fisher");
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);

   return(0);
  }


int start()
  {
   //int     period=10;
   int    limit;
   int    counted_bars=IndicatorCounted();
   double prev,current,old;
   double Value=0,Value1=0,Value2=0,Fish=0,Fish1=0,Fish2=0;
   double price;
   double MinL=0;
   double MaxH=0;  
   

   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;


   for(int i=0; i<limit; i++)
    {  MaxH = High[Highest(NULL,0,MODE_HIGH,period,i)];
       MinL = Low[Lowest(NULL,0,MODE_LOW,period,i)];
      price = (High[i]+Low[i])/2;
      Value = 0.33*2*((price-MinL)/(MaxH-MinL)-0.5) + 0.67*Value1;     
      Value=MathMin(MathMax(Value,-0.999),0.999); 
      ExtBuffer0[i]=0.5*MathLog((1+Value)/(1-Value))+0.5*Fish1;
      Value1=Value;
      Fish1=ExtBuffer0[i];
      
    }


   bool up=true;
   for(i=limit-2; i>=0; i--)
     {
      current=ExtBuffer0[i];
      prev=ExtBuffer0[i+1];
           
      if (((current<0)&&(prev>0))||(current<0))   up= false;    
      if (((current>0)&&(prev<0))||(current>0))   up= true;
      
      if(!up)
        {
         ExtBuffer2[i]=current;
         ExtBuffer1[i]=0.0;
        }
        
       else
         {
          ExtBuffer1[i]=current;
          ExtBuffer2[i]=0.0;
         }
     }

   return(0);
  }




 

 

 


@Garcho
Replies

algotrader
02 Aug 2013, 09:06

You can convert your MQ4 indicator with 2calgo.com. Please tell if results will be different.


@algotrader

Garcho
02 Aug 2013, 23:59

Thanks!! I will try it and let you know... bests


@Garcho

Garcho
07 Aug 2013, 00:08

Hello, 

I was able to convert the indicator but some how I am not able to use it in backtesting. When I try to print the indicator in the backtesting log it says NaN, if I use the indicator on a demo account it works fine. For example, the following code works fine on a demo account but does not prints values of the indicator in the backtesting log, how can I make the indicator usable for backtesting?

//#reference: C:\Users\Luis Garcia\Documents\cAlgo\Sources\Indicators\_Fisher Automatico.algo

using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Requests;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC)]
    public class _Ensayos : Robot
    {
    
    private ConvertedIndicator Fisher10;
  
        protected override void OnStart()
        {
              Fisher10 = Indicators.GetIndicator<ConvertedIndicator>(10,1000);
         }

        protected override void OnBar()
        {

            if (Fisher10.ExtBuffer1_AlgoOutputDataSeries.LastValue > 0)
            {
            Trade.CreateBuyMarketOrder(Symbol,10000);
            }
            else
            {
            Trade.CreateSellMarketOrder(Symbol,10000);
            }
        }

n the code): 


@Garcho

algotrader
07 Aug 2013, 08:59

Thank you for issue report. I will investigate this issue.


@algotrader

algotrader
07 Aug 2013, 13:54

Problem is fixed, please reconverted your indicator


@algotrader

Garcho
08 Aug 2013, 18:29

It worked, thanks for your help


@Garcho