stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

cTrader - Help to build TMA Slope for cTrader/cAlgo
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=2426
Page 2 of 2
Author:  babalu4u [ Tue Jun 04, 2013 9:07 pm ]
Post subject:  Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

Thanks for help I think now its working 1. litle step is done... :D

Code: Select all

 //#reference: C:\Users\ToTo\Documents\cAlgo\Sources\Indicators\AverageTrueRange.algo
    // -------------------------------------------------------------------------------
    //
    //    This is a Template used as a guideline to build your own Robot.
    //    Please use the “Feedback” tab to provide us with your suggestions about cAlgo’s API.
    //
    // -------------------------------------------------------------------------------

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

    namespace cAlgo.Indicators
    {
        [Indicator(IsOverlay = false)]
        public class TMASlope : Indicator
        {
          private AverageTrueRange _averageTrueRange;
          private TriangularMovingAverage _triangularMovingAverage;
          
            [Parameter(DefaultValue = 0.0)]
            public double Parameter { get; set; }

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


            protected override void Initialize()
            {
                _triangularMovingAverage = Indicators.TriangularMovingAverage(MarketSeries.Close, 21);
                _averageTrueRange = Indicators.GetIndicator<AverageTrueRange>(100);
            }
           
          double calcPrevTrue( int index )
          {
             double dblSum  = MarketSeries.Close[ index - 1] * 21;
                double dblSumw = 21;
                int jnx, knx;
       
                dblSum  += MarketSeries.Close[ index ] * 20;
                dblSumw += 20;

                for ( jnx = 1, knx = 20; jnx <= 20; jnx++, knx-- )
                {
                   dblSum  += MarketSeries.Close[index - 1 - jnx ] * knx;
                   dblSumw += knx;
                }
             return ( dblSum / dblSumw );
          }


            public override void Calculate(int index)
            {
                double dblTma, dblPrev;
                double atr =_averageTrueRange.Result[index - 10] / 10;
                double gadblSlope = 0.0;

                if ( atr != 0 )
                {
                   dblTma = _triangularMovingAverage.Result[index];
                   dblPrev = calcPrevTrue( index );
                   gadblSlope = ( dblTma - dblPrev ) / atr;
                }
                Result[index] = gadblSlope ;
            }
        }
    }
Author:  scheinwerfer [ Tue Jun 04, 2013 9:19 pm ]
Post subject:  Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

That's great! Can you compare it to MT values, is it similar or way off?
Author:  babalu4u [ Tue Jun 04, 2013 9:24 pm ]
Post subject:  Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

Code: Select all

//#reference: C:\Users\ToTo\Documents\cAlgo\Sources\Indicators\AverageTrueRange.algo
    // -------------------------------------------------------------------------------
    //
    //    This is a Template used as a guideline to build your own Robot.
    //    Please use the “Feedback” tab to provide us with your suggestions about cAlgo’s API.
    //
    // -------------------------------------------------------------------------------

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

    namespace cAlgo.Indicators
    {
        [Indicator(IsOverlay = false)]
        public class TMASlope : Indicator
        {
          private AverageTrueRange _averageTrueRange;
          private TriangularMovingAverage _triangularMovingAverage;
          
            [Parameter(DefaultValue = 0.0)]
            public double Parameter { get; set; }

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


            protected override void Initialize()
            {
                _triangularMovingAverage = Indicators.TriangularMovingAverage(MarketSeries.Close, 21);
                _averageTrueRange = Indicators.GetIndicator<AverageTrueRange>(100);
            }
           
          double calcPrevTrue( int index )
          {
             double dblSum  = MarketSeries.Close[ index - 1] * 21;
                double dblSumw = 21;
                int jnx, knx;
       
                dblSum  -= MarketSeries.Close[ index ] * 20;
                dblSumw -= 20;

                for ( jnx = 1, knx = 20; jnx <= 20; jnx++, knx-- )
                {
                   dblSum  -= MarketSeries.Close[index - 1 - jnx ] * knx;
                   dblSumw -= knx;
                }
             return ( dblSum / dblSumw );
          }


            public override void Calculate(int index)
            {
                double dblTma, dblPrev;
                double atr =_averageTrueRange.Result[index - 10] / 10;
                double gadblSlope = 0.0;

                if ( atr != 0 )
                {
                   dblTma = _triangularMovingAverage.Result[index];
                   dblPrev = calcPrevTrue( index );
                   gadblSlope = ( dblPrev - dblTma ) / atr;
                }
                Result[index] = gadblSlope ;
            }
        }
    }
