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 1 of 2
Author:  babalu4u [ Tue Jun 04, 2013 8:56 am ]
Post subject:  cTrader - Help to build TMA Slope for cTrader/cAlgo

I decide to start with cTrader because I think there is great potential and I don't want to use CRAP Empty4 any more. My last EA was using TMA Slope combination with SMA 2 of TMA (not finished yet). The EA was using reversal patterens of TMA (SCALPER) ....
For this I decide to start with TMA Slope indicator and than I will tray to make Robot for cTrader. Every body are welcome to help. ;)
Author:  babalu4u [ Tue Jun 04, 2013 9:01 am ]
Post subject:  Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

cTrader have Triangular Moving Average...
Author:  babalu4u [ Tue Jun 04, 2013 1:53 pm ]
Post subject:  Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

Ok this is my first shot my first C#.... for this dont smile to me instead help me... :oops: :shock:
normaly don't work :roll:

Code: Select all

// -------------------------------------------------------------------------------
//
//    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:  babalu4u [ Tue Jun 04, 2013 2:41 pm ]
Post subject:  Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

Second atempt - no errors but don't work... :cry:

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:  babalu4u [ Tue Jun 04, 2013 3:53 pm ]
Post subject:  Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

This is the answer from spotware support on forum where is error..
In the Calculate method index is the last index of the series at the moment. Therefore any value such as:

MarketSeries.Close[index + 1 + jnx ]

does not exist yet.

You want to calculate backwards by subtracting from the last index instead of adding.
Author:  babalu4u [ Tue Jun 04, 2013 4:16 pm ]
Post subject:  Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

If somebody can help is welcome.... ;)
Author:  scheinwerfer [ Tue Jun 04, 2013 8:12 pm ]
Post subject:  Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

Hey,

First of all I'm not much of a help, especially so as I first heard of cTrader couple of days ago :lol:

But I'm very interested how you get on, a while back I tried to port the same indi to another backtesting platform and it didn't work out properly cause values were off. I couldn't trace the bug, didn't have a source at hand.

But my humble advice would be to change pluses to minuses:

Code: Select all

MarketSeries.Close[index - 1 - jnx ] 
Author:  babalu4u [ Tue Jun 04, 2013 8:30 pm ]
Post subject:  Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

I am traying now but stil have a problem...

p.s.: sorry form my EN
Author:  scheinwerfer [ Tue Jun 04, 2013 8:52 pm ]
Post subject:  Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

Read your code, that copy-paste work won't fly, a few dodgy parts. I remembered now problems I had, very similar to yours.

I think first of all lets try to get some values on the screen, run this one and report back what it shows.

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 = 1; //calcPrevTrue( index );
                   gadblSlope = ( dblTma - dblPrev ) / atr;
                }
                Result[index] = gadblSlope ;
            }
        }
    }
Author:  babalu4u [ Tue Jun 04, 2013 9:02 pm ]
Post subject:  Re: cTrader - Help to build TMA Slope for cTrader/cAlgo

Ok now it show histogram... looks like this
All times are UTC Page 1 of 2