How to add TimeFrame parameter to SMA?

Created at 24 Feb 2018, 21:15
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!
DA

Dagfx

Joined 04.12.2017

How to add TimeFrame parameter to SMA?
24 Feb 2018, 21:15


Hello, I'm trying to add a default Timeframe parametre to SMA, buy don't know to implement it. Thanks

 

// -------------------------------------------------------------------------------------------------
//
//    This code is a cAlgo API example.
//    
//    All changes to this file will be lost on next application start.
//    If you are going to modify this file please make a copy using the "Duplicate" command.
//
// -------------------------------------------------------------------------------------------------

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class SampleSMA : Indicator
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter(DefaultValue = 14)]
        public int Periods { get; set; }

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

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

 


@Dagfx
Replies

Dagfx
24 Feb 2018, 21:34

Also how I can show 1h-4h  level on a lower timeframe like 5m. 


@Dagfx

firemyst
13 Aug 2023, 05:13

RE: How to add TimeFrame parameter to SMA?

Dagfx said: 

Also how I can show 1h-4h  level on a lower timeframe like 5m. 

Why don't you look at the examples Spotware provided?

https://help.ctrader.com/ctrader-automate/indicator-code-samples/#multiple-timeframes

 


@firemyst