CW
Cwebhook
Blocked user by Spotware at 17 Jun 2024, 08:31
0 follower(s) 0 following 2 subscription(s)
Replies

Cwebhook
10 Jan 2024, 12:56

RE: Using candle body range as source for SimpleMovingAverage

ctrader.guru said: 

I think I understand, you don't need to manipulate the SMA, you can recreate it, this is a simple example:

using System;using cAlgo.API;using cAlgo.API.Internals;namespace cAlgo{    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]    [Levels(0.0005)]    public class BodySMA : Indicator    {        [Parameter("Period", DefaultValue = 10, MinValue = 2)]        public int Period { get; set; }        [Output("Average", LineColor = "DodgerBlue")]        public IndicatorDataSeries Average { get; set; }        protected override void Initialize()        {                        // TODO        }        public override void Calculate(int index)        {            if (index < Period) return;            double sum = 0;            for (int i = index - Period + 1; i <= index; i++)            {                sum += Math.Abs( Bars.ClosePrices[i] - Bars.OpenPrices[i]);                        }                        Average[index] = Math.Round( sum / Period, Symbol.Digits);        }    }}

Thank you! that is what I was after.


Cwebhook
05 Jan 2024, 14:31 ( Updated at: 06 Jan 2024, 08:16 )

RE: Using candle body range as source for SimpleMovingAverage

ctrader.guru said: 

I'm not sure what you want to do, but start with this approach, if you explain better what you want to achieve I can help you better

 

using cAlgo.API;using cAlgo.API.Indicators;using System;namespace cAlgo{    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]    public class test : Indicator    {        protected override void Initialize()        {            SimpleMovingAverage sma = Indicators.SimpleMovingAverage(Bars.ClosePrices, 100);            double  body = Math.Abs(Bars.ClosePrices.Last(0) - Bars.OpenPrices.Last(0));            double body_sma = sma.Result.Last(0) * 3.0;                    }        public override void Calculate(int index)        {                    }            }    }

 

Thanks for the reply.

The body var returns a pip value of the current candle, in tradingview that pip value is passed directly to the sma function which then returns an average pip value, for example if I log the output to the data window these are those 2 values, which are changing in realtime with tick data. I'm trying to achieve the same in ctrader but no idea how to.