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 ;
}
}
}