cTrader - Help to build TMA Slope for cTrader/cAlgo

User avatar
babalu4u
Trader
Posts: 173
Joined: Fri Apr 13, 2012 6:52 pm
Location: Slovenia - EU

Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

Post by babalu4u »

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 ;
            }
        }
    }
You do not have the required permissions to view the files attached to this post.
scheinwerfer
Trader
Posts: 42
Joined: Mon Dec 12, 2011 12:36 am

Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

Post by scheinwerfer »

That's great! Can you compare it to MT values, is it similar or way off?
User avatar
babalu4u
Trader
Posts: 173
Joined: Fri Apr 13, 2012 6:52 pm
Location: Slovenia - EU

Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

Post by babalu4u »

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 ;
            }
        }
    }
You do not have the required permissions to view the files attached to this post.
User avatar
babalu4u
Trader
Posts: 173
Joined: Fri Apr 13, 2012 6:52 pm
Location: Slovenia - EU

Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

Post by babalu4u »

now will look
You do not have the required permissions to view the files attached to this post.
User avatar
babalu4u
Trader
Posts: 173
Joined: Fri Apr 13, 2012 6:52 pm
Location: Slovenia - EU

Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

Post by babalu4u »

or this
You do not have the required permissions to view the files attached to this post.
scheinwerfer
Trader
Posts: 42
Joined: Mon Dec 12, 2011 12:36 am

Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

Post by scheinwerfer »

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.
User avatar
babalu4u
Trader
Posts: 173
Joined: Fri Apr 13, 2012 6:52 pm
Location: Slovenia - EU

Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

Post by babalu4u »

I will tray with lwma for tmaTrue...
User avatar
babalu4u
Trader
Posts: 173
Joined: Fri Apr 13, 2012 6:52 pm
Location: Slovenia - EU

Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

Post by babalu4u »

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 ;
            }
        }
    }
You do not have the required permissions to view the files attached to this post.
scheinwerfer
Trader
Posts: 42
Joined: Mon Dec 12, 2011 12:36 am

Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

Post by scheinwerfer »

Good job! Your success makes me enthusiastic, I'll try to port it to another platform once more, too.
User avatar
babalu4u
Trader
Posts: 173
Joined: Fri Apr 13, 2012 6:52 pm
Location: Slovenia - EU

Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

Post by babalu4u »

You do not have the required permissions to view the files attached to this post.
Post Reply

Return to “Coders Hangout”