OL
Could some help whit a simple SMA?
05 Jan 2014, 17:32
Hi, i have no experience with coding indecators, I have mainly focused on learning to code robots. So I was wodring if anyone could help me with this simple indecator.
So what i need is a SMA whit two extra line, one above the SMA and one below the SMA with preferably a parameter to change the distance between the true SMA and the lines above and below.
Thanks.

jeex
05 Jan 2014, 20:50 ( Updated at: 21 Dec 2023, 09:20 )
Something like this?
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; namespace cAlgo.Indicators { [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)] public class SMAchannel : Indicator { [Parameter("Periods", DefaultValue = 20, MinValue = 1, MaxValue = 500)] public int _Periods { get; set; } [Parameter("Distance Top (pips)", DefaultValue = 20, MinValue = 1, MaxValue = 1000)] public int _dTop { get; set; } [Parameter("Distance Bottom (pips)", DefaultValue = 20, MinValue = 1, MaxValue = 1000)] public int _dBottom { get; set; } [Output("SMA", Color = Colors.Purple, PlotType = PlotType.Line, Thickness = 1)] public IndicatorDataSeries SMA { get; set; } [Output("dTop", Color = Colors.DodgerBlue, PlotType = PlotType.Line, Thickness = 1)] public IndicatorDataSeries dTop { get; set; } [Output("dBottom", Color = Colors.Tomato, PlotType = PlotType.Line, Thickness = 1)] public IndicatorDataSeries dBottom { get; set; } private SimpleMovingAverage _sma; protected override void Initialize() { _sma = Indicators.SimpleMovingAverage(MarketSeries.Close, _Periods); } public override void Calculate(int index) { SMA[index] = _sma.Result[index]; dTop[index] = _sma.Result[index] + pip2dif(_dTop); dBottom[index] = _sma.Result[index] - pip2dif(_dBottom); } private double pip2dif(int pip) { return pip * Symbol.PipSize; } } }You set the distance in pips. See example below.
@jeex