using another indicator as a data source

Created at 12 Feb 2013, 11:36
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
70

7023423

Joined 12.02.2013

using another indicator as a data source
12 Feb 2013, 11:36


Hi guys,

I actually don't know anything about the coding and needs some help. 

There's an option for the source like close, high, etc...when we insert some indicators.

I want to use below indicator as a source for the simple moving average indicator.

I tried to put two indicator on cAlgo but failed. So for now, I insert midrange indicator first and then insery SMA and select the source data using midrange. I just want to have one indicator file for these steps.

Below is the coding for the indicator called midrange and I want to smooth this indicator by using source data for the simple moving average indicator.

Please help me on this project ^^

Thank you.

p.s: by the way, i alread set the period as 34....

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true)]
    public class midrange : Indicator
    {
        
        [Output("Center", Color = Colors.Black, Thickness = 0, LineStyle = LineStyle.Dots )]
        public IndicatorDataSeries Center { get; set; }

        public override void Calculate(int index)
        {
            double upper = double.MinValue;
            double lower = double.MaxValue;

            for (int i = index - 34; i <= index - 1; i++)
            {
                upper = Math.Max(MarketSeries.High[i], upper);
                lower = Math.Min(MarketSeries.Low[i], lower);
            }

            Center[index] = (upper + lower) / 2;
        }
    }
}


@7023423
Replies

admin
13 Feb 2013, 16:58

You may create another indicator that references the midrange indicator you created:

 

//#reference: midrange.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 NewIndicator : Indicator
    {
    	SimpleMovingAverage sma;
    	midrange mrange;
    	
        [Parameter(DefaultValue = 10)]
        public int Period { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }


        protected override void Initialize()
        {
            mrange = Indicators.GetIndicator<midrange>();
            sma = Indicators.SimpleMovingAverage(mrange.Center, Period);
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
             Result[index] = sma.Result[index];
        }
    }
}




@admin