Author:  babalu4u [ Tue Jun 04, 2013 9:37 pm ]
Post subject:  Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

now will look
Author:  babalu4u [ Tue Jun 04, 2013 9:40 pm ]
Post subject:  Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

or this
Author:  scheinwerfer [ Tue Jun 04, 2013 9:50 pm ]
Post subject:  Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

Doesn't look right. The values at some places are too big, reads more than 10. I had the same sh**.

One other thing which got me thinking - TMA from cT and TMAtrue are not equal, most probably. That's food for thought for now.
Author:  babalu4u [ Tue Jun 04, 2013 10:06 pm ]
Post subject:  Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

I will tray with lwma for tmaTrue...
Author:  babalu4u [ Wed Jun 05, 2013 6:55 am ]
Post subject:  Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

OK... now TMA Slope is calculating RIGHT..... YES my first cAlgo indicator and my first C# experience....
Its not to hard to migrate from Empty4 to cTrader/cAlgo..... now I must add a little lipstick to indy and than next project : First EA for cAlgo.... :mrgreen:

Code: Select all

 //#reference: C:\Users\ToTo\Documents\cAlgo\Sources\Indicators\AverageTrueRange.algo
    // -------------------------------------------------------------------------------
    //
    //    This is a Template used as a guideline to build your own Robot.
    //    Please use the “Feedback” tab to provide us with your suggestions about cAlgo’s API.
    //
    // -------------------------------------------------------------------------------

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

    namespace cAlgo.Indicators
    {
        [Indicator(IsOverlay = false)]
        public class TMASlope_11 : Indicator
        {
          private AverageTrueRange _averageTrueRange;
          private WeightedMovingAverage _weightedMovingAverage;
          
            [Parameter(DefaultValue = 0.0)]
            public double Parameter { get; set; }

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


            protected override void Initialize()
            {
                _weightedMovingAverage = Indicators.WeightedMovingAverage(MarketSeries.Close, 21);
                _averageTrueRange = Indicators.GetIndicator<AverageTrueRange>(100);
            }
           
          double calcPrevTrue( int index )
          {
             double dblSum  = MarketSeries.Close[ index - 1] * 21;
                double dblSumw = 21;
                int jnx, knx;
       
                dblSum  += MarketSeries.Close[ index ] * 20;
                dblSumw += 20;

                for ( jnx = 1, knx = 20; jnx <= 20; jnx++, knx-- )
                {
                   dblSum  += MarketSeries.Close[index - 1 - jnx ] * knx;
                   dblSumw += knx;
                }
             return ( dblSum / dblSumw );
          }


            public override void Calculate(int index)
            {
                double dblTma, dblPrev;
                double atr =_averageTrueRange.Result[index - 10] / 10;
                double gadblSlope = 0.0;

                if ( atr != 0 )
                {
                   dblTma =_weightedMovingAverage.Result[index];
                   dblPrev = calcPrevTrue( index );
                   gadblSlope = ( dblTma-dblPrev ) / atr;
                }
                Result[index] = gadblSlope ;
            }
        }
    }
Author:  scheinwerfer [ Wed Jun 05, 2013 10:00 am ]
Post subject:  Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

Good job! Your success makes me enthusiastic, I'll try to port it to another platform once more, too.
Author:  babalu4u [ Wed Jun 05, 2013 9:45 pm ]
Post subject:  Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

Last version is here:
http://www.stevehopwoodforex.com/phpBB3 ... =67&t=2448
All times are UTC Page 2 of 2