Replies

Scott
21 Feb 2013, 12:10

RE:
cAlgo_Fanatic said:

Hello,

Is it the indicator found here /algos/show/207 that you are refering to? 

Regards,

Yes I'm using that tick indicator, also I have a indicator that shows the pips between SMA and that is not working as well.  Instead of the data I get "NaN" same on tick indicator.


@Scott

Scott
20 Feb 2013, 00:11

RE:
admin said:

You need to replace Result with atr in the FibonacciBands  indicator or replace atr with Result in the averageTrueRange indicator (this requires a build of the averageTrueRange indicator as well)

First option(FibonacciBands):

 public override void Calculate(int index)
        {
            double ema = _exponentialMovingAverage.Result[index];
            double atr = _averageTrueRange.atr[index];

 


Second option (averageTrueRange ):

[Output("AverageTrueRange", Color = Colors.Orange)]
public IndicatorDataSeries Result { get; set; }

 

 

Thank you, it now builds I went with the first solution.  Is there a way to shade in the space between lines, it would make it a lot easyer to see at a glance than looking for the lines?


@Scott

Scott
15 Feb 2013, 23:51 ( Updated at: 21 Dec 2023, 09:20 )

RE:
admin said:

Regarding the error you are receiving you need to add a reference of the Average true range algo file. You can do this by clicking the button next to the build button on the top of the text editor.

 

I still can not get this to work

Build failed Errors: 1  Error: 'cAlgo.Indicators.averageTrueRange' does not contain a definition for 'Results' and no extension method 'Result' accepting a first argument of type 'cAlgo.Indicators.averageTrueRange' could be found (are you missing a using directive or an assembly reference?)

//#reference: C:\Users\scott\Documents\cAlgo\Sources\Indicators\averageTrueRange.algo
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true)]
    public class FibonacciBands : Indicator
    {
        private averageTrueRange _averageTrueRange;
        private ExponentialMovingAverage _exponentialMovingAverage;

        [Parameter(DefaultValue = 55)]
        public int PeriodEma { get; set; }

        [Parameter(DefaultValue = 21)]
        public int PeriodAtr { get; set; }

        [Output("Upper Band 1", Color = Colors.DarkCyan)]
        public IndicatorDataSeries UpperBand1 { get; set; }

        [Output("Upper Band 2", Color = Colors.DarkCyan)]
        public IndicatorDataSeries UpperBand2 { get; set; }

        [Output("Upper Band 3", Color = Colors.DarkCyan)]
        public IndicatorDataSeries UpperBand3 { get; set; }

        [Output("Upper Band 4", Color = Colors.DarkCyan)]
        public IndicatorDataSeries UpperBand4 { get; set; }

        [Output("Lower Band 1", Color = Colors.DarkGreen)]
        public IndicatorDataSeries LowerBand1 { get; set; }

        [Output("Lower Band 2", Color = Colors.DarkGreen)]
        public IndicatorDataSeries LowerBand2 { get; set; }

        [Output("Lower Band 3", Color = Colors.DarkGreen)]
        public IndicatorDataSeries LowerBand3 { get; set; }

        [Output("Lower Band 4", Color = Colors.DarkGreen)]
        public IndicatorDataSeries LowerBand4 { get; set; }

        [Output("EMA", Color = Colors.Blue)]
        public IndicatorDataSeries Ema { get; set; }

        protected override void Initialize()
        {
            _averageTrueRange = Indicators.GetIndicator<averageTrueRange>(PeriodAtr);
            _exponentialMovingAverage = Indicators.ExponentialMovingAverage(MarketSeries.Close, PeriodEma);
        }

        public override void Calculate(int index)
        {
            double ema = _exponentialMovingAverage.Result[index];
            double atr = _averageTrueRange.Result[index];

            UpperBand1[index] = ema + 1.62*atr;
            UpperBand2[index] = ema + 2.62*atr;
            UpperBand3[index] = ema + 4.23*atr;
            UpperBand4[index] = ema + 1*atr;
            LowerBand1[index] = ema - 1.62*atr;
            LowerBand2[index] = ema - 2.62*atr;
            LowerBand3[index] = ema - 4.23*atr;
            LowerBand4[index] = ema - 1*atr;

            Ema[index] = ema;
        }
    }
}

 

The code for the averageTrueRange that I'm using that builds

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false,ScalePrecision = 5)]
    public class averageTrueRange : Indicator
    {   
        [Parameter(DefaultValue = 14, MinValue = 2)]
        public int Period { get; set; }
        
          [Output("AverageTrueRange", Color = Colors.Orange)]
        public IndicatorDataSeries atr { get; set; }
        
        private ExponentialMovingAverage ema;
           public IndicatorDataSeries tr;
           private TrueRange tri;
        protected override void Initialize()
        {
            tr =  CreateDataSeries();
            tri = Indicators.TrueRange();
            ema = Indicators.ExponentialMovingAverage(tr,Period);
        }
        
        public override void Calculate(int index)
        {
            if(index<Period+1)
            {atr[index] = tri.Result[index];}
            if(index>=Period){
            atr[index] = (atr[index-1]*(Period-1)+tri.Result[index]) / Period;}
        }
    }
}

 

Thanks

 

 


@Scott

Scott
10 Feb 2013, 21:23

RE:
rkokerti said:

Hi,

You need to press space button several times between "    ", or press tab button once in this row : string Dist = "    " + Math.Round((sma1.Result[index] - sma2.Result[index]) / Symbol.PipSize,0); 

I hope it helps.

Thanks rkokerti, got it working now, I put in 10 spaces in string Dist = "    " , the tab would move the pipsize to far away.


@Scott

Scott
08 Feb 2013, 23:40 ( Updated at: 21 Dec 2023, 09:20 )

RE: RE: RE: spread indicator

Thanks rkokerti

That exactly what I was after, there's one little problem the value is printing on top off the word Dist:

Thank again 


@Scott

Scott
07 Feb 2013, 20:20

RE: spread indicator
MaXeY said:

Hello

anyone have spread indicator for Ctrader ?

I use this one at the momment it almost in sink with the actual spread Tick Chart /algos/show/207 

or you could use Lables for Charts /algos/show/195  just remove the infomation you dont want and set the indicator to false so that its not on your chart and in your way, I triying to work out how to calculate the pip differance between moving averages that will be printed using Lables.  But I can think of a few good thing that could also be added such as RSI.

 


@Scott

Scott
21 Jan 2013, 00:41 ( Updated at: 21 Dec 2023, 09:20 )

RE: RE: RE: sma

 

Hi thanks, its still not working I removed the block of code you said too and it had the same problem below for the result,results2,results3, I added the Output as I want to be able to control color and line type.  Also how can I set the line width I put it in the Parameters

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true)]
    public class sma8 : Indicator
    {
        [Parameter]
        public DataSeries Source { get; set; }

       private SimpleMovingAverage _simpleMovingAverage1;
       private SimpleMovingAverage _simpleMovingAverage2;
       private SimpleMovingAverage _simpleMovingAverage3; 


protected override void Initialize()
{
     _simpleMovingAverage1 = Indicators.SimpleMovingAverage(Source, Period1);
     _simpleMovingAverage2 = Indicators.SimpleMovingAverage(Source, Period2);
     _simpleMovingAverage3 = Indicators.SimpleMovingAverage(Source, Period3);

}
public override void Calculate(int index)
{       
     Result[index] = _simpleMovingAverage1.Result[index];
     Result2[index] = _simpleMovingAverage2.Result[index];
     Result2[index] = _simpleMovingAverage3.Result[index];
}
       [Output("Period1", Color = Colors.Green)]
              public IndicatorDataSeries Result { get; set; }
     
       [Output("Period2", Color = Colors.Yellow)]
              public IndicatorDataSeries Result2 { get; set; }         
     
       [Output("Period3", Color = Colors.White)]
              public IndicatorDataSeries Result3 { get; set; }         
        
    }
}             
      


@Scott

Scott
18 Jan 2013, 23:26 ( Updated at: 21 Dec 2023, 09:20 )

RE: sma
admin said:

You can use the build in Indicator "SimpleMovingAverage"

 

private SimpleMovingAverage _simpleMovingAverage1;
private SimpleMovingAverage _simpleMovingAverage2;
private SimpleMovingAverage _simpleMovingAverage3;
// ... etc.

protected override void Initialize()
{
     _simpleMovingAverage1 = Indicators.SimpleMovingAverage(Source, Period1);
     _simpleMovingAverage2 = Indicators.SimpleMovingAverage(Source, Period2);
     _simpleMovingAverage3 = Indicators.SimpleMovingAverage(Source, Period3);
      //...etc
}
public override void Calculate(int index)
{       
     Result[index] = _simpleMovingAverage1.Result[index];
     Result2[index] = _simpleMovingAverage2.Result[index];
     //...etc
}

See more examples with build in Indicators at the API Reference

 

 

 

 

 

 

Thanks for getting back to me, I've put the changes in but 1 error has come up

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true)]
    public class sma8 : Indicator
    {
        [Parameter]
        public DataSeries Source { get; set; }

       private SimpleMovingAverage _simpleMovingAverage1;
       private SimpleMovingAverage _simpleMovingAverage2;
       private SimpleMovingAverage _simpleMovingAverage3;


protected override void Initialize()
{
     _simpleMovingAverage1 = Indicators.SimpleMovingAverage(Source, Period1);
     _simpleMovingAverage2 = Indicators.SimpleMovingAverage(Source, Period2);
     _simpleMovingAverage3 = Indicators.SimpleMovingAverage(Source, Period3);

}
public override void Calculate(int index)
{       
     Result[index] = _simpleMovingAverage1.Result[index];
     Result2[index] = _simpleMovingAverage2.Result[index];
     Result2[index] = _simpleMovingAverage3.Result[index];
}
      
        
             public override void Calculate(int index)   
        {
            double sum = 0.0;

            for (int i = index - Periods + 1; i <= index; i++)
            {
                sum += Source[i];
            }
            Result[index] = sum / Periods;
        }
        
    }
} 


@Scott